akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;

const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int main() {
    int H, N;

    cin >> H >> N;

    ll acc = 0;

    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        acc += tmp;
    }

    if(acc >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

using namespace std;

#define ll long long

const int N=1e6+5,MOD=1000000007;

int n,b[N],a[N],q,m,u,v,tc,k,l,ans,x;

char s[N];

int main(){ 
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
   
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++){
        if (a[i]!=a[i-1])
            a[i]--;
        if (a[i]>a[i+1])
            return !printf("No\n");
    }
    printf("Yes\n");
}   


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	i64 ans = 0;
	std::map<int, int> cnt;
	for(int i = n - 1; i >= 0; i--) {
		ans += cnt[a[i] + i];
		cnt[i - a[i]]++;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 20972
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    for(int i=0;i<min(k,(int)s.size());i++){
        if(s.at(i)!='1') {
            p(s.at(i))
            return 0;
        }
    }
    p("1")
} 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


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


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, P, C):
    P = [p-1 for p in P]

    done = set()
    cycles = []
    for i in range(N):
        c = i
        t = []
        while c not in done:
            n = P[c]
            done.add(c)
            t.append(c)
            c = n
        if t:
            cycles.append(t)

    ans = -INF
    for c in cycles:
        cs = sum(C[v] for v in c)
        if cs > 0:
            m = max(0, (K // len(c)) - 1)
            k = K - len(c) * m
            a = cs * m
            ans = max(ans, a)
        else:
            k = min(len(c), K)
            a = 0

        b = a
        for u in c:
            a = b
            for _ in range(k):
                v = P[u]
                a += C[v]
                ans = max(ans, a)
                u = v

    return ans


def main():
    N, K = read_int_n()
    P = read_int_n()
    C = read_int_n()
    print(slv(N, K, P, C))


if __name__ == '__main__':
    main()


Measured memory_bytes: 79304
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  vector<string> x(a);
  for (int i = 0; i < a; i++) {
    cin >> x[i];
  }
  cin >> b;
  vector<string> y(b);
  for (int i = 0; i < b; i++) {
    cin >> y[i];
  }
  int count = 0;
  vector<int> c(a);
  if (a>b) {
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < a; j++) {
      if (x[i] == x[j]) {
        count++;
      }
      if (j < y.size()) {
      if (x[i] == y[j]) {
        count--;
      }
      }
      if (j == a-1) {
        c[i] = count;
        count = 0;
      }
    }
  }
  }
  else {
    for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      if (x[i] == y[j]) {
        count--;
      }
      if (j < x.size()) {
      if (x[i] == x[j]) {
        count++;
      }
      }
      if (j == b-1) {
        c[i] = count;
        count = 0;
      }
    }
  }
  }
  sort(c.begin(), c.end());
  if (c[c.size()-1] < 0) {
    cout << 0 << endl;
  }
  else {
  cout << c[c.size()-1] << endl;
  }
}

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

using namespace std;

const int N = 1e5 + 5;

int dp[N];
bool vis [N];

vector<int> height;

int calc(int x,int k) {
	
	if (x<=0) return 0;
	if (x==1) return dp[x];
	if (vis[x]) return dp[x];
	
	vis[x]=1;
	
	for (int i=1;i<=k;i++) {
		if (x-i>=0) dp[x]= min (dp[x],calc(x-i,k) + abs(height[x]- height[x-i]));
	}
	
	return dp[x];
}
		
		

int main () {
		
	int n,k;
	cin>>n>>k;
	height.emplace_back(INT_MAX);
	for(int i=0;i<n;i++) {
		int a; cin>>a;
		height.emplace_back(a);
	}
	for (int i=1;i<=n;i++) dp[i]=1e9;
	dp[1]=0;
	
	calc(n,k);
	
	//for (int i = 1; i
	
	//for(int i=1;i<=n;i++) cout<<dp[i]<<" ";
	//cout<<endl;
	cout<<dp[n]<<endl;
}
	
	
	


Measured memory_bytes: 12096
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X, Y = lr()
answer = 10 ** 10
if X <= Y:
    answer = Y-X
if -X <= Y:
    answer = min(answer, 1+X+Y)
if X <= -Y:
    answer = min(answer, 1-Y-X)
if -X <= -Y:
    answer = min(answer, 2-Y+X)

print(answer)


Measured memory_bytes: 3060
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String SS, TT;
    SS = sc.next();
    TT = sc.next();
    char[] S = SS.toCharArray();
    char[] T = TT.toCharArray();
    if (S.length < T.length) {
      System.out.println("UNRESTORABLE");
      return;
    }
    for (int i = S.length - T.length; i >= 0; i--) {
      boolean flag = true;
      for (int j = 0; j < T.length; j++) {
        if (S[i + j] == '?')
          continue;
        if (S[i + j] != T[j]){
          flag = false;
        }
      }
      if (flag) {
        for (int j = 0; j < T.length; j++)
          S[i + j] = T[j];
        for (int j = 0; j < S.length; j++)
          if (S[j] == '?')
            S[j] = 'a';
        System.out.println(S);
        return;
      }
    }
    System.out.println("UNRESTORABLE");
  }
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);

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

}


Measured memory_bytes: 3636
d,g=map(int,input().split())
ps=[list(map(int,input().split()))for i in range(d)]
ans=9999999999
for i in range(2**d):
  s=bin(i)[2:].zfill(d)
  c=p=0
  a=[]
  for j in range(d):
    c+=ps[j][0]*int(s[j])
    p+=(ps[j][0]*(j+1)*100+ps[j][1])*int(s[j])
    if s[j]=="0":a.append(j)
  if p>=g:ans=min(ans,c)
  else:
    a.sort(reverse=1)
    while p<g:
      k=min((g-p+(a[0]+1)*100-1)//((a[0]+1)*100),ps[a[0]][0])
      p+=k*(a[0]+1)*100
      if k==ps[a[0]][0]:p+=ps[a[0]][1]
      c+=k
      del a[0]
    ans=min(ans,c)
print(ans)

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

int main(){

  int a=0;
  int b=0;

  cin>>a>>b;
  
  int ans=0;
  
  if(a<10)ans=b+100*(10-a);
  else ans=b;
  
  cout<<ans;
  
}

Measured memory_bytes: 256
using System;

public class Program
{
	const int MAX = 100;
	const int INFTY = (1<<21);
	const int WHITE = 0;
	const int GRAY = 1;
	const int BLACK= 2;

	static int n;
	static int[,] M = new int[MAX,MAX];

	public static void dijkstra()
	{
		int minv;
		int[] d = new int[MAX];
		int[] color = new int[MAX];

		for(int i = 0; i < n; i++){
			d[i] = INFTY;
			color[i] =WHITE;
		}

		d[0] = 0;
		color[0] = GRAY;
		while(true){
			minv = INFTY;
			int u = -1;
			for(int i = 0; i < n; i++){
				if(minv > d[i] && color[i] != BLACK){
					u = i;
					minv = d[i];
				}
			}
			if(u == -1) break;
			color[u] = BLACK;
			for(int v = 0; v < n; v++){
				if(color[v] != BLACK && M[u,v] != INFTY){
					if(d[v] > d[u] + M[u,v]){
						d[v] = d[u] + M[u,v];
						color[v] = GRAY;
					}
				}
			}
		}

		for(int i = 0; i < n; i++){
			Console.WriteLine("{0} {1}", i, d[i] == INFTY ? -1 : d[i]);
		}
	}

	public static void Main()
	{
		n = int.Parse(Console.ReadLine());
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				M[i, j] = INFTY;
			}
		}

		int k, c, u, v;
		for(int i = 0; i < n; i++){
			string[] line = Console.ReadLine().Split(' ');
			u = int.Parse(line[0]);
			k = int.Parse(line[1]);
			for(int j = 0; j < k; j++){
				v = int.Parse(line[2+j*2]);
				c = int.Parse(line[3+j*2]);
				M[u, v] = c;
			} 
		}
		dijkstra();
	}
}

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b;
    cin >> a >> b;

    int ans = a;
    if (a>b) ans--;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let s=read::<String>().chars().collect::<Vec<char>>();
    let t=read::<String>().chars().collect::<Vec<char>>();
    for i in 0..s.len(){
        print!("{}",s[i]);
        if i<t.len(){print!("{}",t[i])}
    }
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

int main() {
  int n=gi();
  vll a(n,0);
  ll ts=0, ans=LLONG_MAX;
  for(int i=0;i<n;i++){
    ts+=(a[i]=gll());
    if(i)a[i]+=a[i-1];
  }
  for(int i=0;i<n-1;i++){
    domin(ans, abs(2*a[i]-ts));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void printv(vector<int>& v){
    for(auto item: v)
        cout<<item<<" ";
    cout<<endl;
}
int main(){
    int N;
    cin >> N;
    vector<int> b(N);
    for(auto& item :b)
        cin >> item;
    vector<int> reverseAns;
    for(int i=0;i<N;i++){
        for(int j=b.size()-1;j>=0;j--){
            if(b[j]==j+1){
                b.erase(b.begin()+j);
                reverseAns.push_back(j+1);
                // printv(reverseAns);
                // printv(b);
                goto succeed;
            }
        }
        goto failure;
        succeed:;
    }
    for (int j = reverseAns.size() - 1; j >= 0; j--)
    {
        cout<<reverseAns[j]<<endl;
    }
    return 0;
    failure:
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
#define int long long
#define REP(i,n) for(int i=0;i<(int)(n); ++i)
signed main() {
  ios::sync_with_stdio(false);
  while(true) {
    int N, M; cin >> N >> M;
    if(N == 0 && M == 0) break;
    vector<int> K(N);
    REP(i,N) cin >> K[i];
    vector<int> psum(N+1);
    psum[0] = 0;
    REP(i,N) psum[i+1] = (psum[i] + K[i]) % M;
    int ans = 0;
    set<int> s;
    s.insert(0);
    for(int i = 1; i <= N; ++i) {
      ans = max(ans, psum[i]);
      s.insert(psum[i]);
      auto lb = s.upper_bound(psum[i]);
      if(lb != s.end()) {
        ans = max(ans, (psum[i] - *lb + M) % M);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2816
def readints(): return map(int,input().split())

W, H, N = readints()
d = [[1 for w in range(W)] for h in range(H)]

for _ in range(N):
    x, y, a = readints()
    if a == 1:
        for h in range(H):
            for w in range(x):
                d[h][w] = 0
                
    elif a == 2:
        for h in range(H):
            for w in range(x,W):
                d[h][w] = 0

    elif a == 3:
        for h in range(y):
            for w in range(W):
                d[h][w] = 0

    else:
        for h in range(y,H):
            for w in range(W):
                d[h][w] = 0

res = 0
for h in range(H):
    res += sum(d[h])

print(res)

Measured memory_bytes: 3188
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e9
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int n;
ll dp[1<<16];
int a[16][16];
ll cost[1<<16];
vector <int> g[1<<16];

ll memo(int msk) {
	if(msk == 0) return 0;
	if(dp[msk] != -1) return dp[msk];
	vector <int> v;
	for(int i=0; i<n; i++) if((msk&(1<<i)) > 0) v.pb(1<<i);
	ll res = 0;
	auto go = [&msk, &res, &v] (int MSK, int idx, auto &func) mutable {
		if(idx == sz(v)) {
			if(MSK > 0) res = max(res, cost[MSK] + memo(msk^MSK));
			return;
		}
		func(MSK, idx+1, func);
		func(MSK|v[idx], idx+1, func);
	};
	go(0, 0, go);
	return dp[msk] = res;
}

int main() {
	int start = clock();
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin >> a[i][j];
	vector <int> v;
	for(int msk=0; msk<(1<<n); msk++) {
		v.clear();
		cost[msk] = 0;
		for(int i=0; i<n; i++) if((msk&(1<<i)) > 0) v.pb(i);
		for(int i=0; i<sz(v); i++) {
			for(int j=i+1; j<sz(v); j++) {
				cost[msk] += a[v[i]][v[j]];
			}
		}
	}
	memset(dp, -1, sizeof dp);
	cout << memo((1<<n)-1) << endl;
	return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    sort(H.begin(), H.end(), greater<int>());
    ll ans = 0;
    rep(i, N) {
    	if (K == 0) ans += H[i];
    	else if (K > 0) --K;
    	else return 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
//
//  main.cpp
//  ABC158B
//
#include <iostream>
#include <algorithm> // min
using namespace std;
int main(int argc, const char * argv[]) {
    long long N,A,B;
    cin>>N>>A>>B;
    long long S=N/(A+B);
    long long M=N%(A+B);
    cout<<A*S+min(A,M)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[200002];
long long b[200002];
long long s[200002];
int check(long long mid,long long q,int n)
{
	for(int i=0;i<n;i++)
	{
		if(s[i]>mid)
		{
			long long u=mid/b[i];
			u=a[i]-u;
			q-=u;
			if(q<0) return 0;
		}
	}
	return 1;
}
int main()
{
	int n;
	long long k;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<n;i++) scanf("%lld",&b[i]);
	sort(a,a+n);
	sort(b,b+n,greater<long long>());
	for(int i=0;i<n;i++)
	{
		s[i]=a[i]*b[i];
	}
	long long r=1000000000000,l=0;
	while(r>l)
	{
		long long mid=l+(r-l)/2;
		if(check(mid,k,n))
		{
			r=mid;
		}
		else
		{
			l=mid+1;
		}
	//	cout<<r<<' '<<l<<endl;
	}
	printf("%lld",r);
	return 0;
} 

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
int calc(int n,int i){
  int j=0;
  while(n>1){
    j+=n/i;
    n/=i;
    }
  return j;
  }
    
int main(){
  int n,a;
  cin>>n>>a;
  int x[n];
  rep(i,n){
    cin>>x[i+1];
    x[i+1]-=a;
    }
  ll dp[51][5001];
  rep(i,51)rep(j,5001)
    dp[i][j]=0;
  dp[0][2500]=1;
  rep(i,n)rep(j,5001){
    if(0<=j-x[i+1]&&j-x[i+1]<=5000)
      dp[i+1][j]=dp[i][j-x[i+1]]+dp[i][j];
    else
      dp[i+1][j]=dp[i][j];
    }
  cout<<dp[n][2500]-1<<endl;
  return 0;
  }

Measured memory_bytes: 2176
import java.util.*;

public class Main {

	public static int[] arr;
	public static char[] answer;
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		arr = new int[4];
		answer = new char[3];
		for (int i = 3; i >= 0; i--) {
			arr[i] = n % 10;
			n /= 10;
		}
		
		answer(0, new char[3]);
		System.out.printf("%d", arr[0]);
		for (int i = 0; i < answer.length; i++) {
			System.out.printf("%c%d", answer[i], arr[i + 1]);
		}
		System.out.printf("=7\n", arr[arr.length - 1]);
	}
	
	public static void answer(int index, char[] ops) {
		if (index == ops.length) {
			if (is7(ops)) {
				for (int i = 0; i < ops.length; i++) {
					answer[i] = ops[i];
				}
			}
		} else {
			ops[index] = '-';
			answer(index + 1, ops);
			ops[index] = '+';
			answer(index + 1, ops);
		}
	}
	
	public static boolean is7(char[] ops) {
		int n = arr[0];
		for (int i = 0; i < ops.length; i++) {
			if (ops[i] == '-') {
				n -= arr[i + 1];
			} else if (ops[i] == '+') {
				n += arr[i + 1];
			}
		}
		return n == 7;
	}
}


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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		selectionSrot(A, N);
		scan.close();
	}

	public static void selectionSrot(int[] A, int N) {
		// ???????????°
		int count = 0;
		
		for (int i = 0; i < N - 1; i++) {
			// ???????????????????????????????????\??¨
			int initialA = A[i];
			int minIndex = i;
			for (int j = i + 1; j < A.length; j++) {
				if (A[minIndex] > A[j]) {
					minIndex = j;
				}
			}
			// ????°??????????????????????????????¨??????
			int temp = A[i];
			A[i] = A[minIndex];
			A[minIndex] = temp;
			// ???????????????????????§??????
			if (initialA != A[i]) {
				count++;
			}

		}
		
		String output = Arrays.toString(A).replaceAll(",", "");
		System.out.println(output.substring(1, output.length() - 1));
		System.out.println(count);
	}
}

Measured memory_bytes: 26368
#include <iostream>
using namespace std;
#define N 100
static const int white=0;
static const int gray=1;
static const int black=2;
static const int infty=(1<<21);

int n,M[N][N];

int prim(){
    int u,minv;
    int d[N],p[N],color[N];
    
    for(int i=0;i<n;i++){
        d[i]=infty;
        p[i]=-1;
        color[i]=white;
    }
    d[0]=0;
    
    while(1){
        minv=infty;
        u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=black){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1)break;
        color[u]=black;
        
        for(int v=0;v<n;v++){
            if(color[v]!=black&&M[u][v]!=infty){
                if(d[v]>M[u][v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=gray;
                }
            }
        }
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if (p[i]!=-1)sum += M[i][p[i]];
    }
    return sum;
    }
    
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int e;
            cin>>e;
            M[i][j]=(e==-1)?infty:e;
        }
    }
    cout<<prim()<<endl;
    
    return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;

typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef double db;

#define in(x) cin >> x
#define ini(x) int x; cin >> x
#define inl(x) ll x; cin >> x
#define ins(x) string s; cin >> x

#define out(x) cout << x;
#define outb(x) cout << x << ' ';
#define outn(x) cout << x << '\n';

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for (int i = s; i < e; ++i)
#define fors(i, n) for (int i = 1; i*i <= n; ++i)

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	forn(i, 0, 2) {
		ini(a);
		if (a % 2 == 0) {
			outn("No");
			return 0;
		}
	}
	outn("Yes");
	
	return 0;
}


Measured memory_bytes: 256
N,Q = map(int,input().split())
S = input()
S_nums = [0 for _ in range(N+2)]
for idx in range(N):
  if S[idx-1:idx+1] == 'AC': S_nums[idx+1] = S_nums[idx] + 1
  else: S_nums[idx+1] = S_nums[idx]

for _ in range(Q):
  l,r = map(int, input().split())
  print(S_nums[r]-S_nums[l])

Measured memory_bytes: 51104
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

typedef struct{
    int team, point ,result;
}team;

void sort2(team t[105], int n){
    rep(i,n){
        rep(j,n - 1){
            if(t[j].team > t[j + 1].team){
                team temp = t[j];
                t[j] = t[j + 1];
                t[j + 1] = temp;
            }
        }
    }
}

void sort(team t[105], int n){
    rep(i,n){
        rep(j,n - 1){
            if(t[j].point < t[j + 1].point){
                team temp = t[j];
                t[j] = t[j + 1];
                t[j + 1] = temp;
            }
        }
    }
}

int main(){
    int n;
    team t[105];
    rep(i,105){
        t[i].team = i;
        t[i].point = 0;
    }
    t[0].point = -1;
    cin >> n;
    rep(i, n * (n - 1) / 2){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if(c > d){
            t[a].point+=3;
        }else if(c < d){
            t[b].point+=3;
        }else{
            t[a].point++;
            t[b].point++;
        }
    }
    sort(t,n + 1);
    int j = 1;
    rep(i,n + 1){
        if(i && t[i - 1].point != t[i].point) j = i + 1;
        t[i].result = j;
    }
    sort2(t, n + 1);
    range(i,1,n + 1){
        cout << t[i].result << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int s;
const int nax=3005;
ll mod=998244353;
int a[nax];
ll dp[nax][nax];
inline ll adds(ll a, ll b){
    a+=b;
    if(a>=mod) a-=mod;
    return a;
} 
ll fun(int st, int end){
    if(st == end){
        return a[st]==s;
    }
    int mid=(st+end)/2;
    ll ans=(fun(st,mid)+fun(mid+1,end))%mod;
    int n=end-st+1;
    int S=0;
    for(int i=st;i<=end;i++) S+=a[i];
    S=min(S,s);
    for(int i=mid+1;i<=end;i++){
        for(int j=0;j<=S;j++){

            if(j==0){
                dp[i-st][j]=1; continue;
            }
            if(i==mid+1){
                if(a[i]==j) dp[i-st][j]=1;
                else dp[i-st][j]=0;
            }
            else{
                dp[i-st][j]=adds(dp[i-1-st][j],(a[i]<=j ? dp[i-1-st][j-a[i]] : (ll)0));
            }
        }
    }
    for(int i=mid;i>=st;i--){
        for(int j=0;j<=S;j++){
            if(j==0){
                dp[i-st][j]=1; continue;
            }
            if(i==mid){
                if(a[i]==j) dp[i-st][j]=1;
                else dp[i-st][j]=0;
            }
            else{
                dp[i-st][j]=adds(dp[i+1-st][j],(a[i]<=j ? dp[i+1-st][j-a[i]] : (ll)0));
            }
        }
    }
    ll t1[s+1]={0};
    for(int j=0;j<=S;j++){
        for(int i=mid+1;i<=end;i++){
            t1[j]=adds(t1[j],dp[i-st][j]);
        }
    }
    for(int j=0;j<=S;j++){
        ll g=0;
        for(int i=mid;i>=st;i--){
            g=adds(g,dp[i-st][j]);
        }
        ans=adds(ans, (g*t1[s-j])%mod );
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n>>s;
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<fun(0,n-1)<<"\n";
}


Measured memory_bytes: 70784
parse_input(type=String, x=readline()) = begin
  type == String && return x
  parse(type, x)
end
parse_inputs(type=String) = parse_input.(type, split(readline()))

function main()
  n, m = parse_inputs(Int)
  Int(n*(n-1)/2 + m*(m-1)/2)
end

println(main())


Measured memory_bytes: 181664
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

[[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max();
[[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min();
[[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max();

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

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

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

ll csum(ll x, ll y) {
    if (x > 0 && y > 0 && x > LL_MAX - y) {
        return LL_MAX;
    }
    if (x < 0 && y < 0 && x < LL_MIN - y) {
        return LL_MIN;
    }
    return x + y;
}

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N;
    cin >> N;
    vector<ll> smalls(N);
    vector<ll> larges(N);
    rep(i,0,N) {
        cin >> smalls[i] >> larges[i];
    }
    sort(smalls.begin(), smalls.end());
    sort(larges.begin(), larges.end());
    ll small = 0;
    ll large = 0;
    if (N % 2 == 0) {
        small = smalls[N/2] + smalls[N/2-1];
        large = larges[N/2] + larges[N/2-1];
    } else {
        small = smalls[N/2];
        large = larges[N/2];
    }
    cout << large - small + 1 << endl;
}


Measured memory_bytes: 5960
#include<iostream>
#include<cstring>
#include<queue>

typedef std::pair<int, int> P;
int vx[] = { 0, 1, 0, -1, 1, 1, -1, -1 }, vy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int w, h;
int map[51][51];

void bfs(int x, int y){

	map[y][x] = 0;

	std::queue<P>que;
	que.push(P(x, y));

	while (!que.empty()){

		P p = que.front();
		que.pop();

		for (int i = 0; i < 8; i++){
			int nx = p.first + vx[i], ny = p.second + vy[i];

			if (0 <= nx&&nx < w && 0 <= ny&&ny < h&&map[ny][nx] != 0){
				map[ny][nx] = 0;
				que.push(P(nx, ny));
			}
		}
	}

	return;
}

int main(){

	while (std::cin >> w >> h, w || h){

		int cnt = 0;

		memset(map, 0, sizeof(map));
	
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				std::cin >> map[i][j];
			}
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (map[i][j] != 0){
					bfs(j, i);
					cnt++;
				}
			}
		}

		std::cout << cnt << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;

public class Main {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int z = sc.nextInt();
        int[] w = new int[z];
        for(int i = 0; i < z; i++){
            w[i] = i+1;
        }
        int n = sc.nextInt();
        for(int j = 0; j<n; j++){
            String s = sc.next();
            String[] ab = s.split(",");
            int a = Integer.parseInt(ab[0])-1;
            int b = Integer.parseInt(ab[1])-1;
            int c = w[a];
            w[a] = w[b];
            w[b] = c;
        }
        for(int k = 0; k < z; k++){
            System.out.println(w[k]);
        }
        sc.close();
    }
}


Measured memory_bytes: 26152
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

#define netoze(a) (a<=0?0:a)


int main(void){
	int k, s;
	cin >> k >> s;

	int ans = 0;
	reg(x, netoze(s-2*k), min(k, s)) ans += min(s-x, k) - netoze((s-x)-k)  + 1;

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

Measured memory_bytes: 256
import sys

r, c = map(int, sys.stdin.readline().strip().split())

col_sums = [0] * (c + 1)

for _ in range(r):
    line = sys.stdin.readline().strip()
    sum = 0
    for col, val in enumerate(map(int, line.split())):
        col_sums[col] += val
        sum += val
    col_sums[c] += sum
    print(f'{line} {sum}')

print(' '.join(map(str, col_sums)))



Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int main(){
    int N,K,Q; cin >> N >> K >> Q;
    vector<int> vec(N,0);
    for(int i=0;i<Q;i++){
        int j; cin >> j; j--;
        vec[j]++;
    }
    for(int i=0;i<N;i++){
        if(vec[i] > Q-K) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 1024
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    int A = 0, B = 0, C = 0, D = 0;
    rep(i, 0, N){
        string S;
        cin >> S;
        if(S == "AC") A++;
        if(S == "WA") B++;
        if(S == "TLE") C++;
        if(S == "RE") D++;
    }
    cout << "AC x " << A << endl;
    cout << "WA x " << B << endl;
    cout << "TLE x " << C << endl;
    cout << "RE x " << D << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;



int main()
{
    string s;
    string t;
    cin>>s>>t;
    ll n=zz(s);
    ll m=zz(t);

    ll dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    string ans=" ";
    for(ll i=1; i<=n; i++)
    {
        for(ll j=1; j<=m; j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=max(dp[i-1][j],1+dp[i-1][j-1]);
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }


//    for(ll i=1; i<=n; i++)
//    {
//        for(ll j=1; j<=m; j++)
//        {
//            cout<<dp[i][j]<<ss;
//        }
//        cout<<nn;
//    }
//



    ll st=m;
    ll i=n,j=m;
    while(1)
    {
        if(i==0||j==0)
            break;

        if(dp[i][j]==dp[i][j-1])
        {
            j--;
            continue;
        }
        if(dp[i][j]==dp[i-1][j])
        {
            i--;
            continue;
        }
        ans+=t[j-1];
        i--;
        j--;


    }


    reverse(all(ans));
    cout<<ans<<nn;

    // cout<<dp[n][m]<<nn;







}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 73980
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    H,W,A,B = map(int,input().split())
    MAXN = H + W + 3
    factorial = [1]
    for i in range(1,MAXN + 1):
        factorial.append(factorial[-1]*i%MOD)
    inv_factorial = [-1] * (MAXN + 1)
    inv_factorial[-1] = pow(factorial[-1],MOD - 2,MOD)
    for i in range(MAXN - 1,-1,-1):
        inv_factorial[i] = inv_factorial[i + 1]*(i + 1)%MOD
    
    fact = lambda N:factorial[N]
    nck = lambda N,K: 0 if K > N or K < 0 else factorial[N]*inv_factorial[N - K]*inv_factorial[K]%MOD
    dist = lambda sy,sx,gy,gx: nck(gy - sy + gx - sx,gy - sy)
    ans = 0
    if H - A < W - B:
        H,W = W,H
        A,B = B,A
    
    for i in range(W - B):
        x = B + i + 1
        y = H - A - i
        ans += dist(1,1,y,x)*dist(y,x,H,W)%MOD
        ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 18988
n = int(input())

taro = 0
hanako = 0
for _ in range(n):
    
    cards = list(input().split())
    win_card = sorted(cards, reverse=True)[0]
    
    if cards[0] == cards[1]:
        taro += 1
        hanako += 1
    elif cards.index(win_card) == 0:
        taro += 3
    elif cards.index(win_card) == 1:
        hanako += 3

print(f"{taro} {hanako}")


Measured memory_bytes: 5612
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
long long int sum=0;
int a[100001];
long long int n,j,ans;
int pd(int i)
{	
	//for(j=0;j<=i;j++)
	sum+=a[i];
	for( j=i+1;j<n;j++)
	{
		if(2*sum>=a[j])
		sum+=a[j];
		else
		return j;
	}
	return 0;
}
int main()
{
	int i,s;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{	s=pd(i);
		if(!s)
		break;
		i=s-1;
	}
	ans=n-i;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int a[3],b[3];
    rep(i,3){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+3);
    if(a[1]==b[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3616
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll M;
    cin >> M;
    ll d[200010], c[200010];
    rep(i,0,M) cin >> d[i] >> c[i];
    ll ans = 0;
    rep(i,0,M){
        ll val = (c[i] - 1) + max(0LL, (d[i] * c[i] - 1) / 9);
        ans += val;
    }
    vector<ll> nxt[10];
    rep(n,0,10){
        ll cur = n;
        nxt[n].push_back(cur);
        while(1){
            cur += n;
            if(cur >= 10){
                cur = cur / 10 + cur % 10;
            }
            // print(n, cur);
            if(cur == nxt[n][0]) break;
            nxt[n].push_back(cur);
        }
    }
    ll num[200010] = {};
    rep(i,0,M){
        ll sz = nxt[d[i]].size();
        ll amari = c[i] % sz;
        if(amari == 0){
            num[i] = nxt[d[i]][sz-1];
        }else{
            num[i] = nxt[d[i]][amari-1];
        }
    }
    // printa(num, M);
    // rep(i,0,10){
    //     rep(j,0,nxt[i].size()){
    //         cout << nxt[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // print(ans);
    ll idx = 0;
    while(idx != M-1){
        ll v1 = num[idx];
        ll v2 = num[idx+1];
        ll v3 = v1 + v2;
        ans++;
        if(v3 >= 10){
            num[idx] = v3 / 10;
            num[idx+1] = v3 % 10;
        }else{
            num[idx+1] = v3;
            idx++;
        }
    }

    print(ans);
    // vector<ll> v;
    // ll sum = 0;
    // while()
    // rep(i,0,M) sum += num[i];
    // ans += (M-1) + sum / 10;

    // print(ans);

    

}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>

using StateVec = std::vector<bool>;

bool findSolution(const StateVec& ls, StateVec& solution) {
    if (ls.size() < 3) {
        return false;
    }

    const auto lastI = ls.size() - 1u;
    const bool initSet[][2] = {{true, true}, {true, false}, {false, true}, {false, false}};

    for(const auto& s : initSet) {
        solution[0] = s[0];
        solution[1] = s[1];
        for(decltype(ls.size()) i = 1; i < lastI; ++i) {
            solution[i+1] = solution[i] ^ ls[i] ^ solution[i-1];
        }

        if (!(solution[lastI] ^ ls[lastI] ^ solution[lastI-1] ^ solution[0]) &&
            !(solution[0] ^ ls[0] ^ solution[lastI] ^ solution[1])) {
            return true;
        }
    }

    return false;
}

int main(int argc, char* argv[]) {
    std::string line;
    std::getline(std::cin, line);
    std::getline(std::cin, line);

    StateVec ls;
    for(auto c : line) {
        ls.push_back(c == 'o');
    }

    StateVec solution;
    solution.assign(ls.size(), false);

    std::string str;
    if (findSolution(ls, solution)) {
        for(auto b : solution) {
            str += (b) ? "S" : "W";
        }
    } else {
        str += "-1";
    }

    std::cout << str << "\n";
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>
#include <array>
#include <deque>

int H, W, N;
std::string S, T;

int main (void) {
  std::cin >> H >> W >> N;

  std::pair<int,int> start;
  std::cin >> start.first >> start.second;

  std::cin >> S >> T;


  // vertical
  std::deque<int> v;
  for(int i=1; i<=H; i++) v.push_back(i);

  for(int i=N-1; i>=0; i--) {
    if ( T[i] == 'U' && v.back() != H ) {
      v.push_back(v.back()+1);
    }
    if ( T[i] == 'D' && v.front() != 1 ) {
      v.push_front(v.front()-1);
    }

    if ( S[i] == 'U' || S[i] == 'D') {
      if ( S[i] == 'U' ) v.pop_front();
      if ( S[i] == 'D' ) v.pop_back();
      if ( v.size() == 0 ) {
        std::cout << "NO" << std::endl;
        return 0;
      }
    }
  }
  if ( std::find(v.begin(), v.end(), start.first) == v.end() ) {
    std::cout << "NO" << std::endl;
    return 0;
  }

  // horizontal
  std::deque<int> h;
  for(int i=1; i<=W; i++) h.push_back(i);

  for(int i=N-1; i>=0; i--) {
    if ( T[i] == 'L' && h.back() != W ) {
      h.push_back(h.back()+1);
    }
    if ( T[i] == 'R' && h.front() != 1 ) {
      h.push_front(h.front()-1);
    }

    if ( S[i] == 'L' || S[i] == 'R') {
      if ( S[i] == 'L' ) h.pop_front();
      if ( S[i] == 'R' ) h.pop_back();
      if ( h.size() == 0 ) {
        std::cout << "NO" << std::endl;
        return 0;
      }
    }
  }
  if ( std::find(h.begin(), h.end(), start.second) == h.end() ) {
    std::cout << "NO" << std::endl;
    return 0;
  }

  // pass
  std::cout << "YES" << std::endl;

  return 0;
}

Measured memory_bytes: 2312
#include <cstdio>
#include <iostream>
using namespace std;
string sig[11]={
"0111111",
"0000110",
"1011011",
"1001111",
"1100110",
"1101101",
"1111101",
"0100111",
"1111111",
"1101111"
};
string now;
int main() {
    int n;
    while (scanf("%d",&n)) {
        if (n==-1) break;
        now="0000000";
        for (int i=0; i<n; i++) {
            int s; scanf("%d",&s);
            string res="";
            for (int j=0; j<7; j++) {
                if (now[j]==sig[s][j]) res+='0';
                else res+='1';
            }
            cout<<res<<endl;
            now=sig[s];
        }
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int n;
	cin>>n;
	cout<<n+(n*n)+(n*n*n)<<endl;	
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
    int H,W;
    int i,j,k,count;

    int a[100][2];

    for(count=0;;count++){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0){
            break;
        }

        a[count][0]=H;
        a[count][1]=W;
    }

    for(i=0;i<count;i++){
        /* 長方形 */
        H = a[i][0];
        W = a[i][1];

        for(j=0;j<H;j++){
            if(j==0||j==(H-1)){
                for(k=0;k<W;k++){
                    printf("#");
                 }
            }
            else{
                /* 横一列 */
                for(k=0;k<W;k++){
                    if(k==0 || k ==(W-1)){
                        printf("#");
                    }
                    else{
                        printf(".");
                    }
                }
            }

            printf("\n");
        }
        printf("\n");
    }
    return 0;
}





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

ll H, W;
vector<string> S;

bool isOK(ll x, ll y) {
    return 0 <= x && x < W && 0 <= y && y < H;
}

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

ll ans;

vector<vector<bool>> isvisit;

array<ll, 2> solve(ll x, ll y) {
    array<ll, 2> result{};
    result[S[y][x] == '.']++;
    isvisit[y][x] = true;
    for (ll i = 0; i < 4; i++) {
        ll nx = x + dx[i];
        ll ny = y + dy[i];
        if (isOK(nx, ny) && S[ny][nx] != S[y][x] && !isvisit[ny][nx]) {
            auto r = solve(nx, ny);
            result[0] += r[0];
            result[1] += r[1];
        }
    }
    return result;
}

int main() {
    cin >> H >> W;
    S.resize(H);
    for (ll i = 0; i < H; i++) {
        cin >> S[i];
    }

    isvisit.resize(H, vector<bool>(W, false));

    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            if (isvisit[i][j]) {
                continue;
            }
            auto r = solve(j, i);
            ans += r[0] * r[1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 15488
#include<bits/stdc++.h>
using namespace std;
const int md=1e9+7;
int n,m,f[33005][20],c[33005][20],d[20][20];
vector<pair<int,int> >g[20];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);u--;v--;
		d[u][v]=d[v][u]=w;
	}
	for(int msk=0;msk<(1<<n);msk++)for(int i=0;i<n;i++)
	{
		f[msk][i]=1e9+7;
		for(int j=0;j<n;j++)if(msk&(1<<j))c[msk][i]+=d[i][j];
	}
	f[1][0]=0;
	for(int msk=0;msk<(1<<n);msk++)
	{
		for(int i=0;i<n;i++)if(msk&(1<<i)&&f[msk][i]!=1e9+7)
		{
			for(int j=0;j<n;j++)
			{
				if(!(msk&(1<<j))&&d[i][j])
				{
					f[msk|(1<<j)][j]=min(f[msk|(1<<j)][j],f[msk][i]+c[msk][j]-d[i][j]);
				}
			}
			int nxt=msk^(1<<i),st=((1<<n)-1)^msk,s;
			for(int j=st;j>0;j=(j-1)&st)
			{
				s=0;
				for(int l=0;l<n;l++)if(j&(1<<l))s+=c[nxt][l];
				f[msk|j][i]=min(f[msk|j][i],f[msk][i]+s);
			}
		}
	}
	printf("%d\n",f[(1<<n)-1][n-1]);
	return 0;
}

Measured memory_bytes: 5376
n, k =map(int,input().split())
a = list(map(int,input().split()))
ans = 0
u = 1000000007
for i in range(n):
    p = a[i]
    l = 0
    r = 0
    for j in range(i+1,n):
        if p > a[j]:
            r += 1
    ans += r*k*(k+1)//2
    ans %= u
    for g in range(0,i):
        if p > a[g]:
            l += 1
    ans += l*k*(k-1)//2
    ans %= u
print(int(ans))

Measured memory_bytes: 3188