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

int main()
{
    string s;
    cin>>s;
    int n = (s.length()-1)/2;
    int flag1=1,flag2=1,flag3=1;
    //check if s is palindrome
    auto itr1 = s.begin(),itr2=s.end()-1;
    while(n--)
    {
	if(*itr1!=*itr2)
	{
	    flag1= 0;
	    cout<<"No";
	    return 0;
	}
	itr1++;
	itr2--;
    }
    //check for left and right at the same time
    auto itr3 = s.begin(),itr4=s.end()-1;
    n=(s.length()-1)/2;
    itr1--;itr2++;
    while(n--)
    {
	if(*itr1!=*itr3)
	{
	    flag2=0;
	    cout<<"No";
	    return 0;
	}

	if(*itr2!=*itr4)
	{
	
	    flag3=0;
	    cout<<"No";
	    return 0;
	}


	itr1--;
	itr2++;
	itr3++;
	itr4--;
    }
    if(flag1 && flag2 && flag3)
	cout<<"Yes";
    else
	cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

// a^b mod m
int powmod(int a,int b,int m)
{
	if(b==0) return 1;
	int x=powmod(a,b/2,m); x=x*x%m;
	return b&1?x*a%m:x;
}
int inv(int n,int m)
{
	return powmod(n,m-2,m);
}

int expr(const string& s,int m,int& i);

int fact(const string& s,int m,int& i)
{
	int n=s.size();
	if(s[i]=='('){
		i++;
		int res=expr(s,m,i);
		i++;
		return res;
	}
	int res=0;
	while(i<n && isdigit(s[i]))
		res=res*10+s[i++]-'0';
	return res;
}

int term(const string& s,int m,int& i)
{
	int n=s.size();
	int res=fact(s,m,i);
	while(i<n){
		int op=s[i];
		if(op!='*' && op!='/') break;
		int tmp=fact(s,m,++i);
		if(op=='*') res=res*tmp%m;
		if(op=='/'){
			if(tmp==0) throw "NG";
			res=res*inv(tmp,m)%m;
		}
	}
	return res;
}

int expr(const string& s,int m,int& i)
{
	int n=s.size();
	int res=term(s,m,i);
	while(i<n){
		int op=s[i];
		if(op!='+' && op!='-') break;
		int tmp=term(s,m,++i);
		if(op=='+') res=(res+tmp)%m;
		if(op=='-') res=(res-tmp+m)%m;
	}
	return res;
}

int main()
{
	for(int p;scanf("%d%*c",&p),p;){
		//static char line[100005]; 
		//fgets(line,sizeof line,stdin);
		//int n=strlen(line); 
		//line[--n]=0;
		//
		//{
		//	int j=0;
		//	rep(i,n) if(line[i]!=' ') line[j++]=line[i];
		//	line[j]=0;
		//}
		//string s=line;
		string s; getline(cin,s);
		s.erase(remove(all(s),' '),s.end());
		
		try{
			int i=0;
			int res=expr(s,p,i);
			printf("%s = %d (mod %d)\n",s.c_str(),res,p);
		}
		catch(const char*){
			puts("NG");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1436
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int count;
		int min = 100000000;

		int numWest=0;
		int numEast=0;
		//ArrayList<Double> westChangeRate = new ArrayList<Double>();
		//ArrayList<Double> eastChangeRate = new ArrayList<Double>();

		for(int i=0; i<N; i++){
			if(S.charAt(i)=='W'){
				numWest ++;
			}
		}
		numEast = N - numWest;
		/*
		for(int i=0; i<N; i++){
			if(S.charAt(i)=='W'){
				westChangeRate.add();
			}
		}*/
		int leftChange = 0;
		int rightChange;
		if(S.charAt(0)=='W'){
			rightChange = numEast;
		}else{
			rightChange = numEast - 1;
		}
		count = rightChange;
		min = Math.min(min,count);
		for(int i=1; i<N; i++){
			count = 0;
			if(S.charAt(i-1)=='W'){
				leftChange ++;
			}
			if(S.charAt(i)=='E'){
				rightChange --;
			}
			count = leftChange + rightChange;
			min = Math.min(min,count);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 28832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T>

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

vvi adl_input(int N,int M){ //N頂点M辺
  vvi L(N);
  rep(i,M){
    int a,b;
    cin >> a >> b;
    //a--;b--;
    L[a].push_back(b);
    L[b].push_back(a);
  }
  return L;
}

ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

vector<int> bfs(vvi L,int S){ //List,Start
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;//startからの距離
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
}

/////////////////////////////////////////

int main(){
  initialize();
  int N,K,Q;
  cin >> N >> K >> Q;
  int A[N];
  rep(i,N) A[i]=K-Q;
  rep(i,Q){
    int a;
    cin >> a;
    a--;
    A[a]++;
  }
  rep(i,N){
    cout << (A[i]>0?"Yes":"No") << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
a = [int(input()) for i in range(N)] 

ans = sum(a)
if not ans % 10 == 0:
  print(ans)
else:
  a.sort()
  for i in range(N):
    temp = ans - a[i]
    if not temp % 10 == 0:
      print(temp)
      break
  else:
    print("0")



Measured memory_bytes: 2940
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;
constexpr int64_t kMod1 = 1000000007LL;
constexpr int64_t kMod2 = 998244353LL;
constexpr int64_t kMod3 = 3571L;

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

  constexpr int64_t kN = 26;
  int64_t D;
  cin >> D;
  vector<int64_t> C(kN + 1, 0);
  for (int64_t c = 1; c <= kN; ++c) {
    cin >> C[c];
  }
  vector<vector<int64_t>> S(D + 1, vector<int64_t>(kN + 1));
  for (int64_t d = 1; d <= D; ++d) {
    for (int64_t c = 1; c <= kN; ++c) {
      cin >> S[d][c];
    }
  }
  vector<vector<int64_t>> last(D + 1, vector<int64_t>(kN + 1, 0));
  vector<int64_t> contests(D + 1);
  for (int64_t d = 1; d <= D; ++d) {
    cin >> contests[d];
  }

  auto Score = [&](const int64_t day) -> int64_t {
    int64_t score = 0;
    for (int64_t d = 1; d <= day; ++d) {
      last[d] = last[d - 1];
      last[d][contests[d]] = d;
      score += S[d][contests[d]];
      for (int64_t c = 1; c <= kN; ++c) {
        score -= C[c] * (d - last[d][c]);
      }
    }
    return score;
  };

  auto OutputResults = [&]() {
    for (int64_t d = 1; d <= D; ++d) {
      cout << contests[d] << endl;
    }
  };

  for (int64_t d = 1; d <= D; ++d) {
    int64_t best_score = INT64_MIN;
    int64_t best_conte = -1;
    for (int64_t c = 1; c <= kN; ++c) {
      contests[d] = c;
      int64_t temp_score = Score(d);
      if (temp_score > best_score) {
        best_score = temp_score;
        best_conte = c;
      }
    }
    contests[d] = best_conte;
  }

  int64_t day_index = 123;
  int64_t contest_index = 2034;
  int64_t ignore_index = 34234;
  int64_t prev_score = Score(D);
  constexpr int64_t kIgnoreBunbo = 5;
  constexpr int64_t kIgnoreBunshi = 0;
  constexpr int64_t kMaxConsecutiveWorse = 3;

  vector<int64_t> best_contests;
  int64_t best_score = INT64_MIN;
  int64_t consecutive_worse = 0;
  vector<int64_t> better_contests;
  for (int64_t i = 0; i < 130000; ++i) {
    const int64_t day_candidate = (day_index % D) + 1;
    const int64_t original_contest = contests[day_candidate];
    const int64_t contest_candidate = (contest_index % kN) + 1;
    contests[day_candidate] = contest_candidate;
    const int64_t temp_score = Score(D);
    if (temp_score > prev_score) {
      // KEEP
      consecutive_worse = 0;
      better_contests = contests;
      if (temp_score > best_score) {
        best_score = temp_score;
        best_contests = contests;
      }
    } else if (ignore_index <= kIgnoreBunshi && temp_score > prev_score * 0.97 &&
               consecutive_worse <= kMaxConsecutiveWorse) {
      // KEEP
      ++consecutive_worse;
    } else {
      contests[day_candidate] = original_contest;
    }
    if (temp_score < best_score * 0.9) {
      contests = better_contests;
    }
    if (temp_score < best_score * 0.5) {
      contests = best_contests;
    }
    day_index = day_candidate + kMod1;
    contest_index = contest_candidate + kMod2;
    ignore_index += kMod3;
    ignore_index %= kIgnoreBunbo;
  }

  contests = best_contests;
  OutputResults();
  return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}
int n;
vector<vector<P> > G;

typedef pair<int,P> PP;
int dijkstra(int s,int t){
  vector<int> D(n,INF);
  vector<int> used(n,0);
  priority_queue<P,vector<P>,greater<P> > Q;
  D[s] = 0;
  Q.push(P(0,s));
  while(!Q.empty()){
    int cost,pos; tie(cost,pos) = Q.top(); Q.pop();
    if(used[pos]++) continue;
    if(pos == t) return cost;
    
    for(auto p:G[pos]){
      int to = p.first;
      int ncost = cost + p.second;
      if(D[to] <= ncost) continue;
      Q.push(P(ncost,to));
      D[to] = ncost;
    }
  }
  assert(0);
}

signed main(){
  int m,s,t;
  cin>>n>>m>>s>>t; s--,t--;
  G.resize(n);
  for(int i=0;i<m;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d; a--,b--,c--;
    G[a].push_back(P(b,d));
    G[b].push_back(P(a,d));
    
    G[a].push_back(P(c,d));
    G[c].push_back(P(a,d));
    
    G[b].push_back(P(c,d));
    G[c].push_back(P(b,d));
  }

  int ans = dijkstra(s,t);
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 24188
int main(void)


{


    int a,b,d,r;


    double f;


    scanf("%d",&a);


    scanf("%d",&b);


    d = a /b;


    r = a % b;


    f = (double)a / (double)b;


    printf("%d %d %lf\n",d,r,f);





    return 0;


}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,k,ans=0,i;
    cin>>n>>m>>k;
    int a[n],b[m];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]+=((i>0)?a[i-1]:0);
    }
    for(i=0;i<m;i++)
    {
        cin>>b[i];
        b[i]+=((i>0)?b[i-1]:0);
        if(b[i]<=k)
            ans=i+1;
    }
    for(i=0;i<n;i++)
    {
        int p=k-a[i],t=i+1,u=0;
        if(p<0)
            break;
        if(b[m-1]<=p)
            t+=m;
        else if(b[0]<=p)
            u=upper_bound(b,b+m,p)-b;
        t+=u;
        ans=max(ans,t);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6736
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

ll mod_pow(ll x, ll n) {
  return (!n) ? 1 : (mod_pow((x * x), n >> 1) * ((n & 1) ? x : 1));
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll n, p;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  ll ans = 1;
  if (n == 2) {
    for (ll i = 1; i <= 1000000; ++i) {
      ll m = i * i;
      if (p % m == 0)
        ans = i;
    }
    cout << ans << endl;
    return 0;
  }
  if (n > 40) {
    cout << 1 << endl;
    return 0;
  }
  for (ll i = 2;;) {
    ll m = mod_pow(i, n);
    if (p < m)
      break;
    if (p % m == 0) {
      ans *= i;
      p /= m;
    } else {
      ++i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=tuple(map(int,input().split()))
flag=[-1]*n
flag[0]=0
x,count=1,0
for i in range(1,n+1):
  x=a[x-1]
  if flag[x-1]<0:
    flag[x-1]=i
  else:
    l=i-flag[x-1]
    count=flag[x-1]
    break
if count>=k:
  x=1
  for _ in range(k):
    x=a[x-1]
  print(x)
  exit()
k=(k-count)%l
for _ in range(k):
  x=a[x-1]
print(x)

Measured memory_bytes: 32428
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 3000;
int N, K, Q, A[MAX_N];

std::vector<int> seg[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> K >> Q;

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

    int ret = 1000000000;
    for (int i = 1; i <= N; i++) {
        int seg_idx = 0;

        for (int j = 0; j <= N; j++) {
            seg[j].clear();
        }

        for (int j = 1; j <= N; j++) {
            if (A[i] <= A[j]) {
                seg[seg_idx].push_back(A[j]);
            } else if (0 < seg[seg_idx].size()) {
                seg_idx++;
            }
        }

        std::vector<int> cand;

        for (int s = 0; s <= seg_idx; s++) {
            if (K <= seg[s].size()) {
                std::sort(seg[s].begin(), seg[s].end());
                for (int m = 0; m <= seg[s].size() - K; m++) {
                    cand.push_back(seg[s][m]);
                }
            }
        }

        //std::cout << i << " " << cand.size() << std::endl;

        if (Q <= cand.size()) {
            std::sort(cand.begin(), cand.end());
            ret = std::min(ret, cand[Q-1] - A[i]);
        }
    }

    std::cout << ret << std::endl;
    
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
 
#define MAX 100
 
int main(void){
 
  int x, n, A[MAX], i, j, c=0;
  int cnt=0;
 
  scanf("%d",&n);
 
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
 
  while(1){
 
    for(j = n-1; j > 0; j--){
      if(A[j] < A[j-1]){
	x = A[j];
	A[j] = A[j-1];
	A[j-1] = x;
	c++;
      }
      else cnt++;
    }
    if(cnt != n-1) cnt=0;
    if(cnt == n-1) break;
  }
 
  for(i = 0;i < n; i++){
    printf("%d",A[i]);
    if(i != n-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",c);
 
  return 0;
}



Measured memory_bytes: 2128
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        if (LnStr() == "ABC") print("ARC"); else print("ABC");
    } 



    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable{var a = new List<T>(array).ToArray();var res = new List<T[]>();res.Add(new List<T>(a).ToArray());var n = a.Length;var next = true;while (next){next = false;int i;for (i = n - 2; i >= 0; i--){if (a[i].CompareTo(a[i + 1]) < 0) break;}if (i < 0) break;var j = n;do{j--;} while (a[i].CompareTo(a[j]) > 0);if (a[i].CompareTo(a[j]) < 0){var tmp = a[i];a[i] = a[j];a[j] = tmp;Array.Reverse(a, i + 1, n - i - 1);res.Add(new List<T>(a).ToArray());next = true;}}return res;}}



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

using namespace std;

void solve() {
  int N;
  cin >> N;
  int p = 0;
  int q = 0;
  for (int i = 0; i < N; ++i) {
    int t;
    cin >> t;
    p *= 10;
    p += t;
  }
  for (int i = 0; i < N; ++i) {
    int t;
    cin >> t;
    q *= 10;
    q += t;
  }
  string n;
  for (int i = 0; i < N; ++i) {
    n.push_back('1' + i);
  }
  int pi = 0;
  int qi = 0;
  int cnt = 0;
  do {
    auto x = stoi(n);
    if (x == p) pi = cnt;
    if (x == q) qi = cnt;
    ++cnt;
  } while (next_permutation(n.begin(), n.end()));
  cout << abs(pi - qi) << endl;
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool up_min(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool up_max(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_mdvector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_mdvector(int n, Ts ... ts){
        return vector<decltype(make_mdvector(ts...))>(n, make_mdvector(ts...));
    }

    inline ll bit(int x){
        return 1ll << x;
    }

    template<class T>
    istream& operator>>(istream& is, vector<T>& v){
        for (auto &&x : v) { is >> x; } return is;
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    ll N;
    void run();
};

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


void solver::run(){
    is >> N;
    if(!is) return;
    ll mini = INF;
    for (int i = 1; i < 1000'009; ++i) {
        if(N % i == 0){
            up_min(mini, N/i + i - 2);
        }
    } // end i
    os << mini << endl;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<P> p(n);
    REP(i, n){
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    } 
    sort(all(p));

    LL ans = 0;
    REP(i, n){
        if(m == 0) break;
        REP(j, p[i].second){
            if(m == 0) break;
            ans += p[i].first;
            m--;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    lint k; cin >> k;
    
    auto S = [](lint n) -> lint {
        lint ret = 0;
        while (n > 0) {
            ret += (n % 10);
            n /= 10;
        }
        return ret;
    };
    
    auto mypow = [](lint a, lint b) -> lint {
        lint ans = 1;
        rep (b) {
            ans *= a;
        }
        return ans;
    };
    
    set<lint> source;
    repeat (i, 16) {
        repeat_from_to (j, 1, 999) {
            lint t = j * mypow(10, i) + mypow(10, i) - 1;
            source.insert(t);
        }
    }
    
    vector<pair<lint, double>> v;
    for (auto &e: source) {
        v.push_back(make_pair(e, (double)e/S(e)));
    }
    sort(v.begin(), v.end(), [](pair<lint, double> a, pair<lint, double> b){
        if (a.snd != b.snd) {
            return a.snd < b.snd;
        }
        else {
            return a.fst < b.fst;
        }
    });
    
    
    lint t = 0;
    vector<lint> ans;
    repeat (i, v.size()) {
        if (t < v[i].fst) {
            ans.push_back(v[i].fst);
            t = v[i].fst;
        }
    }
    
    repeat (i, k) {
        cout << ans[i] << endl;
    }
}

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

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

    char prev = s[0];
    int sum = 1;
    for (int i = 0; i < n; ++i) {
        if (prev != s[i]) sum++;
        prev = s[i];
    }

    cout << sum;

    return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<long long int> vec(n);
  vector<long long int> vecb(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
    vecb.at(i)=vec.at(i);
  }
  sort(vecb.begin(),vecb.end());
  long long int p,q;
  p=vecb.at(n/2-1);
  q=vecb.at(n/2);
  
  for(int i=0;i<n;i++){
    if(vec.at(i)<=p){
      cout<<q<<endl;
      }
    else{
      cout<<p<<endl;
      }
    }
}

Measured memory_bytes: 5376
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
A=tuple(map(int,input().split()))
B=[abs(i) for i in A]
o=0
for i in A:
    if i<0:
        o+=1
if o%2==0:
    print(sum(B))
else:
    print(sum(B)-min(B)*2)

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;

	map<ll, int> a;
	priority_queue<ll> q;
	for(int i=0; i<n; i++){
		ll t;
		cin >> t;
		if(a.find(t) == a.end()){
			a[t] = 1;
		}else{
			a[t] += 1;
			if(a[t] == 2){
				q.push(t);
			}else if(a[t] == 4){
				q.push(t);
			}
		}
	}


	if(q.size() < 2){
		cout << 0 << endl;
	}else{
		ll x1 = q.top(); q.pop();
		ll x2 = q.top(); q.pop();
		cout << x1*x2 << endl;
	}



	
	return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
typedef struct node
{
    string name;
    int score; 
    int num;
    node(string a, int b, int c)
    {
        name = a;
        score = b;
        num = c;
    }
} Node;
bool compare(const Node &l, const Node &r)
{
    if(l.name.compare(r.name) == 0)
        return l.score > r.score;
    if(l.name.compare(r.name) < 0)
        return true;
    return false;
}
int main()
{
    she_told_me_dont_worry
    int n;
    cin>>n;
    vector< Node > books;
    int ans[n+5];
    int i;
    FOR0(i, n) 
    {
        string s;
        int p;
        cin>>s>>p;
        books.pb(Node(s, p, i));
    }
    sort(books.begin(), books.end(), compare);
    //FOR0(i, n) cout<<books[i].name<<" "<<books[i].score<<endl;
    FOR0(i, n)
    {
        cout<<books[i].num+1<<endl;
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#define rep(N) for (int i = 0; i < N; i++)
#define For(i, N) for (i = 0; i < N; i++)
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;

template<typename T>
void say(T s) {
	cout << s << endl;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if ((A - B) % 2 == 0)say("Alice");
	else say("Borys");
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    S = input()

    indexes = {}

    for i in range(len(S)):
        if S[i] not in indexes.keys():
            indexes[S[i]] = [i]
        else:
            indexes[S[i]].append(i)

    ans = 100

    for k, v in indexes.items():
        tmp_max = v[0]
        tmp_max = max(v[0], len(S) - v[-1] - 1)
        v.append(len(S))
        for i in range(len(v) - 1):
            tmp_max = max(tmp_max, v[i+1] - v[i] - 1)
        ans = min(ans, tmp_max)
    print(ans)


main()


Measured memory_bytes: 65200
#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 A, B, C, D;
    cin >> A >> B >> C >> D;

    while(true){
        C = C - B;
        if(C <= 0){
            cout << "Yes" << endl;
            return 0;
        }

        A = A - D;
        if(A <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
    
}

Measured memory_bytes: 3632
W, H, N = map(int, input().split())

x_min = 0
y_min = 0
x_max = W
y_max = H

for i in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        if x > x_min:
            x_min = x
    elif a == 2:
        if x < x_max:
            x_max = x
    elif a == 3:
        if y > y_min:
            y_min = y
    else:
        if y < y_max:
            y_max = y

width = x_max - x_min
height = y_max - y_min
if width > 0 and height > 0:
    print(width * height)
else:
    print(0)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    int cnt=0;
    int i;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        if(tmp%2) cnt++;
    }
    if(cnt%2==0) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000009;

void solve() {
    int n;
    cin >> n;
    cout << (100000000 - n) % 1000 << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int t = 1;
    //cin >> t;
    for (int qq = 0; qq < t; ++qq) {
       solve();
    }
   
    return 0;
}

Measured memory_bytes: 3648
from bisect import bisect_left, bisect_right

N, *L = map(int, open(0).read().split())

L.sort()

cnt = 0
for i in range(1, N - 1):
    b = L[i]
    for j in range(i):
        a = L[j]
        l, r = bisect_left(L, b - a + 1, lo=i), bisect_right(L, a + b - 1, lo=i)
        cnt += r - l - (l <= i <= r) - (l <= j <= r)

print(cnt)


Measured memory_bytes: 43764
from collections import deque
n = int(input())
a = list(map(int, input().split()))
dq = deque()
dq.append(a[0])
if n % 2:
    for i in range(1, n):
        if i % 2:
            dq.append(a[i])
        else:
            dq.appendleft(a[i])
else:
    for i in range(1, n):
        if i % 2:
            dq.appendleft(a[i])
        else:
            dq.append(a[i])
print(*dq)

Measured memory_bytes: 25412
//ainta
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int n, res;
multiset<int>Set;
int main() {
	int i, a;
   	scanf("%d", &n);
   	for (i = 0; i < n; i++) {
   		scanf("%d", &a);
   		Set.insert(a);
   	}
   	while (!Set.empty()) {
   		multiset<int>::iterator it = Set.end();
   		it--;
   		int x = *it;
   		Set.erase(it);
   		for (i = 1; i <= x; i *= 2);
   		if (Set.find(i-x) != Set.end()) {
   			Set.erase(Set.find(i - x));
   			res++;
   		}
   	}
   	printf("%d\n", res);
}

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

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>
#include <queue>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long
#define abs(x) (x<0 ? (-x) : x)
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d %d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld %lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a,b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a,b) printf("%lld%lld",a,b);
#define SIZE 1000000007

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long,long long>> vpl;
typedef vector<vector<pair<long long,long long>>> vvpl;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef pair <ll,ll> pll;
const  double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
/*ios_base::sync_with_stdio(false);cin.tie(0);*/

ll gcd(ll n,ll m){
    if (n==0)return m;
    return gcd(m%n,n) ;
}

long long fast_exp(long long n,long long k){
    if(k == 0)
        return 1;
    if(k==1)
        return n;

    long long temp = fast_exp(n,k>>1);

    if((k&1)==1)
        return (n*temp*temp)%SIZE;
    return (temp*temp)%SIZE;

}

int main() {
 ll n ;
  cin >> n;
  map <string ,int> mm ;
  string s;
    ll count =0;
    for (int i = 0; i <n ; ++i) {
           cin >> s;
           sort(BEND(s));
           mm[s]++;
           if (mm[s]!= 1 )count+=mm[s]-1;
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 11136
//g++ -std=c++14 test.cpp -o test.out
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<62)-10e15;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;
 
LL H,W,K;
vector<string> S;
 
vector<vector<int>> ans;
 
void solve(){
	ans = vector<vector<int>>(H,vector<int>(W,-1));
	int counter = 1;
	for(int h=0;h<H;h++){
		vector<int> paint;
		//横一列に塗るラムダ式
		auto painter = [&](){
			for(int i=0;i<paint.size();i++) ans[h][paint[i]] = counter;
			paint = vector<int>(0);
			counter++;
		};
		int strawberry = 0;
		for(int w=0;w<W;w++){
			if(S[h][w]=='#'){
				if(strawberry==0){//その行で1個目を見つけたとき
					paint.push_back(w);
					strawberry++;
					if(w==W-1) painter();
				}
				else{//その行で2個目以降を見つけたとき
					painter();
					paint.push_back(w);
					if(w==W-1) painter();
				}
			}else{
				if(strawberry==1 && w==W-1){
					paint.push_back(w);
					painter();
				}else{
					paint.push_back(w);
				}
			}
		}
	}
	vector<int> paint;
	//縦に伸ばすように塗るラムダ式
	auto painter = [&](int standard_h){
		for(int i=0;i<paint.size();i++){
			for(int w=0;w<W;w++) ans[paint[i]][w] = ans[standard_h][w];
		}
		paint = vector<int>(0);
		counter++;
	};
	for(int h=0;h<H;h++){
		if(ans[h][0]==-1) paint.push_back(h);
		else if(paint.size()>0){
			painter(h);
		}
	}
	paint = vector<int>(0);
	for(int h=H-1;h>=0;h--){
		if(ans[h][0]==-1) paint.push_back(h);
		else if(paint.size()>0){
			painter(h);
		}
	}
}
 
int main(){
    cin >> H >> W >> K;
    for(int h=0;h<H;h++){
    	string s;cin >> s;
    	S.push_back(s);
    }
 
    solve();
 
    for(int h=0;h<H;h++){
    	for(int w=0;w<W;w++) cout << ans[h][w] << " ";
    	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,js=0,s;
	cin>>a>>b>>c;
	for(int i=1;i<=a;i++)
	{
		cin>>s;
		if(s>=c||s<b)
		js++;
	}
	cout<<js<<endl;
}

Measured memory_bytes: 256
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var y = 0;
	var ans = 0;
	for(var i = 1; i <= n; i+=2){
		y = 0;
		for(var j = 1; j <= i; j++){
			if(i%j===0)y++;
			if(y>8) break;
		}
		if(y===8){
			ans++;
		}
	}

	console.log(ans);

}

Measured memory_bytes: 21064
#include<cstdio>
#include<queue>
#include<map>

#define fst first
#define snd second

using namespace std;

typedef pair<int,int> que;

int p[100500];
char tbl[100500];

int main(void) {
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&p[i]);
    priority_queue<que> q;
    q.push(que(-0,0));
    while(!q.empty()) {
        que t = q.top(); q.pop();
        int cost = -t.fst;
        int i = t.snd;

        tbl[i] = 1;
        if(i==n-1) {
            printf("%d\n", cost);
            break;
        }
        if(p[i]) {
            if(0<=i+p[i] && i+p[i]<n && !tbl[i+p[i]])
                q.push(que(-cost, i+p[i]));
        } else
            for(int dice=1; dice<=6; dice++)
                if(i+dice<n && !tbl[i+dice])
                    q.push(que(-(cost+1), i+dice));
    }
    return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

long long n, m, x;
long long XX[12];

void init_XX(){
    for(long long i = 0; i < m; i++){
        XX[i] = 0;
    }
}


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

    long long a[n][m];
    long long c[n];


    for(long long  y = 0; y < n; y++){
        for(long long x = 0; x < m+1; x++){
            if(x == 0){
                cin >> c[y];
            }
            else{
                cin >> a[y][x-1];
            }
        }
    }

    long long min_money = 1e9;
    long long cost = 0;

    bool flag = true;

    for(long long bit = 0; bit < (1 << n); bit++){
        flag = true;
        init_XX();
        cost = 0;

        for(long long y = 0; y < n; y++){
            if(bit & (1 << y)){
                cost = cost + c[y];
                for(long long i = 0; i < m; i++){
                    XX[i] = XX[i] + a[y][i];
                }
            }
        }

        for(long long i = 0; i < m; i++){
            if(XX[i] < x){
                flag = false;
                break;
            }
        }
        if(flag == true){
            min_money = min(cost, min_money);
        }
    }

    //printf("money %d\n", min_money);

    if(min_money != 1e9){
        printf("%lld\n", min_money);
    }
    else{
        printf("-1\n");
    }

    return 0;



}

Measured memory_bytes: 3748
N = int(input())
plan = [[0,0,0]]
for i in range(N):
    plan.append(list(map(int,input().split())))
flag = 0
for i in range(N):
    t_d = plan[i+1][0]-plan[i][0]
    p_d = abs(plan[i+1][2]-plan[i][2])+abs(plan[i+1][1]-plan[i][1])
    if t_d%2 != p_d%2 or p_d > t_d:
        flag = 1
print("Yes" if flag == 0 else "No")

Measured memory_bytes: 27380
// tzl ak IOI! 

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}

template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }

template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }

template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T>
void chkmax(T &x, const T &y){ if(y > x) x = y; return; }

template <typename T>
void chkmin(T &x, const T &y){ if(y < x) x = y; return; }

#ifdef ONLINE_JUDGE
#define debug(x,c) ;
#else
#define DEBUG
#define debug(x,c) cerr<<#x<<"="<<x<<c;
#endif

void TZL();

void RANK1();

#define tzl int
#define ak main
#define IOI ()
tzl ak IOI
{
#undef tzl
#undef ak
#undef IOI

	TZL();
	RANK1();

#define tzl return
#define caisi 0
#define myy ;
	tzl caisi myy
#undef tzl
#undef caisi
#undef myy
}

//---------------------------head----------------------------

const int N = 1e5 + 100;

int n;
vi g[N];
bool f[N];

void TZL()
{
	scf(n);
	rep(i, n - 1)
	{
		int u, v; scf(u, v);
		g[u].pb(v); g[v].pb(u);
	}
	return;
}

void dfs(int u, int fa = 0)
{
	int cnt = 0;
	for(int v: g[u]) if(v != fa)
	{
		dfs(v, u);
		cnt += (f[v]);
	}

	if(cnt > 1)
	{
		puts("First");
		exit(0);
	}
	f[u] = cnt ? 0 : 1;
	return;
}

void RANK1()
{
	if(n == 2)
	{
		puts("Second");
		return;
	}

	forn(i, 1, n) if(SZ(g[i]) > 1)
	{
		dfs(i);
		puts(f[i] ? "First" : "Second");
		return;
	}
}

Measured memory_bytes: 6016
import java.util.Arrays;
import java.util.Scanner;
class Player implements Comparable<Player>{
	int party;
	int num;
	String time;
	Player(int p,int n,String t){
		this.party = p;
		this.num = n;
		this.time = t;
	}
	@Override
	public int compareTo(Player o) {
		// TODO Auto-generated method stub
		return this.time.compareTo(o.time);
	}	
}
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Player[] person = new Player[24];
		int[][] rank = new int[3][8];
		int[] cnt = new int[3]; 
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < 8;j++){
				person[i*8+j] = new Player(i,sc.nextInt(),sc.next());
			}
		}
		Arrays.sort(person);
		for(int i = 0;i < 24;i++){
			rank[person[i].party][cnt[person[i].party]] = i;
			cnt[person[i].party]++;
		}
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < 2;j++){
				System.out.println(person[rank[i][j]].num+" "+person[rank[i][j]].time);
				person[rank[i][j]].time = "999";
			}
		}
		Arrays.sort(person);
		for(int j = 0;j < 2;j++){
			System.out.println(person[j].num+" "+person[j].time);
		}	
	}
}

Measured memory_bytes: 26168
import math

N = int(input())
Pi = list(map(int,input().split()))
Qi = list(map(int,input().split()))

a = 0
b = 0

numcheck = [1 for i in range(N)]
numcheck[Pi[0]-1] = 0
a = math.factorial(N-1)*(Pi[0]-1) 
for n in range(1,N):
  num = Pi[n]
  numcheck[num-1] = 0
  a = a + math.factorial(N-1-n)*sum(numcheck[:num])
a = a + 1

numcheck = [1 for i in range(N)]
numcheck[Qi[0]-1] = 0
b = math.factorial(N-1)*(Qi[0]-1) 
for n in range(1,N):
  num = Qi[n]
  numcheck[num-1] = 0
  b = b + math.factorial(N-1-n)*sum(numcheck[:num])
b = b + 1

print(abs(a-b))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

const long long INF = 1LL << 60;
const int MAX_V = pow(10, 3) * 100 + 1;

int main()
{
    int N;
    long long W;
    cin >> N >> W;

    vector<long long> w(N), v(N);
    rep(i, N)
    {
        cin >> w[i] >> v[i];
    }

    vector<vector<long long>> dp(N, vector<long long>(MAX_V + 1, INF));

    dp[0][0] = 0;
    for (int j = 1; j <= v[0]; j++)
    {
        dp[0][j] = w[0];
    }

    for (int i = 1; i < N; i++)
    {
        /*
        for (int j = 1; j <= v[i]; j++)
        {
            chmin(dp[i][j], v[i]);
        }
        */

        rep(j, MAX_V + 1)
        {
            chmin(dp[i][j], dp[i - 1][j]);

            if (j - v[i] >= 0)
            {
                chmin(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
            }
        }
    }

    long long res = 0;
    rep(j, MAX_V + 1)
    {
        if (dp[N - 1][j] <= W)
        {
            res = j;
        }
    }
    cout << res << endl;
}


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

using namespace std;

const int MOD = 1e9 + 7;

int add(int a , int b) {
    a += b;
    while (a >= MOD) a -= MOD;
    while (a < 0) a += MOD;
    return a;
}

long long mul(long long a , long long b) {
    return a * b % MOD;
}

long long power(long long a , long long b) {
    if (!b) return 1;
    long long r = power(a , b / 2);
    r = mul(r , r);
    if (b&1) return mul(r , a);
    return r;
}

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

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

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

//    int test = 0;
//    for (int m = 0 ; m < (1 << n) ; m++) {
//        for (int i = 0 ;i < n ;i++) {
//            if (!(m & (1 << i))) continue;
//            int cnt = 0;
//            for (int j = 0 ;j < i ;j++) {
//                if (m & (1 << j)) cnt++;
//            }
//            test += (cnt + 1) * a[i];
//        }
//    }

    int sum = 0 , ans = 0;
    for (int i = 0 ;i < n ;i++) {
        ans = add(ans , mul(a[i] , add(sum , power(2 , n - 1))));
        sum = add(sum , power(2 , n - 2));
    }

    cout << mul(ans , power(2 , n));
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;;
#define ato find_by_order
#define of order_of_key 
typedef long long ll;
#define mp make_pair
#define pb push_back
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
ll mod=998244353;
int main()
{
    flash
    ll n;ll k;
    cin>>n>>k;
    vector<pair<ll,ll>> ranges(k+1);
    for(ll i=1;i<=k;i++)
    {
        cin>>ranges[i].first;
        cin>>ranges[i].second;
    }
    sort(ranges.begin(),ranges.end());
    ll presum[n+1]={0};
    presum[0]=0;
    presum[1]=1;
    ll dp[n+1]={0};
    dp[1]=1;
    for(ll i=2;i<=n;i++)
    {
        for(ll j=1;j<=k;j++)
        {
           if(i-ranges[j].first<=0)
           break;
           if(i-ranges[j].second>0)
           {
            dp[i]=(dp[i]+presum[i-ranges[j].first]-presum[i-ranges[j].second-1]+mod)%mod;
            continue;   
           }
            dp[i]=(dp[i]+presum[i-ranges[j].first]-presum[0]+mod)%mod;
        }
        presum[i]=(presum[i-1]+dp[i])%mod;
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 6732