akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(ll)(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

vl stones;
vl dp;


ll cheap(ll in){
    if(dp[in] != -1){
        return dp[in];
    }
    ll mini = oo;
    FOR(i,max(in-2,0LL),in){
       ll res = cheap(i);
       ll ad = abs(stones[i] - stones[in]);
       mini = min(mini, res+ad);
    }
    dp[in] = mini;
    return mini;
}

int main(){
    ll N;
    cin >> N;
    FOR(ghjk,0,N){
        ll in;
        cin >> in;
        dp.pb(-1);
        stones.pb(in);
    }
    dp[0] = 0;
    cout << cheap(N-1)<<endl;

} //cin.tie(0) bei schnellem Wechseln




Measured memory_bytes: 4332
#include<iostream>

using namespace std;

int min(int former, int later){
    if(former < later){
        return former;
    }else{
        return later;
    }
}

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

    int a[n];

    int b[n + 1];
    for(int i = 0; i < n - 1; i++){
        cin >> b[i];
    }
    b[n - 1] = b[n - 2];
    b[n] = b[n - 1];

    for(int i = 0; i < n; i++){
        if(i > 0){
            a[i] = min(b[i], b[i - 1]);
        }else{
            a[i] = b[i];
        }
    }

    int result = 0;
    for(int i = 0; i < n; i++){
        result += a[i];
    }

    cout << result;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var s = consoleReader.String.Replace("BC", "@").Select(c => c - '@').SkipWhile(i => i != 1).ToArray();
            var N = s.Length;

            var aCount = 0;
            long count = 0;

            for (int i = 0; i < N; i++)
            {
                switch (s[i])
                {
                    case 0:
                        count += aCount;
                        break;
                    case 1:
                        ++aCount;
                        break;
                    default:
                        aCount = 0;
                        break;
                }
            }

            return count;
        }

        static string Debug(int[] s) => new string(s.Select(i => (char)(i + '@')).ToArray());

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> Split { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

Measured memory_bytes: 15072
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); //入出力高速化
  int N; cin >> N;
  int k = 0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<18> s(tmp);
    cout << k << ":";
    k++;
    rep(i,N) {
      if (s.test(i)) cout << " " << i;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>

using namespace std;

int gcd(int a, int b) {
    if (a < b) {
        int temp = a;
        a = b;
        b = temp;
    }
    if (b == 0) return a;
    
    int temp;
    while ((temp = a % b) != 0) {
        a = b;
        b = temp;
    }
    return b;
}

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

    int L[N+1]; // L(i+1) = gcd(L(i), A(i))
    int R[N+1]; // R(i) = gcd(R(i+1), A(i))
    L[0] = 0;
    R[N] = 0;
    for (int i = 0; i < N; i++) {
        L[i+1] = gcd(L[i], A[i]);
    }
    for (int i = N-1; i >= 0; i--) {
        R[i] = gcd(R[i+1], A[i]);
    }
    
    int ans = 1;
    for (int i = 0; i < N; i++) {
        int temp =  gcd(L[i], R[i+1]);
        if (temp > ans) ans = temp;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1,i,j;
    //cin>>t;
    while(t--)
    {
        int n,count=0,sum=0,flag=0,maxi=-1,mini=1e18;
        cin>>n;
        while(n>0)
        {
            if(n%10==7)
            {
                flag=1;
                break;
            }
            n/=10;
        }
        if(flag)
            cout<<"Yes";
        else
            cout<<"No";
    }
}

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

int main()
{
	long q;
	cin >> q;

	map <string, long> mp;

	for (long i = 0; i < q; i++) {
		int t;
		cin >> t;

		string s;
		cin >> s;

		if (t == 0) {
			long x;
			cin >> x;
			mp[s] = x;
		}
		else if (t == 1) {
			std::map<string, long>::iterator itr = mp.find(s);
			if (itr != mp.end())
				cout << itr->second << endl;
			else
				cout << 0 << endl;
		}
		else if (t == 2) {
			mp.erase(s);
		}
	}

	return 0;
}


Measured memory_bytes: 27728
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
uf=UnionFind(n)
for _ in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
  
print(uf.group_count()-1)

Measured memory_bytes: 78972
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define rep(a,b) for(ll int a=0;a<b;a++)
#define Tcase int t;cin>>t;while(t--)
int main(){
  long long int fact[9];
  fact[0]=1;fact[1]=1;
  for(int i=2;i<9;i++)
    fact[i]=fact[i-1]*i;
  int n;
  cin>>n;
  int a[n],b[n];
  int before[n+1],before2[n+1];
  for(int i=1;i<=n;i++)
    before[i]=i-1;
  for(int i=1;i<=n;i++)
    before2[i]=i-1;
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i++)
    cin>>b[i];
  long long int A=0,B=0;
  for(int i=0;i<n;i++){
       // cout<<A<<" "<<n-1-i<<" "<<before[a[i]]<<endl;
  	A+=(before[a[i]])*fact[n-1-i];
    for(int j=a[i]+1;j<=n;j++)
      before[j]--;
  }
  for(int i=0;i<n;i++){
  	B+=(before2[b[i]])*fact[n-1-i];
     for(int j=b[i]+1;j<=n;j++)
      before2[j]--;
  }
  cout<<abs(A-B)<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  ll cnt = 0;
  ll acc = 0;
  ll p = 0;
  for (ll q = 0; q < N; q++) {
    while (p < N && !(acc & A[p])) {
      acc |= A[p];
      p++;
    }
    if (p == N) break;
    cnt += N - p;
    acc ^= A[q];
  }
  cout << N * (N + 1) / 2 - cnt << endl;

  return 0;
}



Measured memory_bytes: 4748
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int dp[101][101];
int cost2cal[101][101];
int cal2well[10101];

int main(){
  //STUNOD
  int upper_HP;
  int total_trainings;
  int training_norma;
  int total_donuts;
  int recover;
  int total_days;
  while(~scanf("%d %d %d %d %d %d",
	       &upper_HP,
	       &total_trainings,
	       &training_norma,
	       &total_donuts,
	       &recover,
	       &total_days)){
    vector<P> trainings;
    for(int training_idx=0;training_idx<total_trainings;training_idx++){
      int training_cost,consume_cal;
      scanf("%d %d",&training_cost,&consume_cal);
      trainings.push_back(P(training_cost,consume_cal));
    }
    vector<P> donuts;
    for(int donuts_idx=0;donuts_idx<total_donuts;donuts_idx++){
      int well_being_level,retain_cal;
      scanf("%d %d",&well_being_level,&retain_cal);
      donuts.push_back(P(well_being_level,retain_cal));
    }

    memset(cost2cal,-1,sizeof(cost2cal));

    cost2cal[0][0] = 0;
    for(int training_idx=0;training_idx<total_trainings;training_idx++){
      int cal = trainings[training_idx].second;
      int training_cost = trainings[training_idx].first;

      for(int prev=training_norma;prev>=0;prev--){
	for(int consumed_HP = upper_HP;consumed_HP >= 0 ;consumed_HP--){
	  if(cost2cal[consumed_HP][prev] == -1) continue;

	  if(consumed_HP + training_cost > upper_HP) continue;
	  cost2cal[consumed_HP + training_cost][prev+1]
	    = max(cost2cal[consumed_HP][prev] + cal,
		  cost2cal[consumed_HP + training_cost][prev+1]);
	}
      }
    }

    memset(cal2well,0,sizeof(cal2well));
    for(int donuts_idx=0;donuts_idx<total_donuts;donuts_idx++){
      int well = donuts[donuts_idx].first;
      int retain = donuts[donuts_idx].second;
      for(int cal=0;cal<=10000;cal++){
	cal2well[cal + retain] = max(cal2well[cal] + well,
				     cal2well[cal + retain]);
      }
    }


    memset(dp,-1,sizeof(dp));
    dp[0][upper_HP] = 0;
    for(int day=0;day<total_days;day++){
      for(int HP=0;HP<=upper_HP;HP++){
	if(dp[day][HP] == -1) continue;
	for(int training_cost=0;training_cost<=HP;training_cost++){
	  if(cost2cal[training_cost][training_norma] == -1) continue;

	  int next_HP = min(HP - training_cost + recover,upper_HP);
	  dp[day+1][next_HP]
	    = max(dp[day][HP] + cal2well[cost2cal[training_cost][training_norma]],
		  dp[day+1][next_HP]);
	}
      }
    }

    int res = -1;
    for(int HP=0;HP<=upper_HP;HP++){
      res = max(dp[total_days][HP],res);
    }
    printf("%d\n",res);
  }
}

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

int main(){
  int s,w;
  scanf("%d%d",&s,&w);

  if(w>=s){
    printf("unsafe\n");}
  else{
    printf("safe\n");}
  
  return 0;
}


Measured memory_bytes: 1648
#include<bits/stdc++.h>
using namespace std;
int read() {
    char cc = getchar(); int cn = 0, flus = 1;
    while(cc < '0' || cc > '9') {  if( cc == '-' ) flus = -flus;  cc = getchar();  }
    while(cc >= '0' && cc <= '9')  cn = cn * 10 + cc - '0', cc = getchar();
    return cn * flus;
}
const int N = 1000 + 5 ; 
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
int n, m, book[N], w[N][N], vis[N], can[N];   
bool check( int x ) {
    memset( book, 0, sizeof(book) ), memset( can, 0, sizeof(can) ) ;
    int flag ; rep( i, 1, n ) vis[i] = 1, ++ book[w[i][vis[i]]] ; 
    rep( i, 1, m ) {
        flag = 1 ; 
        rep( j, 1, n ) {
            int u = w[j][vis[j]] ; 
            if( book[u] > x ) {
                can[u] = 1; flag = 0 ; 
                while( vis[j] <= n && can[w[j][vis[j]]] ) ++ vis[j] ; 
                if( vis[j] > n ) return 0; 
                ++ book[w[j][vis[j]]] ; 
            }
        }
        if( flag ) return 1; 
    }
    return 0 ; 
}
signed main()
{
    n = read(), m = read() ; 
    rep( i, 1, n ) rep( j, 1, m ) w[i][j] = read() ; 
    int l = 1, r = n, ans = 0, mid ; 
    while( l <= r ) {
        mid = ( l + r ) >> 1 ; 
        if( check(mid) ) ans = mid, r = mid - 1 ; 
        else l = mid + 1 ; 
    }
    printf("%d\n", ans ) ; 
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll n;
ll a[200010];

std::deque<ll> deq;

int main()
{
  std::cin >> n;
  rep( i, n )
    std::cin >> a[i];

  bool fl = false;

  rep( i, n )
  {
    if( fl )
      deq.push_back( a[i] );
    else
      deq.push_front( a[i] );

    fl ^= true;
  }

  if( !fl )
    std::reverse( all(deq) );
  
  rep( i, deq.size() )
    std::cout << deq[i] << (i==deq.size()-1?'\n':' ');

  return 0;
}

Measured memory_bytes: 5376
# D
N=int(input())
S=input()
order=list('RGB')
cnt=[[0,0,0] for _ in range(N)]
for i in range(N):
    cnt[i][order.index(S[i])]+=1
    if i!=0:
        for j in range(3):
            cnt[i][j]+=cnt[i-1][j]
ans=0
for j in range(1,N):
    for k in range(j+1,N):
        # print(j,k)
        if S[j]==S[k]:
            continue
        else:
            s=list(set(order)-set([S[j],S[k]]))[0]
            ans+=cnt[j-1][order.index(s)]
            # print('db',ans)
            i=2*j-k
            if i>=0 and S[i]==s:
                # print('!')
                ans-=1
print(ans)

Measured memory_bytes: 69548
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //ramen costs 700YEN and topping costs 100YEN
    //if String first character is 'o', it means it should topped with boiled eggs
    //if first character is 'x', it means it should not top with boiled egg
    //Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions
    // Presence 'o' : absence 'x'
    char line[5];
    scanf("%s", &line);
    int ramenPrice = 700;
    for(int i = 0; i < 3; i++){
        if(line[i] == 'o'){
            ramenPrice += 100;
        }
    }
    printf("%d\n", ramenPrice);
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var H, W, K, ans int
	fmt.Scan(&H, &W, &K)
	mas := make([]string, H)
	for h := range mas {
		fmt.Scan(&mas[h])
	}
	for b := 0; b < (1 << (H + W)); b++ {
		k := 0
		for h := 0; h < H; h++ {
			if (b>>h)&1 == 1 {
				continue
			}
			for w := 0; w < W; w++ {
				if (b>>(H+w))&1 != 1 && string(mas[h][w]) == "#" {
					k += 1
				}
			}
		}
		if k == K {
			ans += 1
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int q;
    cin >> q;
    multiset<int> s;
    while (q--) {
        int c, x;
        cin >> c >> x;
        if (c == 0) {
            s.emplace(x);
            cout << sz(s) << endl;
        } else if (c == 1) {
            cout << s.count(x) << endl;
        } else if (c == 2) {
            s.erase(x);
        } else if (c == 3) {
            int y;
            cin >> y;
            auto st = s.lower_bound(x);
            auto ed = s.upper_bound(y);
            for (;st != ed; st++) cout << *st << endl;
        }
    } 
}



Measured memory_bytes: 12408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Linq.Expressions;

static class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int X, Y;
    readonly int[] Group = new int[13] { -1, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        X = int.Parse(line[0]);
        Y = int.Parse(line[1]);
    }

    public void Solve()
    {
        Scan();
        Console.WriteLine(Group[X] == Group[Y] ? "Yes" : "No");
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int X, Y, Z;
    cin >> X >> Y >> Z;

    int answer = (X - Z) / (Y + Z);
    if (answer <= X){
        cout << answer << endl;
    }
    else {
        cout << X << endl;
    }
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
    long long n, a, b, c, i = 0;
    scanf("%lld",&n);
    for (i = 0; i < n; i++) {
        scanf("%lld %lld %lld",&a, &b, &c);
        if (pow(a, 2) + pow(b, 2) == pow(c, 2)) {
            printf("YES\n");
        }
        else if ((pow(a, 2) + pow(c, 2)) == pow(b, 2)) {
            printf("YES\n");
        }
        else if ((pow(b, 2) + pow(c, 2)) == pow(a, 2)) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
    return (0);
}

Measured memory_bytes: 580
#pragma GCC optimize("O3")
            #pragma comment(linker, "/stack:200000000")
            #pragma GCC optimize("unroll-loops")
             
            #include <algorithm>
            #include <bitset>
            #include <cassert>
            #include <chrono>
            #include <cmath>
            #include <complex>
            #include <cstdio>
            #include <cstdlib>
            #include <cstring>
            #include <ctime>
            #include <deque>
            #include <functional>
            #include <iomanip>
            #include <iostream>
            #include <iterator>
            #include <limits>
            #include <climits>
            #include <list>
            #include <map>
            #include <numeric>
            #include <queue>
            #include <random>
            #include <ratio>
            #include <set>
            #include <sstream>
            #include <stack>
            #include <string>
            #include <unordered_map>
            #include <unordered_set>
            #include <utility>
            #include <vector>
            using namespace std;
             
            typedef long long ll;
            typedef long double ld;
            #define int ll
            #define double ld
            #define pb push_back
            #define mp make_pair
            #define REP(i,n) for (int i = 0; i < n; i++)
            #define loop(i,n) for (int i = 0; i < n; i++)
            #define FOR(i,a,b) for (int i = a; i < b; i++)
            #define REPD(i,n) for (int i = n-1; i >= 0; i--)
            #define FORD(i,a,b) for (int i = a; i >= b; i--)
            #define remax(a,b) a = max(a,b)
            #define remin(a,b) a = min(a,b)
            #define mem(a, b) memset(a, b, sizeof a)
            #define append push_back
            #define all(v) v.begin(),v.end()
            #define F first
            #define S second
            #define print(x) cout << (x) << endl
            #define PRECISION(x) cout << fixed << setprecision(x)
            #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
            
            const double PI=acos(-1);
            const int MOD = 1000000007;
            const int FMOD = 998244353;
            const double eps = 1e-9;
             
            mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
 
signed main(){

	FAST_IO;
	
	int a,b,n;
	cin>>a>>b>>n;
	int x=min(b-1,n);
	int ans=(a*x)/b-a*(x/b);
	cout<<ans;
}
			

Measured memory_bytes: 3656
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, t;
    cin >> n >> t;
    vector<pair<int, int> > v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());

    vector<int> dp(t+1, 0);
    for(int i=0; i<n; ++i){
        for(int j=t-1; j>=0; --j){
            int k = min(t, j + v[i].first);
            dp[k] = max(dp[k], dp[j] + v[i].second);
        }
    }
    cout << dp[t] << endl;

    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.{readLong, readInt}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val arr = (1 to len).toArray.map(a => readLong)
        println(shellSort(arr, len).mkString("\n"))
    }
    
    def shellSort(arr: Array[Long], len: Int): Array[Long] = {
        val copy = new Array[Long](len)
        arr.copyToArray(copy)
        var cnt = 0
        val groups = genGroups(len).reverse
        println(groups.length + "\n" + groups.mkString(" "))
        groups.foreach { g => 
            (0 until g).foreach { start => 
                cnt += insertionSort(copy, start, len, g)
            }
        } 
        println(cnt)
        copy
    }
    
    def insertionSort(arr: Array[Long], start: Int, len: Int, group: Int): Int = {
        var cnt = 0
         Range(start, len, group).foreach { targetIndex => 
             val target = arr(targetIndex)
             Range(start, targetIndex, group).reverse.find { insertIndex =>
                 if (arr(insertIndex) > target) {
                     arr(insertIndex + group) = arr(insertIndex)
                     arr(insertIndex) = target
                     cnt += 1
                     false
                 } else {
                     true
                 }
             }
         }
        cnt
    }
    
    def genGroups(len: Int): List[Int] =  {
        def go(len: Int, glen: Int, next: Int): List[Int] = next match {
            case a if (a == 1) || (a < len && glen < len) => a :: go(len, glen + 1, a * 3 + 1)
            case a => Nil
        }
        go(len, 0, 1)
    }
}


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

int main(){
    string s;
    string t;
    cin >> s >> t;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<s.size();j++){
            if(s[i]<s[j]){
                swap(s[i],s[j]);
                // cout << s << endl;
            }
        }
    }
    for(int i=0;i<t.size();i++){
        for(int j=0;j<t.size();j++){
            if(t[i]>t[j]){
                swap(t[i],t[j]);
                // cout << t << endl;
            }
        }
    }
    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
A_ball = [0 for i in range(N)]

for i in A:
    A_ball[i-1] += 1

max_pattern = 0
for ball in A_ball:
    max_pattern += ball * (ball - 1) /2

for num in A:
    print(int(max_pattern - (A_ball[num-1]-1)))

Measured memory_bytes: 26012
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll a, b, c;
    cin >> a >> b >> c;
    ll x, y;
    cin >> x >> y;
    
    ll ans = a*x + b*y;
    // cout << ans << endl;
    
    for(ll i = 0; i/2 < max(x, y)+1; i+=2) {
        ll temp = a*(max(0LL,x-i/2)) + b*(max(0LL, y-i/2)) + c*i;
        // cout << temp << " " << x-i/2 << " " << y-i/2 << " " << i << endl;
        ans = min(ans, temp);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
 
void cominit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i=2; i<MAX; i++) {
    fac[i] = fac[i-1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
 
ll com(ll n, ll k)
{
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll ans = 0;

    cominit();

    for(ll i = 0; i <= k; i += a){
        if((k-i)%b==0){
            ans += com(n, i/a)%mod*com(n, (k-i)/b)%mod;
            ans %= mod;
        }
    }
    cout << ans%mod << endl;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

ll		f0(ll b, ll md)
{
	ll ret = 0;
	if (b % 4 == 1 || b % 4 == 2)
		ret = (ll)1;
	ll p = 4;
	for (ll i = 1; i <= md; i++) {
		ll m = b % p;
		if (m >= p / 2 && m % 2 == 0)
			ret |= (((ll)1) << i);
		p *= 2;
	}
	return (ret);
}

ll		Xor(ll a, ll b, ll md)
{
	ll ret = 0;
	for (ll i = 0; i <= md; i++) {
		if ((a & (((ll)1) << i)) == (b & (((ll)1) << i)))
			ret &= ~(((ll)1) << i);
		else
			ret |= (((ll)1) << i);
	}
	return (ret);
}

int     main()
{
	ll a, b;
	cin >> a >> b;
	ll md = log2(b);
	ll f0a = f0(a, md);
	ll f0b = f0(b, md);
	ll tmp = Xor(f0a, f0b, md);
	ll fab = Xor(tmp, a, md);
	cout << fab << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long

struct node{
	int id;double val;
	bool operator<(const node b)const{
		return val<b.val;
	}
}h[2010];
signed main(){
	int n,A,i;
	double T;scanf("%lld%lf%lld",&n,&T,&A);
	for(i=1;i<=n;i++){
		double x;scanf("%lf",&x);
		x=T-x*0.006;
		h[i]=(node){i,abs(x-A)};
	}
	sort(h+1,h+n+1);
	printf("%lld\n",h[1].id);
	return 0;
}


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

#define MAX 100002

int n;
vector<long long int> v;

bool flag[MAX];

long long int solve(){
	long long int cur = 0;
	long long int op = 0;
	for (int i = 0; i < n; i++){
		cur += v[i];
		if (cur == 0LL){
			if (flag[i]){
				op++;
				cur++;
			}
			else{
				op++;
				cur--;
			}
			continue;
		}
		if (flag[i] && cur < 0){
			op += abs(cur) + 1LL;
			cur = 1;
			continue;
		}
		if (flag[i] == false && cur > 0){
			op += abs(cur) + 1LL;
			cur = -1;
			continue;
		}
	}
	return op;
}

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	for (int i = 0; i < n; i++){
		flag[i] = (i & 1);
	}
	long long int ans = solve();
	for (int i = 0; i < n; i++){
		flag[i] ^= true;
	}
	ans = min(ans, solve());
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  rep(i, n) {
    if (i == a[a[i]]) ans++;
  }
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

long long gcd(long long a, long long b){
  if(b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long N, M;
  cin >> N >> M;
  vector<long long> X(M);
  for(int i = 0; i < M; i++) {
    cin >> X[i];
  }

  if (M <= N) {
    cout << 0 << endl;
    return 0;
  }

  sort(X.begin(), X.end());

  vector<long long> dist(M - 1);
  for(int i = 0; i < M - 1; i++) {
    dist[i] = X[i + 1] - X[i];
  }

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

  long long ans = X.back() - X.front();

  for(int i = 0; i < N - 1; i++) {
    ans -= dist[i];
  }

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


Measured memory_bytes: 4764
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,k) cin >> a[i];
    for(int i = k; i < n; ++i){
        cin >> a[i];
        if(a[i] > a[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 4780
#!/usr/bin/env python
# -*- coding: utf-8 -*-

M = 1e+9 + 7


def main():
  N, K = map(int, input().split())
  count = 0
  minval = 0
  maxval = 0

  for i in range(1, N + 2):
    minval += i
    maxval += N - i + 2

    if i >= K:
      count = int((count + maxval - minval + 1) % M)

  print(count)


if __name__ == '__main__':
  main()


Measured memory_bytes: 79484
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,i,m;
	string s;
	cin >> s;
	n = s.l_ength();
	for(i=0; i<n; ++i){
		if(s[i]!=s[n-i-1]){
			cout << "No" << endl;
			return 0;
		}
	}
	m = n/2;
	for(i=0; i<m; ++i){
		if(s[i]!=s[m-i-1]){
			cout << "No" << endl;
			return 0;
		}
	}
	for(i=0; i<m; ++i){
		if(s[m+1+i]!=s[m+1+m-i-1]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(i, a) for(auto& i: a)
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int INF = INT_MAX >> 2;
const int MAXN = 10000;
int dp[MAXN * 3];

int main() {
    rep(i, 0, 3 * MAXN) dp[i] = INF;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, n;
    cin >> h >> n;
    dp[0] = 0;
    int ans = INF;
    while(n--) {
        int a, b;
        cin >> a >> b;
        rep(i, a, 3 * MAXN) {
            dp[i] = min(dp[i], dp[i - a] + b);
            if(i >= h) ans = min(ans, dp[i]);
        }
    }
    cout << ans;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
int n,a[200001],i;
int main()
{
    cin>>n; for(i=1;i<=n;i++) cin>>a[i];
    for(i=n;i>=1;i=i-2) cout<<a[i]<<' ';
    for(i=1+n%2;i<=n;i=i+2) cout<<a[i]<<' ';
    return 0;
}


Measured memory_bytes: 2944
var main = function (input: string) {
    let a: string[] = input.split(" ");
    let d: number = parseInt(a[0]);
    let t: number = parseInt(a[1]);
    let s: number = parseInt(a[2]);

    if (t * s >= d) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29584
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int a, b;
  cin >> a >> b;
  a--, b--;
  int h = 100, w = 100;
  char ans[h][w];
  for (int i = 0; i < h / 2; ++i) {
    for (int j = 0; j < w; ++j) ans[i][j] = '.';
  }
  for (int i = h / 2; i < h; ++i) {
    for (int j = 0; j < w; ++j) ans[i][j] = '#';
  }
  for (int i = h / 2 + 1; i < h; i += 2) {
    for (int j = 0; j < w; j += 2) {
      if (a == 0) continue;
      ans[i][j] = '.';
      a--;
    }
  }
  for (int i = 0; i < h / 2; i += 2) {
    for (int j = 0; j < w; j += 2) {
      if (b == 0) continue;
      ans[i][j] = '#';
      b--;
    }
  }
  cout << h << " " << w << endl;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << ans[i][j];
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
k = 2
while 1:
    if k*(k-1)//2 == N: break
    if k*(k-1)//2 > N:
        print('No')
        exit()
    k += 1

print('Yes')
print(k)
ans = [[] for _ in range(k)]
a = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(a)
        ans[j].append(a)
        a += 1
for row in ans:
    print(*[len(row)]+row)

Measured memory_bytes: 9416
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=505;
int n,m,a[maxn][maxn],b[maxn][maxn];
char s[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

int main(){
	n=rd(); m=rd();
	go(i,n+1,1){
		scanf("%s",s);
		go(j,m+1,1)	if(s[j-1] == '#') a[i][j]=b[i][j]=1;
	}
	go(i,n+1,1) a[i][1]=b[i][m]=1;
	go(i,n+1,1)
		if(i%2) go(j,m,2) a[i][j]=1;
		else go(j,m,2) b[i][j]=1;
	go(i,n+1,1){
		go(j,m+1,1)
			if(a[i][j]) printf("#");
			else printf(".");
		puts("");
	}
	puts("");
	go(i,n+1,1){
		go(j,m+1,1)
			if(b[i][j]) printf("#");
			else printf(".");
		puts("");
	}
	/*puts("");
	go(i,n+1,1){
		go(j,m+1,1) 
			if(b[i][j] && a[i][j]) printf("#");
			else printf(".");
		puts("");
	}*/	
	return 0;
}//Faze


Measured memory_bytes: 2688
#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
const int N=2e5+5, M=2e6, oo=1<<30;
namespace Dinic {
	int n, e, S, T, head[N], to[M], next[M], cap[M], q[N], dis[N], cur[N];
	void add_edge(int u, int v, int w, int r=0) {
		to[e]=v, cap[e]=w, next[e]=head[u], head[u]=e++;
		to[e]=u, cap[e]=r, next[e]=head[v], head[v]=e++;
	}
	bool bfs() {
		int l=-1, r=-1, i;
		memset(dis, 0, n*sizeof(int));
		dis[q[++r]=T]=1;
		while(l++<r) {
			if(q[l]==S) return true;
			for(i=head[q[l]]; ~i; i=next[i])
				if(cap[i^1]&&!dis[to[i]]) dis[q[++r]=to[i]]=dis[q[l]]+1;
		}
		return false;
	}
	int dfs(int x, int rem) {
		if(x==T) return rem;
		int save=rem;
		for(int &i=cur[x]; ~i; i=next[i])
			if(cap[i]&&dis[to[i]]==dis[x]-1) {
				int now=dfs(to[i], rem<cap[i]?rem:cap[i]);
				cap[i]-=now;
				cap[i^1]+=now;
				rem-=now;
				if(!rem) break;
			}
		return save-rem;
	}
	int main() {
		int ans=0;
		while(bfs()) {
			memcpy(cur, head, n*sizeof(int));
			ans+=dfs(S, oo);
		}
		return ans;
	}
}
int n, p[N], q[N], a[N], b[N];
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar(), c-'0'>9&c!='-');
	for(a=(b=c=='-')?0:c-'0'; (c=getchar()-'0')<=9; a=a*10+c);
	return b?-a:a;
}
int dump(int *src, int *dst) {
	int m=0;
	memset(dst, -1, n*sizeof(int));
	for(int i=0; i<n; ++i)
		if(dst[i]==-1) {
			int x=i;
			do {
				dst[x]=m;
				x=src[x];
			} while(x!=i);
			++m;
		}
	return m;
}
int main() {
	int (*rd)()=read<int>, x, y, s, t, ans;
	n=ans=rd();
	std::generate(p, p+n, rd), x=dump(p, a);
	std::generate(q, q+n, rd), y=dump(q, b);
	Dinic::n=x+y+2;
	Dinic::S=s=x+y;
	Dinic::T=t=x+y+1;
	memset(Dinic::head, -1, (x+y+2)*sizeof(int));
	for(int i=0; i<n; ++i) {
		if(i==p[i]) {
			if(i==q[i]) --ans; else Dinic::add_edge(s, x+b[i], 1);
		} else {
			if(i==q[i]) Dinic::add_edge(a[i], t, 1); else Dinic::add_edge(a[i], x+b[i], 1, p[i]==q[i]);
		}
	}
	printf("%d\n", ans-Dinic::main());
	return 0;
}


Measured memory_bytes: 13952
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n,m = map(int, input().split())
ns = defaultdict(set)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
s = 0
for t in ns[s]:
    break
l = set([s,t])
from queue import deque
ans = deque([s,t])
while True:
    if not all(u in l for u in ns[s]):
        for u in ns[s]:
            if u not in l:
                break
        ans.appendleft(u)
        l.add(u)
        s = u
    elif not all(v in l for v in ns[t]):
        for v in ns[t]:
            if v not in l:
                break
        ans.append(v)
        l.add(v)
        t = v
    else:
        break
print(len(ans))
write(" ".join(map(lambda x: str(x+1), ans)))

Measured memory_bytes: 132600
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var line1 = Console.ReadLine().Split(' ');
        var s = line1[0];
        var t = line1[1];
        var line2 = Console.ReadLine().Split(' ');
        var a = int.Parse(line2[0]);
        var b = int.Parse(line2[1]);

        var u = Console.ReadLine();
        if (u == s) a--;
        else b--;
        Console.WriteLine($"{a} {b}");
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

int N;
VL a;
LL dp[3010][3010];

LL rec(int i, int j){
    if(dp[i][j] != -LINF) return dp[i][j];
    if((N-(j-i))%2 == 0){
        dp[i][j] = (max(a[i] + rec(i+1,j), a[j-1] + rec(i,j-1)));

        return dp[i][j]; 
    }else{

        dp[i][j] = (min(-a[i] + rec(i+1,j), -a[j-1] + rec(i,j-1)));
        return dp[i][j]; 
    }

}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    cin >> N;
    a.resize(N);
    REP(i,3010) REP(j,3010) {
        if(i == j) dp[i][j] = 0;
        else dp[i][j] = -LINF;
    }
    REP(i,N) cin >> a[i];
    cout << rec(0,N) << endl;



}


Measured memory_bytes: 71168
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  unless (n == 0) $ do
    print $ solve n
    main

solve :: Int -> Int
solve n = fst $ foldl f (0,1000 - n) [500,100,50,10,5,1]
  where
    f (c,m) l = (m `div` l + c, m `mod` l)

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 3652
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y-1);(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int i,j,k,n,q;
  cin>>n;
  vector<string> str(n);
  rep(i,n)cin>>str[i];
  vector<pair<string,int>> srt;
  rep(i,n)srt.emplace_back(str[i],i);
  sort(all(srt));
  vector<int> s(n),rnk(n);
  rep(i,n)
    s[i]=srt[i].Y;
  rep(i,n)
    rnk[s[i]]=i;
  set<int> st;
  cin>>q;
  int t,id;
  rep(i,q){
    cin>>t>>id;
    --id;
    if(t==1){
      st.insert(rnk[id]);
    }else if(t==2){
      st.erase(rnk[id]);
    }else{
      auto re=st.lower_bound(rnk[id]);
      if(re==st.end()){
	cout<<-1<<endl;
      }else{
	//cout<<str[id]<<","<<str[s[*re]]<<endl;
	if(str[id].size()<=str[s[*re]].size() && str[id]==str[s[*re]].substr(0,str[id].size()))
	  cout<<s[*re]+1<<endl;
	else
	  cout<<-1<<endl;
      }
    }
  }
  return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> A;
  A.push_back(0);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(a==(A.size()-1)+1){
      A.push_back(a);
    }
  }
  if(A.size()==1){
    cout << -1 << endl;
  }
  else{
    cout << N-(A.size()-1) << endl;
  }
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

string s;
int i;

int cat()
{
    if (i == s.length()) return 1;
    if (s[i] != 'm') return 1;
    i++;
    if (!cat() || i == s.length() || s[i] != 'e') return 0;
    i++;
    if (!cat() || i == s.length() || s[i] != 'w') return 0;
    i++;
    return 1;
}

int main()
{
    cin >> s; i = 0;
    cout << (cat() && i == s.length() ? "Cat" : "Rabbit") << endl;
    return 0;
}

Measured memory_bytes: 3184