akhauriyash/Code-Regression huggingface dataset:
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////

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

    string S;
    cin >> S;

    vector<string> vec = {"dream", "dreamer", "erase", "eraser"};

    while (S != "") {
        int n = S.size();
        for (auto o : vec) {
            if (o.size() <= S.size()) {
                bool ok = true;
                for (int i = 0; i < o.size(); i++) {
                    if (S[S.size() - 1 - i] != o[o.size() - 1 - i]) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    for (int i = 0; i < o.size(); i++)
                        S.pop_back();
                    break;
                }
            }
        }
        if (S.size() == n) {
            cout << "NO\n";
            return 0;
        }
    }

    cout << "YES\n";

    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <vector>
#include <deque>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;



int main(){
  while(const int n = getInt()){
    const int N = n * (n - 1) / 2;
    vector<int> memo(401);
    vector<int> d(N);
    vector<vector<int> > ans;

    REP(i, N)
      memo[d[i] = getInt()]++;

    sort(d.rbegin(), d.rend());
    if(n == 2){
      ans.push_back(vector<int>(1, d[0]));
    }else{
      vector<int> tmp(n - 1);
      REP(i,1<<(n - 2)){
	int rev = (~i) & ((1 << (n - 2)) - 1);
	if(i > rev) continue;

	vector<int> pos; pos.reserve(n);
	vector<int> cnt(401);
	
	pos.push_back(0);
	pos.push_back(d[0]);
	cnt[d[0]]++;
	
	for(int j = 1; j < N; j++){
	  const int dd = d[j];
	  if(cnt[dd] < memo[dd]){
	    int next = pos.size() - 2;
	    if(i & (1 << next)){
	      pos.push_back(dd);
	    }else{
	      pos.push_back(pos[1] - dd);
	    }

	    const int m = pos.size() - 1;
	    REP(k,m){
	      const int p = std::abs(pos[k] - pos[m]);
	      if(++cnt[p] > memo[p])
		goto next;
	    }
	  }
	}
	
	sort(pos.begin(), pos.end());
	REP(i, n - 1) tmp[i] = pos[i + 1] - pos[i];
	ans.push_back(tmp);
	reverse(tmp.begin(), tmp.end());
	ans.push_back(tmp);
      next:;
      }
    }

    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    REP(i,ans.size())
      REP(j, n - 1)
	printf("%d%c", ans[i][j], j == n - 2 ? '\n' : ' ');

    puts("-----");
  }
  return 0;
}

Measured memory_bytes: 884
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    t = input()
    n = len(s)

    res = []
    for i in range(n):
        ss = list(s)
        if (s[i] == t[0] or s[i] == "?") and i + len(t) <= n:
            pos = 0
            for j in range(i, i + len(t)):
                if s[j] != "?" and s[j] != t[pos]:
                    break
                pos += 1
            else:
                pos = 0
                for j in range(i, i + len(t)):
                    ss[j] = t[pos]
                    pos += 1
                ss = "".join(ss).replace("?", "a")
                res.append(ss)

    if len(res) == 0:
        print("UNRESTORABLE")
    else:
        res = sorted(res)
        print(res[0])


if __name__ == '__main__':
    resolve()


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

int main()
{
  int64_t n,m;
  cin>>n>>m;
  vector<pair<int64_t,int64_t>> vec(n);
  for (int i = 0; i < n; ++i)
  {
    int64_t a,b;
    cin>>a>>b;
    vec[i]=make_pair(a,b);
  }
  sort(vec.begin(), vec.end());
  int64_t ans=0;
  auto start=vec.begin();
  priority_queue<int64_t> pque;
  for (int i = 1; i <= m; ++i)
  {
    for (auto itr = start; itr != vec.end(); ++itr)
    {
      if((*itr).first<=i){
        pque.push((*itr).second);
        start=itr;
        ++start;
      }
      else {
        start=itr;
        break;
      }
    }
    if(pque.empty()) continue;
    ans+=pque.top();
    pque.pop();
  }
  cout<<ans;
}

Measured memory_bytes: 2936
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

const long long MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  // 2D vector and sorting, Ref. https://qiita.com/Arusu_Dev/items/c36cdbc41fc77531205c //
  vector<vector<int>> order(N,vector<int>(2));
  REP(n,N){
    cin >> order[n][0], order[n][0];
    order[n][1] = n;
  } 
  sort(order.begin(),order.end(),[](const vector<int> &alpha,const vector<int> &beta){return alpha[0] < beta[0];});

  REP(n,N){
    cout << order[n][1] +1 << " ";
  }
  cout << endl;

}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      for (int k = 0; k < j; ++k) {
        if (l[i] < l[j] + l[k] and l[j] != l[k] and l[i] != l[j] and l[i] != l[k]) {
          ++ans;
        }
      }
    }
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 3672
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	cin >> N;
	M = 0;
	for (int i = 0; i < N; i++) {
		cin >> L;
		K += max(0LL, M - L);
		M = max(M, L);
	}
	cout << K << endl;
}

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

int main(){
    int flag=0;
    int ans=0;
    int a,b,c,d;
    cin >> a>>b>>c>>d;

    if(a+b==c+d){
        cout << "Balanced"<<endl;
    }else if(a+b > c+d){
        cout << "Left"<<endl;
    }else{
        cout << "Right"<<endl;

    }

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define loop(I, N) for(int I = 1; I <= N; I++)
#define pool(I, N) for(int I = N; I >= 1; I--)
#define rep(I, N) for(int I = 0; I < N; I++)
#define per(I, N) for(int I = N - 1; I >= 0; I--)
#define FOR(I, L, R) for(int I = L; I <= R; I++)
#define FOD(I, R, L) for(int I = R; I >= L; I--)
#define SET(P, VAL) memset(P, VAL, sizeof(P));

int n, A[105], ans = 0;
int main() {
	scanf("%d", &n);
	rep(i, n) scanf("%d", &A[i]);
	sort(A, A + n);
	loop(i, n - 1) if(A[i] != A[i - 1]) ++ans;
	printf("%d\n", ans + 1);
}


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

using namespace std;

int init = 0;

bool sl = true;
vector<vector<int> > tree;
vector<long long> pesos;

vector<int> visto;
long long sol(int ver){

	visto[ver] = 1;

	long long count = 0;
	long long val = 0;
	vector<long long> vecVal;
	for(int i = 0; i < tree[ver].size(); i++){
		if(visto[tree[ver][i]] == 0){
			count++;
			long long v = sol(tree[ver][i]);
			vecVal.push_back(v);
			val += v;
		}
	}

	if(count == 1){

            if(val != pesos[ver]){
                     sl = false;
                     return 0;
            }else{
                  return val;
            }
     }else if(ver == init){


 		if(2*pesos[ver]-val != 0){
 		                   sl = false;
 		                   return 0;
 		           }else{
 		        	   int acomu = val;

 		        	   sort(vecVal.begin(), vecVal.end());
 						for(int i = vecVal.size()-1; i >= 0; i--){
 						//	cout << vecVal[i] << '\n';
 							if(vecVal[i] == val - pesos[ver]){
 								return 2*pesos[ver]-val;
 							}else if(vecVal[i] < val - pesos[ver] && acomu >= val - pesos[ver]){
 								return 2*pesos[ver]-val;
 							}else if(vecVal[i] > val - pesos[ver] && val - vecVal[i] >= val - pesos[ver]){
 								return 2*pesos[ver]-val;
 							}
 							acomu -= vecVal[i];
 						}
 		        	   	 sl = false;
 		        	   	 return 0;

 		           }
 	}else if(count == 0){
           return pesos[ver];
     }else{

           if(2*pesos[ver]-val < 0 || pesos[ver] > val){
                   sl = false;
                   return 0;
           }else{

	        	   if(val - pesos[ver] == 0) return 2*pesos[ver] - val;
	        	   sort(vecVal.begin(), vecVal.end());
		        	   int acomu = val;
		        	  // sort(vecVal.begin(), vecVal.end());
						for(int i = vecVal.size()-1; i >= 0; i--){

							if(vecVal[i] == val - pesos[ver]){
								return 2*pesos[ver]-val;
							}else if(vecVal[i] < val - pesos[ver] && acomu >= val - pesos[ver]){
								return 2*pesos[ver]-val;
							}else if(vecVal[i] > val - pesos[ver] && val - vecVal[i] >= val - pesos[ver]){
								return 2*pesos[ver]-val;
							}
							acomu -= vecVal[i];
						}
		        	   	 sl = false;
		        	   	 return 0;
           }
     }
}





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

    for(int i = 0; i < n; i++){
         vector<int> aux;
         tree.push_back(aux);
         long long auxa;
         cin >> auxa;
         pesos.push_back(auxa);
         visto.push_back(0);
    }

    for(int i = 0; i < n-1; i++){
            int a,b;
            cin >> a >> b;
            tree[a-1].push_back(b-1);
            tree[b-1].push_back(a-1);
    }
    init = 0;
    for(int i = 0; i < n; i++){
    	if(tree[i].size() != 1){
    		init = i;
    		break;
    	}
    }



    sol(init);

    if(sl) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 16304
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll S,T,A,B,C,D;

bool check(ll N){
  if(A+B-C-D<INF){
    if((A+B)*N+A<=(C+D)*N+C){
      return 1;
    }
    return 0;
  }
  if((A+B-C-D)<=(C-A)/N){
    return 1;
  }
  return 0;
}

int main(){
  cin >> S >> T >> A >> B >> C >> D;
  A = S*A; B= T*B;
  C = S*C; D= T*D;
  if(A+B == C+D){
    cout << "infinity" << endl;
    return 0;
  }
  if(D+C>A+B){
    swap(A,C);
    swap(B,D);
  }
  if(C<A){
    cout << 0 << endl;
    return 0;
  }
  cout << (C-A)/(A+B-C-D)*2+1-((C-A)%(A+B-C-D)==0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    int count=0;
    for(int i=0;i<n;i++){
        if(p[i]!=i+1) count++;
    }
    if(count==2 || count==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;
const double PI (acos(-1));


int main()
{
 int H, A;
 cin >> H >> A;

int num =0;
 while(H > 0 )
 {
   H -= A;
   num++;
 }

cout << num;

}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
long long int n,m,nd;
int main(){
    cin>>n>>m;
    nd=2*n;
    if(nd>m)cout<<m/2<<endl;
    else if(nd==m)cout<<n<<endl;
    else{
        m-=nd;
        m/=4;
        cout<<n+m<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

n = int(input())
s1 = input()
s2 = input()

ans = 1
index =0
if s1[0] == s2[0]:
  ans *= 3
  index = 1
else:
  ans *= 3 * 2
  index = 2
  
while index < n:
  if s1[index-1] == s2[index-1]:
    ans *= 2
    if s1[index] == s2[index]:
      index += 1
    else:
      index += 2
      
  else:
    if s1[index] == s2[index]:
      index += 1
    else:
      ans *= 3
      index += 2
  
  ans %= MOD
      
print(ans)

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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

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

int n, k;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> k;
	cout << (n % k != 0) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static boolean isPrime(long n){
	if(n % 2 == 0)
		return false;
        for(int i = 3 ; i <= Math.sqrt(n) ; i+= 2){
		if(n % i == 0)
			return false;
	}
	return true;
    }
    public static void main(String[] agrs){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if(isPrime(n))
            System.out.println(n + ": " + n);
        else{
            System.out.print(n + ":");
            while(n % 2 == 0){
		System.out.print(" " + 2);
		n /= 2;
	    }
	    for(int i = 3 ; i <= Math.sqrt(n) ; i += 2){
		if(n % i == 0 && isPrime(i)){
			while(n % i == 0){
				System.out.print(" " + i);
				n /= i;
			}
		}
		if(n == 1)
			break;
		else if(isPrime(n)){
			System.out.print(" " + n);
			break;
		}
	    }
            System.out.println();
	}
    }
}


Measured memory_bytes: 26292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

    string s;
    cin >>s;

    int sum =0;
    for(char c : s)
        sum += c;

    printf("%s\n",sum % 'B' == 0 || sum % 'A' == 0 ? "No" : "Yes");

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    string s;
    cin >> s;
    int count=0;
    int mx = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='R'){
            count++;
        }else{
            count=0;
        }
        mx = max(mx,count);
    }
    cout << mx <<endl;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> v(4);
    for (int i = 0; i < 4; i++) cin >> v[i];
    sort(v.begin(), v.end());
    vector<int> v2 = {1, 4, 7, 9};
    cout << (v == v2 ? "YES" : "NO") << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int oo = 1e9;

const int N  = 200001;
const int LOGN = 18;


int n , m;

pii e[N];

map<pii,int> mp;

int main() {
	//freopen("input.txt", "r", stdin);
	scanf("%d%d",&n,&m);
	for (int i = 0; i < m; ++i){
		scanf("%d%d",&e[i].first,&e[i].second);
		if(e[i].first > e[i].second)
			swap(e[i].first,e[i].second);
		mp[e[i]] = 1;
	}
	for(int i = 0 ; i < m ; i++){
		if(e[i].second == n){
			if(mp[make_pair(1,e[i].first)]){
				puts("POSSIBLE");
				return 0;
			}

		}
	}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 20608
import sys
from operator import itemgetter

stdin = sys.stdin

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


n, m = na()
a = na()
bcs = []
for i in range(m):
    bcs.append(na())
for i in range(n):
    bcs.append([1, a[i]])
bcs.sort(key=itemgetter(1))

ans = 0
rem = n
for i in range(m+n-1, -1, -1):
    use = min(rem, bcs[i][0])
    ans += use*bcs[i][1]
    rem -= use

print(ans)

Measured memory_bytes: 43424
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-13

#define INF 1e9
int n;
map<int, int> last;
int const MaxSize = 1e5 + 10;
LL MOD = 1e9 + 7;
LL f[MaxSize], invF[MaxSize], r[MaxSize];

void preCalc() {
	r[1] = 1;
	f[1] = 1;
	invF[1] = 1;
	LL m = MOD;

	for (LL i = 2; i < MaxSize; ++i) {
		r[i] = (m - (m / i) * r[m % i] % m) % m;

		f[i] = (i * f[i - 1]) % MOD;
		invF[i] = (r[i] * invF[i - 1]) % MOD;
	}
}

LL choose(LL top, LL bottom) {
	if (top < bottom || top < 0 || bottom < 0)
		return 0;
	if (top == bottom || bottom == 0)
		return 1;

	LL bfs = (invF[bottom] * invF[top - bottom]) % MOD;

//	cout << "ftop:" << top << " " << f[top] << endl;

	return (f[top] * bfs) % MOD;
}

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);

	preCalc();

	cin >> n;
	int midLen;
	int fi, si;
	LP(i, 0, n+ 1)
	{
		int a;
		cin >> a;

		if (last.count(a)) {
			midLen = i - last[a] + 1;
			fi = last[a];
			si = i;
		} else {
			last[a] = i;
		}
	}

//	cout << midLen << endl;

	LPE(k, 1, n + 1)
	{
		LL all = choose(n + 1, k);
		LL dup = choose(n + 1 - midLen, k - 1);


	//	cout << k << " " << all << " " << dup << endl;
		cout << ((all - dup) + MOD) % MOD << endl;
	}

	return 0;
}


Measured memory_bytes: 8320
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
ans=10**9
x=0
for i in range(N):
  a=abs(A*1000-(T*1000-H[i]*6))
  if ans > a:
    ans=a
    x=i
print(x+1)

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		ou.println(Integer.parseInt(sc.next()) + Integer.parseInt(sc.next()) / 2);
		ou.flush();
	}
}

Measured memory_bytes: 35724
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n;
    cin >> n;
    std::vector<int> a(n+1);
    REP(i, n+1) {
        cin >> a[i];
    }
    ll cnt = 0;
    REP(i, n) {
        int x;
        cin >> x;
        if (a[i] < x) {
            cnt += a[i];
            x -= a[i];
            if (a[i+1] < x) {
                cnt += a[i+1];
                a[i+1] = 0;
            } else {
                cnt += x;
                a[i+1] -= x;
            }
        } else {
            cnt += x;
        }
    }

    std::cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define MAX 1000000
#define INF 1000000 
#define M 1000000007
#define PI 2 * acos(0.0)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main(){
    fast_io
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll r = 0;
    ll w = 0;
    for(ll i = 0;i<n;i++){
        if(s[i] == 'R') r++;
        else w++;
    }
    if(w == 0){
        cout<<0<<endl;
    }
    else if(r == 0){
        cout<<0<<endl;
    }
    else{
        ll f =  0;
        ll i = n-1;
        while(w--){
            if(s[i] == 'R'){
               f++;
            }
            i--;
        }
        cout<<f<<endl;
    }
    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;

int main(void){
        int N,K,t,i=0;
        long cnt=0;
        int *H;

        cin >> N >> K;
        H = (int *)malloc(sizeof(int)*N);
        while(cin >> t){
                H[i] = t;
                i++;
                if(i>=N){
                        break;
                }
        }
        sort(H,H+N,greater<int>());
        for(i=K;i<N;i++){
                cnt += H[i];
        }
        cout << cnt << endl;
        free(H);

        return 0;
}

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

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

int main(){
	string s; cin>>s;
	char mem=s[0];
	ll ans=0;
	rep(i,s.sz){
		if(mem==s[i]) continue;
		else{
			mem=s[i];
			ans++;
		}
	}
	cout<<ans;
}

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

int main(){
  vector<int> x(5);
  for(int i=0;i<5;i++){
    cin >> x.at(i);
    if(x.at(i)==0){
      cout << i+1 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


string S;


signed main(){
    cin >> S;

    if(S[0] == S[1] and S[1] == S[2]) No;
    else Yes;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl '\n' 
#define ull unsigned long long
 
using namespace std;

int main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;  cout.tie( 0 ) ;
    
    int n , k ;

    cin >> n >> k ;

    int a[n] ; 

    ll f[100001] ;

    //f[1] = abs(a[1] - a[0]) ;

    for(int i = 0 ; i < n ; i++){
        cin >> a[i] ; 
        if(i == 0){
            f[0] = 0 ;
        }
        else if(i == 1){
            f[1] = abs(a[0] - a[i]) ; 
        }
        else{

            ll minn = 10000000000000 ; 
            for(int j = i - 1 ; j >= i - k and j >= 0 ; j--){
                minn = min( minn , f[j] + abs(a[j] - a[i])) ; 
            }

            f[i] = minn ;
        }

    }



    cout << f[n - 1] << endl ;


     return 0 ;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
	ll a[200020], b[200020];
	for(int i=0; i<n; i++) cin>>a[i]>>b[i];
	sort(a, a+n); sort(b, b+n);
	if(n&1){
		cout<<b[n/2]-a[n/2]+1<<endl;
	}else{
		cout<<(b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1)<<endl;
	}
	return 0;
}


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

int main(){
	ll n,k;
	cin >> n>>k;
	vector<ll>a(n+1);
	for(ll i=1; i<= n;i++)cin >> a[i];

	vector<bool> check(n+1,0);
	vector<ll> visit_time(n+1,0);
	

	ll start = 1;
	ll move_time = 0; 
	while(check[start] != 1){
		check[start] = 1;
		visit_time[start] = move_time; 
		start = a[start];
		move_time++;
		// cout<< "move_time: " << move_time 
		// 	<< ", visit: " << start << endl;
	}

	ll roop = move_time - visit_time[start];
	//cout << "roop:" << roop;
	ll before_roop = visit_time[start];
	//cout << ", before_roop: " << before_roop << endl;
	ll spot;

	if(k <= move_time){
		spot = 1;
		rep(i,k){
			spot = a[spot];
		}
		cout << spot << endl;
		return 0;
	}
	else{
		spot = start;
		ll amari = (k - before_roop) % roop;
		rep(i,amari){
			spot = a[spot];
		}
		cout << spot << endl;
		return 0;

	}
}

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

int main(){
    int n,m;
    int a,b;
    cin>>n>>m;
    vector<vector<int>> v(n);
    rep(i,m){
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    queue<int> Q;
    vector<int> tt(n,-1),dist(n,-1);
    Q.push(0);
    dist[0]=0;
    while (!Q.empty()){
        int fron=Q.front();
        Q.pop();
        for(auto x:v[fron]){
            if(dist[x]==-1){
                Q.push(x);
                dist[x]=fron;
            }
        }
    }
    cout<<"Yes"<<endl;
    for(auto i=dist.begin()+1;i!=dist.end();i++)
    cout<<*i+1<<endl;
    
}



Measured memory_bytes: 10504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 100
#define vmax 10000
#define sentinel 2000000000
#define INF (1<<30)
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
static const int NIL=-1;

//cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);

int main() {
    int n,x1,y1,x2,y2,ans=0;
    cin>>n;
    vector<vector<int>> a(1010,vector<int>(1010,0));
    rep(i,n){
        cin>>x1>>y1>>x2>>y2;
        x1++,y1++;x2++;y2++;
        a[x1][y1]++;a[x2][y1]--;
        a[x1][y2]--;a[x2][y2]++;
    }
    for(int i=0;i<=1000;i++){
        for(int j=0;j<=1000;j++){
            a[i+1][j+1]+=(a[i][j+1]+a[i+1][j]-a[i][j]);
            ans=max(ans,a[i+1][j+1]);
        }
    }
    cout<<ans<<endl;
    return 0;
}






Measured memory_bytes: 6820
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
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

sys.setrecursionlimit(10000)


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


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


def read_float():
    return float(input())


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


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


def read_str_n():
    return list(map(str, input().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, V):
    v1 = [v for v in V[::2]]
    v2 = [v for v in V[1::2]]

    v1c = Counter(v1)
    v2c = Counter(v2)
    v1 = v1c.most_common(2)
    v2 = v2c.most_common(2)
    v1.append((-1, 0))
    v2.append((-1, 0))
    v1_1, v1_2 = v1[:2]
    v2_1, v2_2 = v2[:2]

    if v1_1[0] != v2_1[0]:
        return (N//2 - v1_1[1]) + (N//2 - v2_1[1])

    return min(
        (N//2 - v1_1[1]) + (N//2 - v2_2[1]),
        (N//2 - v1_2[1]) + (N//2 - v2_1[1]),
    )


def main():
    N = read_int()
    V = read_int_n()
    print(slv(N, V))


if __name__ == '__main__':
    main()


Measured memory_bytes: 19892
N = int(input())
A = [int(input())for _ in range(N)]
visit = [False] * (N+1)
pre = 1
ans = 0
visit[1] = True
while True:
    ans += 1
    x = A[pre-1]
    if visit[x]:
        break
    visit[x] = True
    if x == 2:
        break
    pre = x
if not visit[2]:
    ans = -1
print(ans)

Measured memory_bytes: 7852
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e=0;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d) e++;
  else if(abs(a-b)<=d&&abs(b-c)<=d) e++;
  cout<<(e?"Yes":"No");
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	x := make([]int, N)
	y := make([]int, N)
	for i := 0; i < N; i++ {
		x[i] = nextInt()
		y[i] = nextInt()
	}
	var sum float64
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			_x := (x[i] - x[j]) * (x[i] - x[j])
			_y := (y[i] - y[j]) * (y[i] - y[j])
			sum += math.Sqrt(float64(_x + _y))
		}
	}
	fmt.Println(sum / float64(N))
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		log.Fatal(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var inf = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  string a,b;
  cin>>a>>b;
  
  if(a=="H"){
    cout<<b<<endl;
    return 0;
  }else{
    if(b=="H"){
      cout<<"D"<<endl;
    }else {
      cout<<"H"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int d, e;

int main() {
    while(1) {
        cin >> d >> e;
        if(d == 0 && e == 0) break;
        long double ans = 1e9;
        for(int i = 0; i < d; ++i) {
            int x = i, y = d-i;
            long double xx = (long double)x;
            long double yy = (long double)y;
            long double xy = sqrtl(xx*xx + yy*yy);
            long double res = abs(xy-(long double)e);
            chmin(ans, res);
        }
        cout << fixed << setprecision(10);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3208
from sys import stdin
import bisect
from math import factorial

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

point = 0

for i in range(n-1):
    if li[i]-1 == i:
        li[i],li[i+1] = li[i+1],li[i]
        point += 1
if li[-1] == n:
    point += 1

print(point)

Measured memory_bytes: 13812
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int data[100],cnt=0,n;
  cin >> n;
  for(int i=0;i<n;i++) cin >> data[i];
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(data[j]<data[j-1]){
    swap(data[j],data[j-1]);
    cnt++;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << (i!=0?" ":"") << data[i];
  }
  cout << endl << cnt << endl;
  }

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb push_back
const int N = 2e5+5;
int a[4][4];
int b[4][4];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int n;
    cin>>n;
    for(int l=0;l<n;l++){
        int x;
        cin>>x;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(a[i][j]==x)b[i][j] = 1;
            }
        }
    }
    bool ans = false;
    for(int i=0;i<3;i++){
        if(b[i][0]==1 and b[i][1] == 1 and b[i][2]==1)ans = true;
        if(b[0][i]==1 and b[1][i] == 1 and b[2][i]==1)ans = true;
    }
    if(b[0][0]==1 and b[1][1]==1 and b[2][2] == 1)ans = true;
    if(b[2][0]==1 and b[1][1]==1 and b[0][2] == 1)ans = true;
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
i=1
while i<=4:
    t,n=map(int,input().split())
    if t==1:
        n1=n*6000
        print(n1)
    elif t==2:
        n2=n*4000
        print(n2)
    elif t==3:
        n3=n*3000
        print(n3)
    else:
        n4=n*2000
        print(n4)
    i+=1



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

int main() {
  int x,y;
  cin>>x>>y;
  int a[]={1,2,1,3,1,3,1,1,3,1,3,1};
  if(a[x-1]==a[y-1]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  
  



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

using namespace std;

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

	string str;
	cin >> str;

	int a_pass = 0, b_pass = 0;
	for (auto ch : str)
	{
		if (ch == 'a')
		{
			if (a_pass + b_pass < a + b)
			{
				cout << "Yes" << endl;
				a_pass++;
			}
			else
				cout << "No" << endl;
		}
		else if (ch == 'b')
		{
			if (a_pass + b_pass < a + b && b_pass < b)
			{
				cout << "Yes" << endl;
				b_pass++;
			}
			else
				cout << "No" << endl;
		}
		else
			cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 896
<?php
fscanf(STDIN, '%d', $n);

$s  = [];
for ($i = 0; $i < $n; $i++) {
	$s[$i] = fgets(STDIN);
}

$m = 0;
$a = 0;
$r = 0;
$c = 0;
$h = 0;
foreach ($s as $name) {
	if ($name[0] === 'M') {
		$m++;
		continue;
	}
	if ($name[0] === 'A') {
		$a++;
		continue;
	}
	if ($name[0] === 'R') {
		$r++;
		continue;
	}
	if ($name[0] === 'C') {
		$c++;
		continue;
	}
	if ($name[0] === 'H') {
		$h++;
	}
}

echo $m*$a*$r + $m*$a*$c + $m*$a*$h + $m*$r*$c + $m*$r*$h + $m*$c*$h + $a*$r*$c + $a*$r*$h + $a*$c*$h + $r*$c*$h;

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define inf (1LL<<61)
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define int long long
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >  
#define mod %1000000007
#define ll long long

int N;
vll v;
vll res;
void matmul(int ch,vll m,vll n)
{
   vll cr(N,vl(N,0));
   for(int i=0;i<N;i++)
   {
       for(int j=0;j<N;j++)
       {
           for(int k=0;k<N;k++)
           {
               cr[i][k]=(cr[i][k]+((m[i][j]mod)*((n[j][k])mod))mod)mod;
           }
       }
   }
   if(ch)
   {
       for(int i=0;i<N;i++)
       {
           for(int j=0;j<N;j++)
               v[i][j]=cr[i][j];
       }
   }
   else
   {
       for(int i=0;i<N;i++)
       {
           for(int j=0;j<N;j++)
               res[i][j]=cr[i][j];
       }
   }
}
void fastexpomatrix(ll a)
{
       
      for(int i = 0;i < N;i++)
        res[i][i] = 1;
      while(a>0)
      {
           if(a%2==1)
               matmul(0,res,v);
      
      matmul(1,v,v);
      a/=2;
      }

}


int32_t main()
{
    IOS;
    
    int k;
    cin>>N>>k;
    v.resize(N,vl(N));
    res.resize(N,vl(N,0));
    for(int i = 0;i < N;i++)
    {
        for(int j = 0; j < N;j++)
            cin>>v[i][j];
    }
    fastexpomatrix(k);
    int ans = 0;
    for(int i = 0;i < N;i++)
    {
        for(int j = 0;j < N;j++)
        {
            ans = (ans + res[i][j])mod;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

typedef pair<int, int> point_t;
point_t operator+( point_t &lhs, point_t &rhs)
{
  point_t p = make_pair(lhs.first + rhs.first, lhs.second + rhs.second);
  return p;
}

bool operator==(point_t &lhs, point_t &rhs)
{
  return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}

bool operator!=(point_t &lhs, point_t &rhs)
{
  return (lhs.first != rhs.first) || (lhs.second != rhs.second);
}

bool is_in_field(int row, int col,  point_t &point){
  const int r = point.first;
  const int c = point.second;
  return (1<= c && c<=col) && (1 <= r && r <= row);
}


//r,c
int main(void){
  int H,W;
  int failureFlag=0;
  cin>>H>>W;

  vector<point_t> moves={MP(-1,0),MP(0,1),MP(1,0),MP(0,-1)};
  
  char board[H+3][W+3];
  FORQ(i,1,H){
    FORQ(j,1,W){
      cin>>board[i][j];
    }
  }

  

  FORQ(i,1,H){                  // about row
    FORQ(j,1,W){                // about col
      if(board[i][j]=='#'){
        int localSuccessFlag=0;
        for(auto x:moves){
          point_t pnt=MP(i,j);
          pnt=pnt+x;
          if( board[pnt.first][pnt.second]=='#'   ){
            localSuccessFlag=1;
          }
        }
        if(localSuccessFlag==0){
          failureFlag=1;
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}



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

int main() {
  int n;
  int64_t k;
  cin>>n>>k;
  int a[n];
  for(int i=0; i<n; i++) cin>>a[i];

  int seen[n];
  for(int i=0; i<n; i++) seen[i] = -1;

  seen[0] = 0;
  int posi = 0;
  int count = 0;
  while(true) {
    posi = a[posi]-1;
    count++;

    if(count==k) {
      cout<<posi+1<<endl;
      return 0;
    }

    if(seen[posi]!=-1) {
      break;
    }

    seen[posi] = count;
  }

  int roop = count - seen[posi];
  int initial = seen[posi];

  int rest = (k-initial)%roop;

  while(rest>0) {
    posi = a[posi]-1;
    rest--;
  }

  cout<<posi+1<<endl;


  return 0;
}

Measured memory_bytes: 5196
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		sc.close();

		long xor = 0;
		long sum = 0;

		long ans = 0;
		int right = 0;
		for(int left=0;left<N;left++) {
			//rightを右に伸ばす
			while( right < N && (xor^A[right]) == (sum+A[right]) ) {
				xor ^= A[right];
				sum += A[right];
				right++;
			}

			ans += (right-left);

			if(left==right) {
				right++; //leftもrightも進めるので、xorやsumを更新する必要はない
			}else {
				xor ^= A[left];
				sum -= A[left];
			}
		}
		out.println(ans);

//		//愚直解
//		long a = 0;
//		for(int i=0;i<N;i++) {
//			for(int j=i;j<N;j++) {
//				long s = 0;
//				long x = 0;
//				for(int k=i;k<=j;k++) {
//					s += A[k];
//					x ^= A[k];
//				}
//				if(s==x) {
//					a++;
//				}
//			}
//		}
//		out.println(a);

	}

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

}


Measured memory_bytes: 85536
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let v: Vec<u16> =
        s.split_whitespace().map(|n| n.parse().unwrap()).collect();
    let n = v[0];
    let a = v[1];
    let b = v[2];

    println!("{}", if n * a < b { n * a } else { b });
}

Measured memory_bytes: 4352
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    k = int(input())
    if k%2 == 0:
        print((k//2)*(k//2))
    else:
        print((k//2)*(k//2 + 1))
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define for0(i,n) for (int i=0; i<n; i++)
#define forr(i,n) for (int i=n-1; i>=0; i--)
#define fori(i,a,b) for (int i=a; i<=b; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define size(x) (int)(x).size()
#define read(x) int x; scanf("%d",&x);
#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<size(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int main()
{
    #ifdef DEBUG
    freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    read(a); read(b); read(c);
    set<vector<int> > seen;
    bool repeat = false;
    vector<int> start = {a,b,c};
    seen.insert(start);
    int steps = 0;

    while (!(a&1) && !(b&1) && !(c&1)) {
        pr(a) pr(b) pr(c) nl
        int aa = b/2 + c/2;
        int bb = a/2 + c/2;
        int cc = a/2 + b/2;
        vector<int> next = {aa,bb,cc};
        sort(all(next));
        if (seen.find(next) != seen.end()){
            repeat = true;
            break;
        }
        else{
            seen.insert(next);
        }
        a = aa;
        b = bb;
        c = cc;
        steps++;
    }

    if (repeat){
        cout<<-1<<endl;
    }
    else{
        cout<<steps<<endl;
    }
    return 0;
}


Measured memory_bytes: 256