akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (N % 2) {
        cout << "No" << endl;
        return 0;
    }
    for (size_t i = 0; i < N / 2; i++) {
        if (S[i] != S[i + N / 2]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b) {
    puts("Zero");
  } else if (a > 0) {
    puts("Positive");
  } else if ((b - a) & 1) {
    puts("Positive");
  } else {
    puts("Negative");
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, X, Y;
  cin>>N>>X>>Y;
  X--;
  Y--;
  map<int, int> amap;
  int ans;
  for(int i=0;i<N;++i) {
    for(int j=i+1;j<N;++j) {
      ans = j-i;
      ans = min(ans, abs(i-X)+1+abs(Y-j));
      ans = min(ans, abs(i-Y)+1+abs(X-j));
      amap[ans]++;
    }
  }
  for(int i=1;i<N;++i) cout<<amap[i]<<endl;
}



Measured memory_bytes: 3696
#ベルマンフォード法
#正の閉路がない時は普通のベルマンフォード法
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
  a,b,c=list(map(int,input().split()))
  es.append((a-1,b-1,c))
import sys
def Bellmanford(n,m,s,es):
  d=[-float("INF")]*n
  d[s]=0
  cnt=0
  negative=[False]*n
  while(1):
    update=False
    for p,q,r in es:
      if d[p]!=-float("INF") and d[q]<d[p]+r:
        d[q]=d[p]+r
        update=True
        if cnt==n-1:
          negative[q]=True
    if cnt==n-1:
      for count in range(n):
        for p,q,r in es:
          if negative[p]:
            negative[q]=True
    cnt+=1
    if not update:
      break
    if cnt==n:
      if negative[n-1]:
        print(float("INF"))
        sys.exit()
      else:
        print(d[n-1])
        sys.exit()
        
  print(d[n-1])
  
Bellmanford(n,m,0,es)  
    
    
      
  
  

  

Measured memory_bytes: 75704
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  cout << ((s < t) ? "Yes" : "No")  << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	return !b?a:gcd(b,a%b);
}
int main(){
	
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;++i)
	for(int j=1;j<=n;++j)
	for(int k=1;k<=n;++k)
		ans+=gcd(gcd(i,j),k);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
/*ex2_3*/
/*moriai ryo*/
#include <stdio.h>
 
int main(void){
  int size,white;/*変数用意*/
  scanf("%d",&size);
  scanf("%d",&white);/*入力*/
  printf("%d\n",size*size-white);/*一辺^2-白いマスの数*/
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n,k,a[maxn],b[maxn];
bool flag;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    while(k--){
        flag=true;
        for(int i=1;i<=n;i++)b[i]=0;
        for(int i=1;i<=n;i++){
            b[max(1,i-a[i])]++;
            b[min(n,i+a[i])+1]--;
        }
        int noww=0;
        for(int i=1;i<=n;i++){
            noww+=b[i];
            a[i]=noww;
            // cout<<b[i]<<" "<<noww<<endl;
            if(noww<n)flag=false;
        }
        if(flag)break;
    }
    for(int i=1;i<=n;i++)
        cout<<a[i]<<" ";
    return 0;
}

Measured memory_bytes: 5236
N, M = map(int, input().split())		# 5 7

h=[]
for i in range(N+1):
	h.append([])

a=[]
b=[]

for i in range(M):
	A, B = map(int, input().split())		# 5 7
	h[A].append(B)
	h[B].append(A)
	a.append(A)
	b.append(B)




def dfs(Graph, Start, Visited=None):
	if(Visited==None): Visited = []
	Visited.append(Start)
	#print(Start, Visited)
	for Next in Graph[Start]:
		if( Next in Visited ): 
			#print("   Visited", Next, Visited)
			continue
		dfs(Graph, Next, Visited)

z=[_ for _ in range(1, N+1)]
#print(z)
ans=0

import copy
for i in range(M):
	g = copy.deepcopy(h)
	
	A = a[i]
	B = b[i]

	g[A].remove(B)
	g[B].remove(A)
	
	Visited = []
	dfs(g, 1, Visited)
	
	#print(A, B, i, Visited)
	if len( list(set(z) - set(Visited)) ) > 0:
	    ans += 1

	
print(ans)


Measured memory_bytes: 3568
#include <cstdio>
#include <cstdlib>


using namespace std;

typedef struct {
  int h, w;
} POINT;

int main(void) {
  POINT *map;
  int *dist;
  int h, w;
  int d, diff;
  int q;
  int l, r;
  int tmp;
  int mp;
  
  scanf("%d%d%d", &h, &w, &d);
  map = new POINT[h * w + 1];
  dist = new int[h * w + 1];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      scanf("%d", &tmp);
      map[tmp].h = i;
      map[tmp].w = j;
      dist[tmp] = -1;
    }
  }
  
  for (int i = 1; i <= d; i++) {
    dist[i] = 0;
    for (int j = i + d; j <= h * w; j += d) {
      dist[j] = dist[j-d] + abs(map[j].h - map[j-d].h) + abs(map[j].w - map[j-d].w);
    }
  }
    
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &l, &r);
    printf("%d\n", dist[r] - dist[l]);
  }
  return 0;
}
      


Measured memory_bytes: 2176
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Wed Dec 26 00:55:01 2018
//
package main

import "fmt"

func pow(a, b int) int {
	if b == 0 {
		return 1
	}
	return a * pow(a, b-1)
}

func main() {
	var X int
	fmt.Scan(&X)

	ans := 1
	for i := 2; i*i <= X; i++ {
		for j := 2; pow(i, j) <= X; j++ {
			if ans < pow(i, j) {
				ans = pow(i, j)
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
# coding: utf-8
# user: herp_sy

def quicksort(seq):
    if len(seq) < 1:
        return seq
    pivot = seq[0]
    left = []
    right = []
    for x in range(1, len(seq)):
        if seq[x] <= pivot:
            left.append(seq[x])
        else:
            right.append(seq[x])
    left = quicksort(left)
    right = quicksort(right)
    foo = [pivot]
    return (left + foo + right)

# , = map(int, input.split())
#  = int(input())

n,a,b = map(int, input().split())
if(n * a < b):
	print(n * a)
else:
	print(b)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fin(x) freopen(x,"r",stdin)
#define fout(x) freopen(x,"w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll inf=0xc0c0c0c0c0c0c0c0;
int N;
const double pi=acos(-1);
vector<int> V;
bool find(int x)
{
	int M=x;
	int cpy=N;
	while(cpy)
	{
		int val=min(cpy,M);
		if(val==0)return 0;
		cpy-=val;
		M=val-1;
	}
	return 1;
}
void solve(int x)
{
	
	int M=x;
	int cpy=N;
	while(cpy)
	{
		int val=min(cpy,M);
		V.pb(val);
		cpy-=val;
		M=val-1;
	}
	for(int i=V.size()-1;~i;i--)
		printf("%d\n",V[i]);
}
int main()
{
	scanf("%d",&N);
	int low=0,high=N;
	while(low+1<high)
	{
		int mid=(low+high)>>1;
		if(find(mid))high=mid;
		else low=mid;
	}
	solve(high);
	return 0;
}


Measured memory_bytes: 384
import sys

n, y = input().split()
n = int(n) + 1
y = int(y)
for i in range(n):
    for j in range(n - i):
        if y == 10000 * i + 5000 * j + 1000 * (n - 1 - i - j):
            print(i, j, n - 1 - i - j)
            sys.exit()

print("-1 -1 -1")


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e8;
const ll mod = 998244353;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	ll n;	cin >> n;
	if (n % 2 == 0) {
		cout << n << " " << n << " " << n / 2 << endl;
		return 0;
	}
	else {
		for (int i = 1; i <= 3500; i++) {
			for (int j = 1; j <= 3500; j++) {
				if (4 * i*j <= n*(i + j))	continue;
				if ((n*i*j) % (4 * i*j - n*(i + j)) == 0) {
					cout << i << " " << j << " " << (n*i*j) / (4 * i*j - n*(i + j)) << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
s = input()
p = input()
if p in s:
    print("Yes")
elif len(p) == 1:
    print("No")
else:    
    for i in range(1, len(p)):
        if p[:i] == s[-i:] and p[i:] == s[:len(p)-i]:
            print("Yes")
            break
        if i == len(p)-1:
            print("No")


Measured memory_bytes: 5560
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(void)
{
    long long int H;
    cin >> H ;
     //vector<long long int >A(H);
    long long int count = 1, sum = 0;

    
    for (; H > 1; H /=2)
    {
        sum += count;
        count *= 2;
    }
    sum += count;
    cout << sum << endl;

}

    

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

#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define mid(a,b) (a+b)/2
#define pii pair<int,int>

using namespace std;

int n,x;

int main()
{
	cin >> n;
	x = n / 2;
	if(n % 2 == 1) x++;
	printf("%.7f",double(x)/double(n));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pqmin priority_queue<ll,vector<ll>,greater<ll>>
#define pqmax priority_queue<ll>
using namespace std;
ll power(ll a,ll n){
	if(n==0)
	  return 1;
	if((n%2)==0)
	  return (power((a*a),n/2));
	else
	  return (a*(power((a*a),n/2)));    
}
int main()
{
  IOS;
      ll n,c=0;
      string s;
      cin>>n>>s;
      for(ll i=0;i<n-2;i++)
      {
          if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
          c++;
      }
      cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 256
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd

mod=10**9+7
#N=int(input())
A,B=map(int,input().split())
#A=list(map(int,input().split()))

for i in range(1,500001):
    #print((i*8)//100,(i*10)//100,i)
    if (i*8)//100==A and (i*10)//100==B:
        print(i)
        exit()

print(-1)


Measured memory_bytes: 63800
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion
signed main() {
	int c=0;
	string s,a="No";
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == 'C')
			c++;
		if (s[i] == 'F' && c > 0)
			a = "Yes";
	}
	cout << a;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int pointA = 0;
	int pointB = 0;
	for(int i = 0; i < n; i++) {
		a[i] = sc.nextInt();
	}
	Arrays.sort(a);
	int[] b = new int[n];
	for(int i = 0; i < n; i++) {
		b[i] = a[n - i - 1];
	}
	for(int i = 0; i < n; i++) {
		if(i % 2 == 0) {
			pointA += b[i];
		} else {
			pointB += b[i];
		}
	}
	System.out.println(pointA - pointB);
}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(ll i=a;i<b;i++)
#define ll long long

int main()
{
   int n;
  cin>>n;
  int a[n+1];
  ll prefix[n+1];
  for(int i=0;i<=n;i++) prefix[i] = 0;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    prefix[i] = prefix[i-1]+a[i];
  }
  vector<vector<ll>> dp(n+1,vector<ll> (n+1,0));
  ll small;
  for(int i=n;i>=1;i--)
  {
    for(int j=i+1;j<=n;j++)
    {
      dp[i][j] = prefix[j]-prefix[i-1];
      small = 1e14;
      for(int k=i;k<j;k++)
      {
        small = min(dp[i][k]+dp[k+1][j],small);
      }
      if(small != 1e14)
        dp[i][j] = dp[i][j] + small;
    }
  }
  cout<<dp[1][n];
  return 0;
}

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

int main(){
    vector<vector<int>> a1(3, vector<int>(10));
    vector<vector<int>> a2(3, vector<int>(10));
    vector<vector<int>> a3(3, vector<int>(10));
    vector<vector<int>> a4(3, vector<int>(10));
    int n; cin >> n;

    for (int i = 0; i < n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        if (b == 1) a1[f-1][r-1] += v;
        if (b == 2) a2[f-1][r-1] += v;
        if (b == 3) a3[f-1][r-1] += v;
        if (b == 4) a4[f-1][r-1] += v;
    }
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 10; j++){
            cout << " " << a1[i][j]; 
        }
        cout << endl;
    }
    for (int i = 0; i < 20; i++){
        cout << "#";
    }
    cout << endl;

    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 10; j++){
            cout << " " << a2[i][j]; 
        }
        cout << endl;
    }
    for (int i = 0; i < 20; i++){
        cout << "#";
    }
    cout << endl;

    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 10; j++){
            cout << " " << a3[i][j]; 
        }
        cout << endl;
    }
    for (int i = 0; i < 20; i++){
        cout << "#";
    }
    cout << endl;

    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 10; j++){
            cout << " " << a4[i][j]; 
        }
        cout << endl;
    }

}


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

int main() {

	int n, r; cin >> n >> r;
	int ans;
	if (10 <= n) ans = r;
	else ans = r + 100 * (10 - n);
	cout << ans << endl;	
    return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
// constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;

ll n,k;
int a[200010];

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
}

ll table[200010][100];
ll pre[200010];

void make_table() {

    for (int i = n * 2 - 1; i >= 0; i--) {
        table[i%n][0] = pre[a[i%n]] - i + 1;
        pre[a[i%n]] = i;
    }

    for (int i = 1; i < 64; i++) {
        for (int j = 0; j < n; j++) {
            if (table[j][i-1] == -1 || table[(table[j][i-1] + j) % n][i-1] == -1) {
                table[j][i] = -1;
                continue;
            }
            table[j][i] = table[j][i-1] + table[(table[j][i-1] + j) % n][i-1];
            if (table[j][i] > k) table[j][i] = -1;
        }
    }

}

bool inque[200010] = {};
void solve() {
    make_table();
    ll pos = 0;
    ll left = n * k;
    // for (int i = 0; i < 64; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << table[j][i] << " ";
    //     }
    //     cout << endl;
    // }
    while (1) {
        // cout << pos << " " << left << endl;
        bool f = 1;
        for (int i = 63; i >= 0; i--) {
            if (table[pos][i] == -1) continue;
            if (left >= table[pos][i]) {
                left -= table[pos][i];
                pos += table[pos][i];
                pos %= n;
                f = 0;
                break;
            }
        }
        if (f) break;
    }

    deque<int> dq;
    while (left--) {
        if (!inque[a[pos]]) {
            dq.push_back(a[pos]);
            inque[a[pos]] = 1;
        } else {
            inque[a[pos]] = 0;
            while (dq.back() != a[pos]) {
                inque[dq.back()] = 0;
                dq.pop_back();
            }
            dq.pop_back();
        }
        pos++;
        pos %= n;
    }

    while (!dq.empty()) {
        cout << dq.front();
        dq.pop_front();
        if (dq.empty()) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
}

int main(int argc, char *argv[]) {
    input();
    solve();
    return 0;
}


Measured memory_bytes: 161152
# coding: utf-8

n = int(input())
weights = [int(x) for x in input().rstrip().split(" ")]
s_diff = n * 100

for i in range(n):
    s1 = sum(weights[0:i])
    s2 = sum(weights[i:])
    s_diff_candidate = abs(s1 - s2)
    if s_diff > s_diff_candidate:
        s_diff = s_diff_candidate

print(s_diff)


Measured memory_bytes: 2940
//vacation: dp state, day, last choice he made

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

using ll = long long;
#define pb push_back
#define f first
#define s second
#define MAXN 1e5+5
int dp[3][(int)MAXN];
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<pair<int, int> , int>> inp(n);
    for(int i = 0 ; i < n; i++){
        cin >> inp[i].f.f >> inp[i] .f.s >> inp[i].s; 
    }
    dp[0][0] = inp[0].f.f; dp[1][0] = inp[0].f.s; dp[2][0] = inp[0].s;
    for(int i= 1; i < n; i++){
        dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + inp[i].f.f;
        dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + inp[i].f.s;
        dp[2][i] = max(dp[1][i-1], dp[0][i-1]) + inp[i].s;
    }
    cout << max({dp[0][n-1], dp[1][n-1], dp[2][n-1]});
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
using namespace std;
int main(){
    int i,j,n,a[5]={0},b,c=0;
    cin >> n;
    for(i=0;i<=n;i++){
        b = i;
        j = 0;
        while (b!=0){
            a[j] = b%10;
            b = b/10;
            j++;
        }
        if(j%2!=0){
            c++;
        }
    }
    cout << c;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <functional>
#include <queue>
#include <tuple>
#include <cstring>
#include <iomanip>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define each(i,n) for(auto i : n)
#define all(n) n.begin(),n.end()
#define clr(n) memset(n,0,sizeof(n))
#define mclr(n) memset(n,-1,sizeof(n))

//dp[bit][i][j] ?´???£??????????????????bit???i???????????¨?±????j?????????????????????
//??¨??¨????????????????¢????
double dp[1 << 16][16];

//ap[i][j][k] ???i ?????¨?±?j????????¨?±?k?????????????¢????
double ap[16][16][17];
double a[16][17];

int main() {
	int n, m;
	cin >> m >> n;
	mclr(dp);
	rep(i, m) {
		rep(j, n) {
			cin >> a[i][j];
		}
		a[i][n] = 0.0;
	}
	rep(i, m) {
		rep(j, n) {
			rep(k, n + 1) {
				ap[i][j][k] = 1.0;
				for (int l = j; l < k; l++) {
					ap[i][j][k] *= a[i][l];
				}
				ap[i][j][k] *= (1.0 - a[i][k]);
			}
		}
	}
	function<double(int, int)> solve = [&](int bit, int i) {
		if (i == n)return 1.0;
		if (dp[bit][i] >= -0.5) {
			return dp[bit][i];
		}
		double re = 0.0;
		rep(k, m) if(!(bit & (1 << k))) {
			double p = 0.0;
			for (int l = i; l <= n; l++) {
				p += solve(bit | (1 << k), l) * ap[k][i][l];
			}
			re = max(re, p);
		}
		return dp[bit][i] = re;
	};
	cout << fixed << setprecision(30) << solve(0, 0) << endl;
	
	return 0;
}

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




int main() {
    long long ans = 0;
    int num, keta;
    string s;
    cin >> s;
    int m[2019];
    for (int i = 0; i < 2019; i++)m[i] = 0;
    num = 0;
    keta = 1;
    m[num] = 1;

    for (int i = s.size() - 1; i >= 0; i--) {
        int l = (int)(s[i] - '0');
        num = keta * l + num;
        num %= 2019;
        m[num]++;
        keta *= 10;
        keta %= 2019;
    }

    for (int i = 0; i < 2019; i++) {
        if(m[i] != 0)ans += m[i] * (m[i] - 1) / 2;
    }
    cout << ans;
}

Measured memory_bytes: 3744
#include <iostream>
#include <queue>
#include <map>

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

int main(){
    ll n;
    cin >> n;
    map<ll, ll> s;
    REP(i, n){
        ll ai;
        cin >> ai;
        s[ai]++;
    }
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(auto it = s.begin(); it != s.end(); ++it){
        que.push(it->second);
    }

    vector<ll> ans(n, 0);
    for(ll i = que.size(); i >= 1; --i){
        ans.at(i - 1) = que.top();
        if(que.size() > 1){
            ll x1 = que.top(); que.pop();

            while(x1 > 0){
                ll x2 = que.top(); que.pop();
                que.push(x2 + 1);
                x1--;
            }
        }
    }
    REP(i, ans.size()){
        cout << ans.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 24684
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int data[512][512];
int main() {
  int H, W;
  cin>>H>>W;
  REP(h,H) REP(w,W) cin>>data[h][w];
  vector<int> ys, xs;
  deque<pint> os;
  REP(h,H) {
    if(h % 2 == 0) {
      for(int w = 0; w < W; w++) {
	ys.push_back(h);
	xs.push_back(w);
	if(data[h][w] % 2 != 0) os.push_back(make_pair(h, w));
      }
    } else {
      for(int w = W-1; w >= 0; w--) {
	ys.push_back(h);
	xs.push_back(w);
	if(data[h][w] % 2 != 0) os.push_back(make_pair(h, w));
      }
    }
  }
  if(os.size() % 2 != 0) os.pop_back();
#ifdef DEBUG
  REP(i, os.size()) {
    cout << os[i].first << " " << os[i].second << endl;
  }
  REP(i, ys.size()) {
    cout << i << " " << ys[i] << endl;
  }
  REP(i, xs.size()) {
    cout << i << " " << xs[i] << endl;
  }
#endif
  int count = 0;
  vector<pint> from, to;
  REP(i, ys.size()-1) {
    if(!os.empty() && os[0].first == ys[i] && os[0].second == xs[i]) {
      count ++;
      os.pop_front();
    }
    if(count % 2 != 0) {
      from.push_back(make_pair(ys[i], xs[i]));
      to.push_back(make_pair(ys[i+1], xs[i+1]));
    }
  }
  //  cout << "Answer=";
  cout << from.size() << endl;
  REP(i, from.size()) {
    cout << from[i].first+1 << " "
	 << from[i].second+1 << " "
	 << to[i].first+1 << " "
	 << to[i].second+1 << endl;
  }
  return 0;
}


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

int main(){
	int n;
	cin>>n;
	
	vector<int> a(n);
	cin>>a[0]>>a[1];
	vector<int> left(n),right(n);
	left[1]=a[0];
	for(int i=2;i<n;++i){
		cin>>a[i];
		left[i]=__gcd(left[i-1],a[i-1]);
	}
	right[n-2]=a[n-1];
	for(int i=n-3;i>=0;--i){
		right[i]=__gcd(right[i+1],a[i+1]);
	}
	left[0]=right[0];
	right[n-1]=left[n-1];
	
	int ans=0;
	REP(i,n){
		ans=max(ans,__gcd(left[i],right[i]));
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (50)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, A, B;
  long vs[MAX_N];
  scanf("%d %d %d", &N, &A, &B);
  for (int i = 0; i < N; i++) {
    scanf("%ld", &vs[i]);
  }

  // sort
  sort(vs, vs + N);

  // calculate the maximum average
  double ave_max = 0.0;
  for (int i = 0; i < A; i++) {
    ave_max += vs[N - 1 - i];
  }
  ave_max /= A;

  // take A from the back and determine the smallest value used
  const long v_min = vs[N - A];
  // determine how many v_min are in vs (n) and
  // how many to use when A values are chosen in total (k)
  const long *it_lb = lower_bound(vs, vs + N, v_min);
  const long *it_ub = upper_bound(vs, vs + N, v_min);
  const int n = it_ub - it_lb, k = it_ub - (vs + N - A);

  // calculate combinations
  long comb[MAX_N + 1][MAX_N + 1];  // comb[i][j] : iCj
  comb[0][0] = 1;
  comb[1][0] = 1;
  comb[1][1] = 1;
  for (int i = 2; i <= N; i++) {
    comb[i][0] = 1;
    comb[i][i] = 1;
    for (int j = 1; j < i; j++) {
      comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
    }
  }

  // calculate ans
  long ans = 0;
  if (v_min == vs[N - 1]) {  // choose arbitrary v_min
    for (int i = A; i <= B && k + i - A <= n; i++) {
      ans += comb[n][k + (i - A)];
    }
  } else {
    ans = comb[n][k];
  }

  printf("%.10lf\n%ld\n", ave_max, ans);

  return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T x; cin >> x; return x; }

signed main()
{
	while (true) {
		int h = in(), w = in();
		if (h == 0 && w == 0) {
			break;
		}
		vector<vector<char>>tile(h, vector<char>(w));
		vector<vector<bool>>step(h, vector<bool>(w, false));
		REP(i, h) {
			REP(j, w) {
				tile[i][j] = in<char>();
			}
		}
		int x = 0, y = 0;
		while (true) {
			step[y][x] = true;
			switch (tile[y][x]) {
			case '>':
				++x;
				break;
			case '<':
				--x;
				break;
			case '^':
				--y;
				break;
			case 'v':
				++y;
				break;
			}
			if (tile[y][x] == '.') {
				cout << x << ' ' << y << endl;
				break;
			} else if (step[y][x]) {
				cout << "LOOP" << endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 3132
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val ans = Array(26) { Int.MAX_VALUE }
    for (i in 0 until n) {
        val s = sc.nextLine()
        for (j in 0 until 26) {
            val c = 'a' + j
            val num = s.filter { it == c }.count()
            ans[j] = Math.min(ans[j], num)
        }
    }
    for (i in 0 until 26) {
        val c = 'a' + i
        print(c.toString().repeat(ans[i]))
    }
    println()
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 31640
#include <bits/stdc++.h>
const int maxn = int(1e5) + 7, inf = 0x3f3f3f3f;
int n, x[maxn], up[maxn][20], l, q, u, v, e[27] = {1}, ans, tmp;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", x + i);
    scanf("%d%d", &l, &q);
//    memset(up, 0x3f, sizeof(up));
    int cur = 1;
    for (int i = 1; i <= n; i++) while (x[i] > x[cur] + l) up[cur++][0] = i - 1;//, printf("asd %d\n",up[cur-1][0]);
    for (int j = 1; j < 20; j++) {
        e[j] = e[j - 1] << 1;
        for (int i = 1; i <= n; i++) if (up[i][j - 1] ) //if (up[i][j - 1] < inf)
            up[i][j] = up[up[i][j - 1]][j - 1];
    }
    while (ans = 0, q--) {
        scanf("%d%d", &u, &v);
        if (u > v) std::swap(u, v);
        for (int i = 19; i >= 0; i--) if (up[u][i] < v && up[u][i]) u = up[u][i], ans += e[i];
        printf("%d\n", ans + 1);
    }
    return 0;
}//倍增优化DP？ 

Measured memory_bytes: 9088
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, k;

	cin >> a >> b >> k;

	int saidai = max(max(a, b), k);

	int goukei = a + b + k;

	if (goukei % 2 == (saidai * 3) % 2) {
		cout << ((saidai * 3) - goukei) / 2 << endl;
	}
	else {
		cout << ((saidai * 3) + 3 - goukei) / 2 << endl;
	}

	
	

}
	

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        int[][] sums = new int[h + 1][w + 1];
        for (int i = 1; i <= h; i++) {
            char[] arr = sc.next().toCharArray();
            for (int j = 1; j <= w; j++) {
                sums[i][j] = sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1];
                if (arr[j - 1] == '1') {
                    sums[i][j]++;
                }
            }
        }
        ArrayDeque<ArrayList<Unit>> deq = new ArrayDeque<>();
        ArrayDeque<ArrayList<Unit>> decided = new ArrayDeque<>();
        for (int i = 1; i <= h; i++) {
            ArrayList<Unit> list = new ArrayList<>();
            list.add(new Unit(0, i));
            if (i == h) {
                decided.add(list);
            } else {
                deq.add(list);
            }
        }
        while (deq.size() > 0) {
            ArrayList<Unit> u = deq.poll();
            int start = u.get(u.size() - 1).down;
            for (int i = start + 1; i < h; i++) {
                ArrayList<Unit> base = (ArrayList<Unit>)(u.clone());
                base.add(new Unit(start, i));
                deq.add(base);
            }
            u.add(new Unit(start, h));
            decided.add(u);
        }
        int min = Integer.MAX_VALUE;
        while (decided.size() > 0) {
            ArrayList<Unit> each = decided.poll();
            int left = 0;
            int right = left + 1;
            int count = 0;
            while (left < w) {
                if (getMax(left, right, each, sums) > k) {
                    count = Integer.MAX_VALUE / 2;
                    break;
                }
                while (right < w && getMax(left, right + 1, each, sums) <= k) {
                    right++;
                }
                count++;
                left = right;
                right = left + 1;
            }
            min = Math.min(min, each.size() - 1 + count - 1);
        }
        System.out.println(min);
   }
   
   static int getMax(int left, int right, ArrayList<Unit> each, int[][] sums) {
       int max = 0;
       for (Unit u : each) {
           max = Math.max(max, sums[u.down][right] - sums[u.up][right] - sums[u.down][left] + sums[u.up][left]);
       }
       return max;
   }
   
   static class Unit {
       int up;
       int down;
       
       public Unit(int up, int down) {
           this.up = up;
           this.down = down;
       }
       
       public String toString() {
           return up + ":" + down;
       }
   }
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    cout << (s[0] == s[2] ? "Yes" : "No") << endl;
}


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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x-a) % b << endl;
}

Measured memory_bytes: 256
def search_leaf(edge:list):
    """ 葉を取得 """
    for v in range(N):
        if len(edge[v]) == 1: return v
    return -1

N,M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

ans = 0
for _ in range(M):
    V = search_leaf(edge)
    if V == -1: break

    main_land = edge[V][0]
    edge[main_land].remove(V)
    edge[V] = []

    ans += 1

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class CKThSubstring {
public:
	void solve(istream& in, ostream& out) {
        string s; int k;
        in >> s >> k;
        int sz = s.size();
        vector<string> a;
        int cnt = 0,z = 0;
        rep(i,k){
            int j = 0;
            while(j < sz - i){
                string sub = s.substr(j,i+1);
                a.push_back(sub);
                j++;
                cnt++;
            }
        }
        sort(a.begin(),a.end());
        rep(i,cnt - 1) {
            if (a[i + 1] == a[i]){
                a[i] = "00";
                z++;
            }
        }
        sort(a.begin(),a.end());

        out << a[z + k-1] << endl;
	}
};

int main() {
	CKThSubstring solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 1660
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
ll pw(ll x,int y){
    REP(i,y){
        x*=2;
    }
    return x;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    int now;
    vint tim(20,0);
    cin >> n >> k;
    if(n>=k){
        tim[0]=n-k+1;
        now=k;
    }else{
        now = n+1;
    }
    for(int i=1;i<18;++i){
        if(pw(now,i)<k){
            continue;
        }
        ll ok = now;
        ll ng = -1;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(pw((ll)mid,i)>=k){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        tim[i]=now-ok;
        now=ok;
    }
    ll bunsi = 0;
    ll bunbo = 0;
    bunbo = pw(1,17)*(ll)n;
    REP(i,18){
        bunsi+=(ll)tim[i]*pw(1,17-i);
    }
    double ans = (double)bunsi/(double)bunbo;
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

int main(){
  
  // read problem
  long long int N, tmp;
  scanf("%lld", &N);

  std::vector<long long int> P(N), Q(N);
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    P[i] = tmp;
  }
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    Q[i] = tmp;
  }


  // solve problem
  long long int n_perm = 0;
  int flagP = 0, flagQ = 0, flg;
  long long int n_P, n_Q;
  std::vector<long long int> perm(N);
  for(long long int i = 0; i < N; i++){
    perm[i] = i+1;
  }

  while(flagP == 0 || flagQ == 0){

    /*std::cerr << "perm: " << std::endl;
    for(long long int i = 0; i < N; i++){
      std::cerr << perm[i] << " ";
    }std::cerr << std::endl;*/

    // compare perm and P
    flg = 1;
    for(long long int i = 0; i < N; i++){
      if(perm[i] != P[i]){
        flg = 0;
        break;
      }
    }
    if(flg == 1){
      n_P = n_perm;
      flagP = 1;
    }

    // compare perm and Q
    flg = 1;
    for(long long int i = 0; i < N; i++){
      if(perm[i] != Q[i]){
        flg = 0;
        break;
      }
    }
    if(flg == 1){
      n_Q = n_perm;
      flagQ = 1;
    }

    // update state
    n_perm++;
    std::next_permutation(perm.begin(), perm.end());
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << std::abs(n_P - n_Q) << std::endl;

  return 0;

}


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

s = map(int, input().split())

ans = 0
step = 0
prev = -1

for x in s:
  if x <= prev:
    step += 1
  else:
    if ans < step:
      ans = step
    step = 0
  prev = x

if ans < step:
  ans = step

print(ans)


Measured memory_bytes: 11136
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        ArrayList<String> a = new ArrayList<String>();
        try {
            int i = 1;
            while (i <= 10000) {
                a.add("Case " + i + ": " + scanner.nextInt());
                i++;
            }
        } catch (InputMismatchException e) {
            //
        } catch (NoSuchElementException e) {
            //
        }
        for (int i = 0; i < a.size(); i++) {
            System.out.println(a.get(i));
        }
        scanner.close();
    }
}



Measured memory_bytes: 43528
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int min = 101;
        for (int i = 0; i < 27; i++) {
            boolean hit = false;
            int count = 0;
            int maxChain = 0;
            char target = (char) ('a' + i);
            for (char c : S.toCharArray()) {
                if (target == c) {
                    hit = true;
                    maxChain = Math.max(maxChain, count);
                    count = 0;
                } else {
                    count++;
                }
            }
            if (hit) {
                maxChain = Math.max(maxChain, count);
                min = Math.min(min, maxChain);
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 35788
#include "bits/stdc++.h"
using std::cin;
using std::cout;

int cnt = 0;
char map[21][21];

void dfs(int x, int y, int mx, int my){
    if((x < 0) || (x >= mx)){
        return;
    }
    if((y < 0) || (y >= my)){
        return;
    }
    if(map[x][y] == '#'){
        return;
    }
    map[x][y] = '#';
    cnt++;
    dfs(x+1, y, mx, my);
    dfs(x-1, y, mx, my);
    dfs(x, y+1, mx, my);
    dfs(x, y-1, mx, my);
}

int main(){
    int W, H, sx, sy;
    cin >> W >> H;

    while(W != 0 && H != 0){
        for(int i = 0; i < H; i++){
            scanf("%20s", map[i]);
            if(std::string(map[i]).find('@') != std::string::npos){
                sx = i;
                sy = std::string(map[i]).find('@');
            }
        }
        dfs(sx, sy, H, W);
        cout << cnt << std::endl;

        cin >> W >> H;
        cnt = 0;
        
    }
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int main() {
	int x; cin >> x;
	if (x == 0) cout << "1" << endl;
	else cout << "0" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (142 + 17);

template<class FlowT>
struct max_flow
{
	const static FlowT finf = 1e18 + 42 + 17;
	const static FlowT feps = 0;

	struct edge
	{
		FlowT flow, cap;
		int idx, rev, to;
		edge() { flow = 0; cap = 0; rev = 0; idx = 0; to = 0; }
		edge(int _to, int _rev, FlowT _flow, FlowT _cap, int _idx)
		{
			to = _to; rev = _rev;
			flow = _flow; cap = _cap;
			idx = _idx;
		}
	};

	vector<edge> G[MAXN];
	int n, dist[MAXN], po[MAXN];

	bool bfs(int s, int t)
	{
		dist[s] = -1, po[s] = 0;
		dist[t] = -1, po[t] = 0;
		for(int v = 0; v <= n; v++)
			dist[v] = -1, po[v] = 0;

		queue<int> Q;
		Q.push(s);
		dist[s] = 0;

		while(!Q.empty())
		{
			int u = Q.front();
			Q.pop();

			for(edge e: G[u])
				if(dist[e.to] == -1 && e.flow < e.cap)
				{
					dist[e.to] = dist[u] + 1;
					Q.push(e.to);
				}
		}

		return dist[t] != -1;
	}

	FlowT dfs(int u, int t, FlowT fl = finf)
	{
		if(u == t)
			return fl;

		for(; po[u] < G[u].size(); po[u]++)
		{
			auto &e = G[u][po[u]];
			if(dist[e.to] == dist[u] + 1 && e.flow < e.cap)
			{
				FlowT f = dfs(e.to, t, min(fl, e.cap - e.flow));

				e.flow += f;
				G[e.to][e.rev].flow -= f;

				if(f > 0)
					return f;
			}
		}

		return 0;
	}

	void init(int _n) { n = _n; }

	void add_edge(int u, int v, FlowT w, int idx = -1)
	{
		G[u].push_back(edge(v, G[v].size(), 0, w, idx));
		G[v].push_back(edge(u, G[u].size() - 1, 0, 0, -1));
	}

	FlowT flow(int s, int t)
	{
		if(s == t) return finf;

		FlowT ret = 0, to_add;
		while(bfs(s, t))
			while((to_add = dfs(s, t)))
				ret += to_add;

		return ret;
	}
};


int n;
int64_t a[MAXN];

void read()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i]; 
}

max_flow<int64_t> mf;

void solve()
{
	int s = n + 2, t = n + 3;
	mf.init(n + 42);

	for(int i = 1; i <= n; i++)
		for(int j = 2 * i; j <= n; j += i)
			mf.add_edge(i, j, max_flow<int64_t>::finf);

	int64_t answer = 0;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] < 0) mf.add_edge(s, i, -a[i]);
		else mf.add_edge(i, t, a[i]), answer += a[i];
	}

	cout << answer - mf.flow(s, t) << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	while (true)
	{
    	int X, Y, A;
    	cin >> X >> Y >> A;
		if (X == 0) break;
    // 	int L[101][1001] = {};
        vector<vector<int>> L(101, vector<int>(1001, 0));
	    
	    REP(m, Y) {
    		int y, l, r;
    		cin >> y >> l >> r;
    
    		L[l][y] = r;
    		L[r][y] = l;
	    }

        for (int i=1000; i!=0; --i)
        {
    		if (L[A][i] != 0)
    		{
    			A = L[A][i];
    		}
        }
	    cout << A << endl;
	}

	return 0;
}



Measured memory_bytes: 3464
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
int main(void){
	string s;
	int w,i;
	cin>>s>>w;
	for(i=0;i<s.size();i+=w)cout<<s[i];
	cout<<endl;
}

Measured memory_bytes: 256