akhauriyash/Code-Regression huggingface dataset:
from collections import deque
NegInf = -float('inf')


n, m, p = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    graph[a-1].append((b-1, c-p))


def bellman_ford(vst, graph, node_num, NegInf):
    costs = [NegInf] * node_num
    costs[0] = 0
    v_nows = set([vst])
    for _ in range(n):
        v_changeds = set()
        for v_from in v_nows:
            for v_to, cost in graph[v_from]:
                c2 = costs[v_from] + cost
                if c2 > costs[v_to]:
                    costs[v_to] = c2
                    v_changeds.add(v_to)
        v_nows = v_changeds



    if not v_changeds:
        return costs

    for i in v_nows:
        costs[i] = NegInf

    que = deque(v_nows)
    while que:
        v_from = que.popleft()
        for v_to, cost in graph[v_from]:
            if costs[v_to] != NegInf:
                costs[v_to] = NegInf
                que.append(v_to)
    return costs


costs = bellman_ford(0, graph, n, -float('inf'))
if costs[n-1] == NegInf:
    print(-1)
else:
    print(max(0, costs[n-1]))

Measured memory_bytes: 76504
for _ in [0]*int(input()):
    s=input()
    if s[:2]==">'" and s[-1]=='~' and '#' in s:
        s=s[2:-1].split('#')
        print(['NA','A'][set(s[0])==set(s[1])=={'='} and len(set(s))==1])
    elif s[:2]=='>^' and s[-2:]=='~~':
        s=s[2:-2]
        print(['NA','B'][len(s)==2*s.count('Q=') and len(s)>0])
    else:print('NA')

Measured memory_bytes: 7476
import sys
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
A=get_array()
B=get_array()
C=get_array()
score=0
for i in range(n):
  score+=B[A[i]-1]
  if i!=0:
    if A[i]==A[i-1]+1:
      score+=C[A[i-1]-1]
print(score)

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

int n;
long double dp[301][301][301];

long double Cal(int N, int ones, int twos, int threes)
{
    if (ones == 0 && twos == 0 && threes == 0)
    {
        return 0.0;
    }
    if (dp[ones][twos][threes] != 0.0)
    {
        return dp[ones][twos][threes];
    }
    int nonEmptyPlates = ones + twos + threes;
    long double p_wasted = 1.0 - (long double)nonEmptyPlates / N;
    long double p1 = 0.0, p2 = 0.0, p3 = 0.0;
    if (ones > 0)
    {
        p1 = (long double)ones / nonEmptyPlates * Cal(N, ones - 1, twos, threes);
    }
    if (twos > 0)
    {
        p2 = (long double)twos / nonEmptyPlates * Cal(N, ones + 1, twos - 1, threes);
    }
    if (threes > 0)
    {
        p3 = (long double)threes / nonEmptyPlates * Cal(N, ones, twos + 1, threes - 1);
    }
    dp[ones][twos][threes] = p1 + p2 + p3 + p_wasted / (1 - p_wasted);
    return dp[ones][twos][threes];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int ones = 0, twos = 0, threes = 0;
    int x;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        ones += (x == 1);
        twos += (x == 2);
        threes += (x == 3);
    }
    cout << fixed << setprecision(9) << ones + twos * 2 + threes * 3 + Cal(n, ones, twos, threes) << '\n';
    return 0;
}


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


int main()
{
  int N,K,d,A,count=0;
  bool *b;
  cin>>N>>K;
  b=new bool[N];
  for(int i=0;i<N;i++)
    b[i]=false;
  for(int i=0;i<K;i++)
  {
    cin>>d;
    for(int j=0;j<d;j++)
    {
      cin>>A;
      b[A-1]=true;
    }
  }
  for(int i=0;i<N;i++)
    if(!b[i])
      count++;
  cout<<count;
  
  delete[] b;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    cin>> n;

    int sum=0 , l[n];

    for(int i=0; i<n; i++)
    {
        cin>> l[i];
        sum+= l[i];
    }

    
    cout << (sum > (2* *max_element(l, l+n)) ? "Yes\n" : "No\n");

    return 0;
}




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

using namespace std;

int main()
{
	int K;
	cin >> K;
	string S;
	cin >> S;

	for (size_t i = 0; i < min((size_t)K, S.size()); i++) {
		cout << S[i];
	}

	if (S.size() > (size_t)K) {
		cout << "...";
	}

	cout << "\n";

	return 0;
}


Measured memory_bytes: 3640
// https://atcoder.jp/contests/abc125/tasks/abc125_b

#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;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int N, t, score = 0;
  vector<int> V(50);
  cin >> N;

  REP(i, N)
  {
    cin >> V[i];
  }

  REP(i, N)
  {
    cin >> t;
    score += max(0, V[i] - t);
  }

  cout << score << '\n';

  return 0;
}


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

using namespace std;

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

	vector<vector<int>> x(n, vector<int>(d, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int dist2 = 0;
			for (int k = 0; k < d; k++) {
				int tmp = x[i][k] - x[j][k];
				dist2 += tmp * tmp;
			}

			int rt = sqrt(dist2);
			if (rt * rt == dist2) {
				ans++;
			}
		}
	}

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


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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L < R) {
    cout << "Right" << endl;
  } else if(L > R) {
    cout << "Left" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
# coding: utf-8
# 線形探索


def linearSearch(target, data_list):
    for data in data_list:
        if target == data:
            return 1

    return 0


if __name__ == "__main__":
    n = int(input())
    S = [int(i) for i in input().split()]
    q = int(input())
    T = [int(j) for j in input().split()]

    total = 0

    for target in T:
        total += linearSearch(target, S)

    print(total)



Measured memory_bytes: 6564
#include <bits/stdc++.h> 
using namespace std; 
  
int main() {
	string a,b;
	int count=0;
	cin>>a;
	cin>>b;
	for(int i=0;i<a.size();i++){
		if(a[i]!=b[i]){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3848
#全体-絶対値一番小さいやつ*2
N = int(input())
A = list(map(int,input().split()))
# N=3
# A = [-10,5,-4]
ans = 0
minnum = abs(A[0])
numminus = 0
for i in range(N):
    if A[i]<0:
        numminus+=1
    ans += abs(A[i])
    minnum = min(minnum,abs(A[i]))
    #print(minnum,ans)
if numminus%2 == 1:
    ans -= minnum*2
print(ans)

Measured memory_bytes: 14332
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		string s;
		cin>>s;
		ll int q;
		cin>>q;
		deque<char> dq;
		for(auto i:s) dq.push_back(i);
		ll int f=0;
		while(q--)
		{
			ll int t;
			cin>>t;
			if(t==1)
			{
				f=1-f;
			}
			else
			{
				ll int ff;
				char c;
				cin>>ff>>c;
				if(ff==1)
				{
					if(f==0) dq.push_front(c);
					else dq.push_back(c);
				}
				else
				{
					if(f==1) dq.push_front(c);
					else dq.push_back(c);
				}
			}
		}	
		while(dq.size()!=0)
		{
			if(f==0) cout<<dq.front();
			if(f==0) dq.pop_front();
			if(f==1) cout<<dq.back();
			if(f==1) dq.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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; }
const long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  string l[10];
  vector<pair<int,int>> m;
  int n=9;
  rep(i,n){
    string s,r;
    pair<int,int> t;
    int a,b;
    cin>>s>>a>>b;
    l[i]=s;
    t.first=a+b;
    t.second=a*200+b*300;
    m.pb(t);
  }
  rep(i,n){
    cout<<l[i]<<" "<<m[i].first<<" "<<m[i].second<<endl;
  }
  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0;i<(n);++i)
const ll MOD=1e9+7;

template<typename T,typename E>
struct PrimalDual{
    const E inf=numeric_limits<E>::max()/2;
    struct edge{
        int to,rev; T cap; E cost;
        edge(int to,T cap,E cost,int rev):
            to(to),cap(cap),cost(cost),rev(rev){}
    };
    vector<vector<edge>> G;
    vector<E> h,dist;
    vector<int> prevv,preve;
    PrimalDual(int n):G(n),h(n),dist(n),prevv(n),preve(n){}
    void add_edge(int from,int to,T cap,E cost){
        G[from].emplace_back(to,cap,cost,G[to].size());
        G[to].emplace_back(from,0,-cost,G[from].size()-1);
    }
    void dijkstra(int s){
        struct P{
            E first; int second;
            P(E first,int second):first(first),second(second){}
            bool operator<(const P &a) const{
                return a.first<first;
            }
        };
        priority_queue<P> pq;
        fill(dist.begin(),dist.end(),inf);
        dist[s]=0;
        pq.emplace(dist[s],s);
        while(!pq.empty()){
            P p=pq.top(); pq.pop();
            int v=p.second;
            if (dist[v]<p.first) continue;
            for (int i=0;i<G[v].size();++i){
                edge &e=G[v][i];
                if (e.cap>0&&dist[v]+e.cost+h[v]-h[e.to]<dist[e.to]){
                    dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
                    prevv[e.to]=v,preve[e.to]=i;
                    pq.emplace(dist[e.to],e.to);
                }
            }
        }
    }
    E min_cost_flow(int s,int t,T f){
        E res=0;
        fill(h.begin(),h.end(),0);
        while(f>0){
            dijkstra(s);
            if (dist[t]==inf) return -1;
            for (int v=0;v<h.size();++v){
                if (dist[v]<inf) h[v]+=dist[v];
            }
            T d=f;
            for (int v=t;v!=s;v=prevv[v]){
                d=min(d,G[prevv[v]][preve[v]].cap);
            }
            f-=d;
            res+=h[t]*d;
            for (int v=t;v!=s;v=prevv[v]){
                edge &e=G[prevv[v]][preve[v]];
                e.cap-=d;
                G[v][e.rev].cap+=d;
            }
        }
        return res;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V,E,F; cin >> V >> E >> F;
    PrimalDual<int,int> PD(V);
    rep(i,E){
        int u,v,c,d; cin >> u >> v >> c >> d;
        PD.add_edge(u,v,c,d);
    }
    cout << PD.min_cost_flow(0,V-1,F) << endl;
}


Measured memory_bytes: 3284
// +build ignore
package main

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

func solve(sc *scanner, wr *bufio.Writer) int {
	S := sc.i()
	W := sc.i()

	if S <= W {
		fmt.Println("unsafe")
	} else {
		fmt.Println("safe")
	}

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 1756
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b,c;
	cin>>a;
	a[0]=a[0]-32;
	cin>>b;
	b[0]=b[0]-32;
	cin>>c;
	c[0]=c[0]-32;
	cout<<a[0]<<b[0]<<c[0]<<endl;
	return 0;
 } 

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

int main(int argc, char const *argv[]) {
  int n,d;
  cin>>n>>d;
  double a[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>a[i][j];
    }
  }

  int count=0;

  for(int i=0;i<n;i++){
    for(int j=1;j<n-i;j++){
      double dis=0;
      for(int k=0;k<d;k++){
        // cout<<"a[i][k]="<<a[i][k]<<endl;
        // cout<<"a[i+j][k]="<<a[i+j][k]<<endl;
        //
        dis += pow(a[i][k]-a[i+j][k],2);
        //
        // cout<<"i="<<i<<",j="<<j<<",k="<<k<<endl;
        // cout<<"dis="<<dis<<endl;
      }
      dis = sqrt(dis);
      if(lround(dis)==dis)  {
        count++;
        // cout<<"sqrt_dis="<<dis<<endl;
        // cout<<endl;
      }
    }
  }

  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#ifdef _WIN64
#define __builtin_popcountll __popcnt64
#else
inline int __builtin_popcountll(__int64 a) {
	return __builtin_popcount((unsigned int)a) + __builtin_popcount(a >> 32);
}
#endif
#endif
using ll = long long;
using ull = unsigned long long;
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y//be careful from the multiplication while using this define 
#define TC int t;cin>>t;while(t--)
//</DEFINE>
//<FUNCTIONS>
//</FUNCTIONS>	
int main() {
	Fast();
	int n, cpcty;
	cin >> n >> cpcty;
	vector<vector<ll>>dp(n, vector<ll>(cpcty + 1));
	vector<pair<ll, ll>>v(n);
	for (int i = 0; i < n; i++)cin >> v[i].first >> v[i].second;
	for (int i = v[n - 1].first; i <= cpcty; i++)dp[n - 1][i] = v[n - 1].second;
	for (int i = n - 2; i >= 0; i--) {
		for (int j = 1; j <= cpcty; j++) {
			if (j >= v[i].first)dp[i][j] = max(dp[i + 1][j - v[i].first] + v[i].second, dp[i + 1][j]);
			else dp[i][j] = dp[i + 1][j];
		}
	}
	cout << dp[0][cpcty] << endl;
}


Measured memory_bytes: 82292
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int A = scn.nextInt();
		int B = scn.nextInt();
		System.out.println(A%2!=0&&B%2!=0?"Yes":"No");
		scn.close();
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

char t[114];

bool issame(int len, char c){
	bool res=true;
	REP(i, len){
		if(t[i]!=c){
			res=false;
			break;
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int ans=100;
	REP(i, 26){
		REP(j, s.size()){
			t[j]=s[j];
		}
		char c='a'+i;
		int len=s.size();
		while(!issame(len, c)){
			char u[114];
			REP(j, len){
				u[j]=t[j];
			}
			REP(j, len-1){
				if(u[j]==c){
					t[j]=u[j];
				}
				else if(u[j+1]==c){
					t[j]=u[j+1];
				}
				else{
					t[j]=u[j];
				}
			}
			--len;
		}
		ans=min(ans, (int)s.size()-len);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())

ans = [-1, -1, -1]

for x in range(Y//1000+1):
    y_Y = Y - 10000 * x
    y_N = N - x
    if (y_Y - 1000 * y_N) % 4000 == 0:
        y = (y_Y - 1000 * y_N) // 4000
        if 0 <= y and y <= y_N:
            z = y_N - y
            ans = [x, y, z]
            break

print(*ans)


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
long long a,b,ans=1;
long long gcd(long long a,long long b)
{
	if (a<b) 
	   swap(a,b);
	if (b==0) 
	   return a;
	else 
	   return gcd(b,a%b);
}
int main()
{
	fast;
	cin>>a>>b;
	long long c=gcd(a,b),cc=c;
	for (long long i=2;i<=sqrt(cc);i++)
    {
		if (c%i==0 && i<=c)
        {
			ans++;
			while (c%i==0) 
              c/=i;
		}
	}

	for (long long i=sqrt(cc);i>=1;i--)
    {
		long long ni=cc/i;
		if (c%ni==0)
        {
			if (ni<=1) 
              continue;
			ans++;
			while (c%ni==0 && ni<=c)
              c/=ni;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main(){
  //insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
  int n,a[N],i,v,j,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  // for i が 1 から N-1 まで

  for(i=0;i<n;i++){
    v = a[i];
    j = i - 1;
    while(j>=0 && a[j]>v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    for(c=0;c<n;c++){
      printf("%d",a[c]);
      if(c==n-1)break;
      printf(" ");
    }
    printf("\n");
  }


  return 0;
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    pii cnt[2][MAX];
    rep(i, 2)rep(j, MAX) cnt[i][j] = {0, j};
    rep(i, n){
        int v;
        scanf("%d", &v);
        ++cnt[i%2][v].fi;
    }
    rep(i, 2) sort(cnt[i], cnt[i]+MAX, greater<>());

    if(cnt[0][0].se != cnt[1][0].se){
        printf("%d\n", n - cnt[0][0].fi - cnt[1][0].fi);
    }
    else{
        int s = n - cnt[0][0].fi - cnt[1][1].fi;
        int t = n - cnt[0][1].fi - cnt[1][0].fi;
        printf("%d\n", min(s, t));
    }
}

Measured memory_bytes: 1920
n,k = map(int,input().split())
a=[]
c=[]
for i in range(n):
    b=int(input())
    a.append(b)
a.sort()
for u in range(n-k+1):
    d=a[u+k-1]-a[u]
    c.append(d)
print(min(c))

Measured memory_bytes: 11164
# -*- coding: utf-8 -*-
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def slv(K, A, B):
    for i in range(INF):
        if A <= i*K <= B:
            return 'OK'
        if i * K > B:
            break
    return 'NG'


def main():
    K = read_int()
    A, B = read_int_n()
    print(slv(K, A, B))


if __name__ == '__main__':
    main()


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> d, v(n), c(n);
  rep (i, n) cin >> v[i];
  rep (i, n) cin >> c[i];
  rep (i, n) d.eb(v[i] - c[i]);

  int ans = 0;
  rep (i, n) if (d[i] > 0) ans += d[i];

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

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

    vector<pair<long long, int>> a(n, make_pair(0, 0));
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }

    sort(a.begin(), a.end(), greater<pair<long long, int>>());

    vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; i + j < n; j++) {
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a[i + j].first * (a[i + j].second - j));
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[i + j].first * (n - i - a[i + j].second - 1));
        }
    }

    long long res = 0;
    for (int i = 0; i <= n; i++) {
        res = max(res, dp[i][n - i]);
    }

    cout << res << endl;
}


Measured memory_bytes: 34652
#include <iostream>
#include <map>
#include <iterator>

int main(){
	int n;
	std::map< char, char > m;

	while( std::cin >> n, n ){
		while( n-- ){
			char c[2];

			std::cin >> c[0] >> c[1];

			m[c[0]] = c[1];
		}

		std::cin >> n;
		while( n-- ){
			 char c;
			 std::map< char, char >::iterator it;

			 std::cin >> c;

			 if( (it = m.find(c)) != m.end() ){
			 	c = it->second;
			 }
			 std::cout << c;
		}

		std::cout << std::endl;
		m.clear();
	}
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
 
int main(){
  vector<int> vec; // int型の配列変数vecを宣言
 
  vec = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int i;
  cin>>i;
  cout<<vec.at(i-1)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b;
	cin >> a >> b;

	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;

	} else{
		cout << "Impossible" << endl;

	}
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int d; cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    vector<int> ids(26);
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j];
        }
        iota(all(ids), 0);
        sort(all(ids), [&](int x, int y){ return s[i][x] > s[i][y]; });
        cout << ids[0] + 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


Measured memory_bytes: 3696
## coding: UTF-8
A = int(input()) # 500
B = int(input()) # 100
C = int(input()) # 50
X = int(input()) 

#max = 500 * A + 100 * B + 50 * C #払える最大値
#print(max)

counter = 0 #場合の数カウンター（これが回答になる）
xa = A
xb = B
xc = C

def purchase(a,b,c):
    return 500 * a + 100 * b + 50 * c

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            #print(purchase(i,j,k))
            if(purchase(i,j,k) == X):
                counter += 1
print(counter)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  long long int H, W;
  cin >> H >> W;
  if(!((H%3)*(W%3))) cout << 0 << endl;
  else{
    long long int ans = 1e15;
    for(long long int i = 1; i < H; ++i){
      ans = min(ans, max({abs(i*W - (H - i)*(W/2)), abs(i*W - (H - i)*(W - W/2)), abs((H - i)*(W%2))}));
    }
    for(long long int i = 1; i < W; ++i){
      ans = min(ans, max({abs(i*H - (W - i)*(H/2)), abs(i*H - (W - i)*(H - H/2)), abs((W - i)*(H%2))}));
    }
    if(H > 3) ans = min(ans, W);
    if(W > 3) ans = min(ans, H);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (A,B,C) = readLine()!!.split(" "). map { it.toInt() }
    if (A == B && A != C) {
        println("Yes")
    } else if (A == C && A != B) {
        println("Yes")
    } else if (B == C && A != B) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 36164
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import fractions
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
 
n = int(input())
a = list(map(int, input().split()))
a = deque(sorted(a))
ans = 0
for i in a:
    ans = fractions.gcd(ans, i)
print(ans)

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

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;

int ans=1e9;
string s,ss;
int len1,len2;
void work(int h)
{
    int sum=0;
    for(int i=h;i<=h+len2-1;i++){
        if(s[i]!=ss[i-h])  sum++;
    }
 //   cout<<sum<<endl;
    ans=min(ans,sum);
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);

    cin>>s>>ss;
    len1=s.size();
    len2=ss.size();

    for(int i=0;i<len1-len2+1;i++){
        work(i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
s = input()
a = int(s[:2]) #上2桁
b = int(s[2:]) #下2桁

if 0 < a < 13:
    if 0 < b < 13:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 0 < b < 13:
        print('YYMM')
    else:
        print('NA')

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

 
int main() {
    int k;
    long l,lun;
    queue<long> lunlun;
    cin >> k;
    for (int i = 1; i < 10; i++){
        lunlun.push(i);
    }
    for (int i = 0; i < k; i++){
        lun = lunlun.front();
        lunlun.pop();
        l = lun % 10;
        if (l != 0){
            lunlun.push(lun*10+l-1);
        }
        lunlun.push(lun*10+l);
        if (l != 9){
            lunlun.push(lun*10+l+1);
        }
    }
    printf("%ld\n",lun);
}

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

int main() {
int r,g,b;
cin >>r>>g>>b;
int c = 100*r+10*g+b;
  
if(c%4 == 0){
cout<<"YES"<<endl;
}
  
else{
cout<<"NO"<<endl;
}

}

Measured memory_bytes: 256
import Control.Monad -- for replicateM_
import Data.List -- for sort


{-
deal :: IO()
deal = do 
    [n, x] <- map read . words <$> getLine
    info <- replicateM (n-1) getWeight
    -- graph <- buildTree info [[[]]]
    putStrLn $ show info

main :: IO()
main = getLine >>= flip replicateM_ deal . read 
-}

solve :: Int -> Int -> Int -> Int
solve n x t = t * (ceiling $ toRational (realToFrac n / (realToFrac x)))

main :: IO()
main = do 
    [n, x, t] <- map read . words <$> getLine
    putStrLn $ show $ solve n x t


Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    int n,we;
    cin>>n>>we;

    vi v(n),w(n);
    forn(i,0,n)
    {
        cin>>w[i]>>v[i];
    }

        
    v2l dp(n+1,vl(we+1,0));

    forn(i,1,n+1)
    {
        forn(j,1,we+1)
        {
            dp[i][j] = dp[i-1][j];
            if(j-w[i-1] >= 0)
            {
                // cout<<j<<" ";
                dp[i][j] = max(dp[i][j],v[i-1]+dp[i-1][j-w[i-1]]);
            } 
        }
    }

/*    forn(i,0,n+1)
    {
        forn(j,0,we+1)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }

*/

    cout<<dp[n][we];

    return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod> struct modulo {
	int w;
	operator int&() { return w; }
	operator int() const { return w; }
	
	modulo() {}
	modulo(int w, bool f = 0) { this->w = w; if (f) fix(); }
	void inline fix() { if (w >= mod || w < -mod) w %= mod; if (w < 0) w += mod; }
	
	inline modulo  operator -  () { w = -w + mod; return *this; }
	inline modulo  operator +  (const modulo &b) { modulo r = *this; return r += b; }
	inline modulo  operator -  (const modulo &b) { modulo r = *this; return r -= b; }
	inline modulo  operator *  (const modulo &b) { modulo r = *this; return r *= b; }
	inline modulo  operator /  (const modulo &b) { modulo r = *this; return r /= b; }
	inline modulo& operator += (const modulo &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline modulo& operator -= (const modulo &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline modulo& operator *= (const modulo &b) { w = (num) w * b.w % mod; return *this; }
	inline modulo& operator /= (const modulo &b) { return *this *= inv(b); }
	
	friend inline modulo inv(const modulo &w) {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return modulo(u, 1);
	}
	
	friend inline modulo pow(const modulo &w, int p) {
		if (!w)  return 0;
		modulo a = w, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
const int mod = int(1e9 + 7);
typedef modulo<mod> rem;

const int nsz = int(3e3);
int n, m;
rem dp[2][nsz + 5][2], ans;

int main() {
	scanf("%d%d", &n, &m);
	n -= 1, m -= 1;
	int o = 0, x = 1;
	circ (k, 0, n) dp[o][k][k == 0] = 1;
	loop (i, m) {
		circ (k, 0, n) {
			rem val = dp[o][k][0];
			if (val) {
				dp[x][k][0] += val * rem(2);
				if (k > 0) dp[x][k - 1][k == 1] += val;
				dp[x][k + 1][0] += val;
			}
			val = dp[o][k][1];
			if (val) {
				dp[x][k][1] += val * rem(2);
				if (k > 0) dp[x][k - 1][1] += val;
				dp[x][k + 1][1] += val;
			}
		}
		swap(o, x);
		memset(dp[x], 0, sizeof(dp[x]));
	}
	circ (k, 0, n) ans += dp[o][k][1];
	ans *= rem(4);
	printf("%d\n", ans.w);
}

Measured memory_bytes: 3844
#include <stdio.h>

int main(void)
{
	int a;
	int i;
	int num[100];
	int count = 0;
	
	
		
	while(scanf("%d", &a)!=EOF){
		
		if(a!=0){
			num[count] = a;
			count++;
		}else if(a==0){
			printf("%d\n", num[count-1]);
			count--;
		}
		
	}
	
	/* printf("Hello, world\n"); */
	return 0;
}

Measured memory_bytes: 600
//In The Name Of GOD
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 2000000000;
const int maxn = 100000;
#define ll long long
#define pb push_back
#define mp make_pair
#define IO ios_base::sync_with_stdio(false);
int main(){
  IO;
  int n,m;
  cin>>n>>m;
  if(m==1||m==2*n-1)
    cout<<"No";
  else{
    cout<<"Yes\n";
    for(int i=0;i<2*n-1;i++)
      cout<<(i+m-n+2*n-1)%(2*n-1)+1<<endl;
  }
}


Measured memory_bytes: 1536
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0


ans=0

n=I()
a=LI()

m=inf
for i in a:
    if i<=m:
        ans+=1
    m=min(i,m)

print(ans)


Measured memory_bytes: 69964
#include<stdio.h>
#define N 10000
  
 main(){
  int i,j,k,l,count=0,a[N],b,c[N],d;
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&a[i]);
  }
  
  scanf("%d",&d);
  for(j=0;j<d;j++){
    scanf("%d",&c[j]);
  }
  
 for(i=0;i<d;i++){
    for(j=0;j<b;j++){
      if(a[j]==c[i]){  
    count++;
    break;
      }
    }
  }
 printf("%d\n",count);
 return 0;
 }

Measured memory_bytes: 1868
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string S;
    cin >> S;
    bool ans = S.size() % 2 == 0;
    if (ans) {
        rep(i, S.size() / 2) {
            if (S.substr(2 * i, 2) != "hi") ans = false;
        }
    }
    write(ans ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n;
	vector<ll> l;
	cin >> n;
	ll x;
	FOR(i,n){cin >> x;l.push_back(x);};

	sort(all(l));
	int ans=0;

	FOR(i,n-1){
		for(int j=i+1;j<n;j++){
			int p=lower_bound(all(l),l[i]+l[j])-l.begin();
			ans+=max(p-j-1,0);
			
			
		}	
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;

int main() {
	int n;
	cin >> n;
	vi a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	int cou = 0;
	while (1) {
		rep(i, 0, n) {
			if (a[i] % 2 != 0) {
				cout << cou << endl;
				return 0;
			}
			a[i] /= 2;
		}
		cou++;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int N;
    bool ok;
    cin>>N;
    vector<int> v,ans;
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    for(int i=0;i<N;i++){
        ok=false;
        for(int j = v.size()-1;j>=0;j--){
            if((j+1)==v[j]){
                ok=true;
                ans.push_back(v[j]);
                v.erase(v.begin()+j);
                break;
            }
        }
            
        if(ok == false){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <iostream>



int main()
{
    int N;
    std::cin >> N;
    std::vector<int> A(N);

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


    int x = 0;
    for (int i = 0; i < N-1; i+=2)
    {
        x += A[i] - A[i+1];
    }
    x += A[N-1];
    
    printf("%d ", x);

    for (int i = 0; i < N - 1; i++)
    {
        x = 2*A[i] - x;
        if (i != N - 2) 
        {
            printf("%d ", x);
        }
        else
        {
            printf("%d\n", x);
        }
    }

    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main() {
    int q;
    cin>>q;
    vector<int> l(q),r(q);
    for(int i=0; i<q; i++) cin>>l[i]>>r[i];
    vector<bool> p(1e5+1,false);
    for(int i=2; i<=1e5; i++){
        p[i]=true;
    }
    for(int i=2; i<=1e5; i++){
        if(p[i]){
            for(int j=2*i; j<=1e5; j+=i){
                p[j]=false;
            }
        }
    }
    vector<int> pp(1e5+1,0);
    vector<int> sum(1e5+2,0);
    for(int i=3; i<=1e5; i++){
        if(p[i]&&p[(i+1)/2]) pp[i]++;
    }
    for(int i=2; i<=1e5; i++){
        sum[i+1]=sum[i]+pp[i];
    }
    for(int i=0; i<q; i++) r[i]++;
    for(int i=0; i<q; i++){
        cout<<sum[r[i]]-sum[l[i]]<<endl;
    }

}


Measured memory_bytes: 2176
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

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

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];

    int ans = 0;
    vector<int> sum(N);
    sum[0]              = A[0];
    FOR(i, 1, N) sum[i] = sum[i - 1] + A[i];
    REP(i, N) {
        int a = sum[i];

        FOR(j, i, N) a += B[j];
        chmax(ans, a);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# map(int, input().split())

S = input()
T = input()

ans = 100000000
for i in range(len(T),len(S)+1):
    sub = S[i-len(T):i]
    count = 0
    for j in range(len(T)):
        if sub[j] != T[j]:
            count += 1
            
    ans = min(ans,count)
    
print(ans)

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

using namespace std;

const int mod = 998244353;

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

  vector<long long> A(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  vector<vector<long long>> dp(N + 10, vector<long long>(S + 10, 0));
  dp[0][0] = 1;

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= S; j++) {
      dp[i][j] += dp[i - 1][j] * 2;
      dp[i][j] %= mod;
      if (j + A[i] <= S) {
        dp[i][j + A[i]] += dp[i - 1][j];
        dp[i][j + A[i]] %= mod;
      }
    }
  }
  cout << dp[N][S] << "\n";

  return 0;
}

Measured memory_bytes: 74200
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
d = [tuple(map(int, input().split())) for _ in range(m)]
d.sort(key=lambda p: -p[1])
now = 0
for b, c in d:
    while b > 0:
        if c > a[now]:
            a[now] = c
            now += 1
            b -= 1
            if now == len(a):
                break
        else:
            break
    if now == len(a):
        break
print(sum(a))


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

using namespace std;

struct station {
    int c, s, f;

    station() {}
};

int main() {
    int n;
    cin >> n;
    vector<station> a(n - 1);
    for (int i = 0; i < n - 1; ++i) {
        cin >> a[i].c >> a[i].s >> a[i].f;
    }
    vector<int> ans(n, 0);
    for (int i = 0; i < n - 1; ++i) {
        int prev = 0;
        for (int j = i; j < n - 1; ++j) {
            if (prev < a[j].s) {
                ans[i] += a[j].s - prev;
                prev = a[j].s;
            }
            while ((prev % a[j].f) != 0) {
                ++prev;
                ++ans[i];
            }
            ans[i] += a[j].c;
            prev += a[j].c;
        }
    }
    for (auto x : ans) {
        cout << x << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void sub_main(istream &cin) {
    ll N;
    cin >> N;
    if(!cin) return;
    ll red;
    red = 0;
    for (int i = 0; i < N; ++i) {
        char t;
        cin >> t;
        if(t == 'R') red++;
        else red--;
    }// i
    cout << (red > 0 ? "Yes" : "No") << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test_B.txt";
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#\n";
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


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

int main(){
  char a,b,c,C,B,A;
  cin >>a>>b>>c>>C>>B>>A;
  if(a==A&&b==B&&c==C){
    cout <<"YES"<<endl;
  }else{
    cout <<"NO"<<endl;
  }
}

Measured memory_bytes: 256