akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>// 加法 S.size() s.substr(l,r=s.size()-l) -> l文字目からr文字分
#include<cmath>//三角関数,rad
#include<algorithm>//__gcd()　lower_bound(a+l,a+r,x)-a でindex
// 配列  -> min/max({}) 
// vector-> *min_element(a+l,a+r)  *忘れず lとrで[l,r) 
//reverse(a+l,a+r)   配列aの[l,r)を逆順に strはreverse(all(s))
//sort(a+l,a+r,greater <int>()) 配列aの[l,r)昇順sort,大きい順はgreater<type>()
//vectorならall(v)
#include<ctime>//"clock()/CLOCKS_PER_SEC で秒数
#include<vector>//v.push_back(x),v.pop_back()
#include<queue>//q.push(x),front()で先頭を返す,pop()で削除, size(),empty()
#include<functional>//vector,queueと併用でpriority_queue
//宣言は priority_queue< Type, vector<Type>, greater<Type>> Q1; 
// pq.push(x),top()で参照 pop()で削除   greaterで最小 lessで最大がtopに
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define print(i) std::cout << (i) << '\n'
inline int ceildiv(int a, int b) { return (a+b-1)/b; }
typedef pair<int,int> P;
const int inf = 10e7;
//int |x|<=2*10**9     long |x|<= 9*10**18

void inlineprint(auto v){
    auto p=v.end()-1;
    for (auto y=v.begin();y<p;y++){cout<<*y<<" ";}
    cout<<*p<<"\n";
}
signed main(){
long long n,m,ans=0ll;cin>>n;m=n;

for (int i=2;i<=sqrt(m);i++){
    if (n%i==0){
        
        while (n%i==0){n/=i;}
        ;
        if (n%i==1){ans+=1;}

        n=m;
        }
}
long long jk=1;
n--;
for (int i=2;i<=sqrt(m-1);i++){
  if (n%i==0){
        long long cnt=0ll;
        while (n%i==0){n/=i;cnt++;}
 
        jk*=(cnt+1);
        }
}if (n!=1)jk*=2;

print(ans+jk);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
string S,T,U;
vector<string> ans;
int i,j,k,l;

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>S>>T;
  for(i=0;i<S.size();i++){
    for(j=0;j<T.size();j++){
      if(i+j>=S.size())goto E;
      // cout<<S[i+j]<<" "<<T[j]<<endl;
      if(S[i+j]!=T[j] && S[i+j]!='?'){
        goto E;
      }
    }
    // forを抜けた
    U="";
    for(k=0;k<S.size();k++){
      if(k==i){
        for(l=0;l<T.size();l++){
          U+=T[l];
          k++;
        }
        k--;
      }else if(S[k]=='?'){
        U+='a';
      }else{
        U+=S[k];
      }
    }
    ans.push_back(U);

    E:;
  }
  if(ans.size()==0){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  sort(ans.begin(), ans.end());
  cout<<ans[0]<<endl;
  // for(auto ss: ans){P(ss);}
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (n == i * j) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        sc = new Scanner(System.in);
        long a = sc.nextLong(),ans = 0,num = 100;
        while(true){
            if(num >= a){
                System.out.println(ans);
                break;
            }  
            num += num/100;
            ans++;
        }
    }
}








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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N;
	cin >> N;
	string S;
	cin >> S;

	//右側のR, G, Bの数を数えておく
	vector <ll> R(N, 0);
	vector <ll> G(N, 0);
	vector <ll> B(N, 0);

	if (S[N-1] == 'R'){
		R[N-1] = 1;
	} else if(S[N-1] == 'G') {
		G[N-1] = 1;
	}else {
		B[N-1] = 1;
	}
	for (int ii = N-2; ii >= 0; --ii){
		R[ii] = R[ii+1];
		G[ii] = G[ii+1];
		B[ii] = B[ii+1];
		if (S[ii] == 'R'){
			R[ii] += 1;
		} else if(S[ii] == 'G') {
			G[ii] += 1;
		}else {
			B[ii] += 1;
		}
	}

	//カウント
	ll sum = 0;
	for (int ii = 0; ii < N-2; ++ii){
		for (int jj = ii+1; jj < N-1; ++jj){
			int invalidIdx = jj + abs(jj-ii);
			if ( ((S[ii] == 'R') && (S[jj] == 'G')) || ((S[ii] == 'G') && (S[jj] == 'R')) ){
				sum += B[jj+1];
				if (invalidIdx < N){
					if (S[invalidIdx] == 'B'){
						sum -= 1;
					}
				}
			} else if ( ((S[ii] == 'R') && (S[jj] == 'B')) || ((S[ii] == 'B') && (S[jj] == 'R'))){
				sum += G[jj+1];
				if (invalidIdx < N){
					if (S[invalidIdx] == 'G'){
						sum -= 1;
					}
				}
			} else if ( ((S[ii] == 'B') && (S[jj] == 'G')) || ((S[ii] == 'G') && (S[jj] == 'B')) ){
				sum += R[jj+1];
				if (invalidIdx < N){
					if (S[invalidIdx] == 'R'){
						sum -= 1;
					}
				}
			}
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3648
N, M = map(int, raw_input().split())
D = [map(int, raw_input().split()) for _ in range(M)]
 
score = [None for _ in range(N+1)]
score[1] = 0
 
for _ in range(N):
    for a, b, c in D:
        if score[a] != None:
            score[b] = max(score[b], score[a] + c)
v1 = score[-1]
for _ in range(N):
    for a, b, c in D:
        if score[a] != None:
            score[b] = max(score[b], score[a] + c)
v2 = score[-1]
 
if v1 != v2:
    print "inf"
else:
    print v2

Measured memory_bytes: 2948
N = int(input())
AList = [int(i) for i in input().split()]
BList = [int(i) for i in input().split()]
CList = [int(i) for i in input().split()]
Kasan = 0
for k in range(N-1):
    if AList[k]+1 == AList[k+1]:
        Kasan += CList[AList[k]-1]
print(sum(BList) + Kasan)

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

int main(){
  
  int N;
  cin >> N;
  vector<string> vecblue(N);
  
  for(int i=0;i<N;i++){
    cin >> vecblue.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> vecred(M);
  
  for(int i=0;i<M;i++){
    cin >> vecred.at(i);
  }
  
  vector<int> veccount(N);
  
  int c;
  
  for(int i=0;i<N;i++){
    c=0;
    for(int j=0;j<N;j++){
      if(vecblue.at(i)==vecblue.at(j)){
        c++;
      }
    }
    for(int k=0;k<M;k++){
      if(vecblue.at(i)==vecred.at(k)){
        c--;
      }
    }
    veccount.at(i) = c;
    }
    
	int a = 0;
      for(int i=0;i<N;i++){
        if(a < veccount.at(i)){
          a = veccount.at(i);
        }
      }
      
      cout << a << endl;
}
  

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

int main()
{
  int N; cin >> N;
  int L[200];
  for(int i = 0; i < N*2; i++) cin >> L[i];
  sort(L, L+2*N);
  int ans = 0;
  for(int i = 0; i < N; i++) ans += L[i*2];
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int i, j;
  int sum[10000] = {};
  char st[1000];

  for( i = 0 ; ; i++ )
  {
    sum[i] = 0;
    scanf("%s", st);
    if( st[0] == '0' )
      break;
    for( j = 0 ; j < strlen(st) ; j++ )
    {
      sum[i] = sum[i] + st[j] - '0';
    }
  }

  for( j = 0 ; j < i ; j++ )
    printf("%d\n", sum[j]);
}



Measured memory_bytes: 2064
#include<iostream>
using namespace std;
int main()
{
    // get two integer
    int i,n,k;
    cin >> n>>k;
	int l[n];
	for (i = 0;i<n;i++){
	cin>>l[i];
	}
    // output
	for(i = 1;i < n;i++){  
		int temp = l[i];  
		int j = i - 1;  
		while(temp < l[j]){  
			l[j+1] = l[j];  
			j--;  
			if(j == -1){  
				break;  
			}  
		}  
		l[j+1] = temp;  
	}  
	int sum = 0;
	for(i = 0;i<k;i++)
		sum +=l[n-i-1];
	cout<<sum<<endl;
    return 0;
}


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

using namespace std;

typedef vector<int> Vec;

vector<int> gay;

int Dfs(int msk) {
  if (!msk) return 0;
  assert((msk & -msk) != msk);
  int &res = gay[msk];
  if (res) return res;
  res = 2233;
  for (int i = 0; i < 16; ++i) {
    if (msk >> i & 1) {
      for (int j = i + 1; j < 16; ++j) {
        if (msk >> j & 1) {
          int g = i ^ j;
          res = min(res, 1 + (msk >> g & 1) + Dfs(msk ^ (1 << i) ^ (1 << j) ^ (1 << g)));
        }
      }
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  Vec w(n), cnt(16);
  
  for (int i = 1, x, y, z; i < n; ++i) {
    cin >> x >> y >> z;
    w[x] ^= z;
    w[y] ^= z;
  }
  for (int i = 0; i < n; ++i) {
    ++cnt[w[i]];
  }

  int ans = 0, msk = 0;
  for (int i = 1; i < 16; ++i) {
    ans += cnt[i] / 2;
    cnt[i] %= 2;
    msk |= cnt[i] << i;
  }

  gay.resize(1 << 16);
  cout << ans + Dfs(msk) << endl;
  
  return 0;
}


Measured memory_bytes: 896
import math
k = int(input())


total = 0

for x in range(1,k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            if x == y == z:
                total += x
            elif x == y or y == z:
                total += 3 * math.gcd(math.gcd(x,y),z)
            else:
                total += 6 * math.gcd(math.gcd(x,y),z)

print(total)


Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin >> n;
    ll a[100050];
    ll sum = 0,amin = 1e12;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        sum += llabs(a[i]);
        amin = min(amin, llabs(a[i]));
    }
    for(int i = 0;i < n-1;i++)
        if(a[i] < 0)a[i] = -a[i],a[i+1] = -a[i+1];
    if(a[n-1] < 0)sum -= amin * 2;
    cout << sum << endl;
}

Measured memory_bytes: 1024
n, k, s = map(int, input().split())
L = [0] * n
for i in range(n):
    if i < k:
        L[i] = s
    else:
        if s != 10 ** 9:
            L[i] = s + 1
        else:
            L[i] = s - 1
print(*L)


Measured memory_bytes: 9676
N = int(input())
A = [int(input()) for _ in range(N)]
A = [(A[i],i) for i in range(N)]
A = sorted(A,key=lambda x:x[0])
cnt = 0
for i in range(N):
    a,j = A[i]
    if (i-j)%2==1:
        cnt += 1
print(cnt//2)

Measured memory_bytes: 89248
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll n,x,t,i,j,l,k;
	cin>>n>>x>>t;
	if(n%x==0)
		k=n/x;
	else
		k=(n/x)+1;
	cout<<k*t<<"\n";
	return 0;
}
	

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  if (2 * N >= M)
    cout << M / 2 << endl;
  if (2 * N < M)
    cout << N + (M - 2 * N) / 4 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int input;
	scanf("%d",&input);
	if(input<1200 && input >=0) printf("ABC\n");
	else if(input<2800 && input >=1200)  printf("ARC\n");
	else if(input>=2800 ) printf("AGC\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SC second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll cnt = 0;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  int l, r ;
  cin >> l >> r ;
  int x = l%2019 ;
  int y = r%2019 ;
  
  int ans = 2020 ;  
  
  if(r-l>=2019){
    ans = 0 ;
  }
  
  if(x>=y){
    y += 2019 ;
  }
  
  FOR(i,x,y){
    FOR(j,i+1,y+1){
      int z = ((i%2019)*(j%2019))%2019 ;
      ans = min(z,ans) ;
      z = 2020 ;
    }
  }
  cout << ans  <<endl;

  return 0 ;
}



Measured memory_bytes: 256
n = int(input())
lst_4 = [x for x in range(4, 101, 4)]
lst_7 = [x for x in range(7, 101, 7)]
lst = []
for i in lst_4:
    for j in lst_7:
        lst.append(i)
        lst.append(j)
        lst.append(i + j)

ans = [x for x in lst if x <= 100]
print('Yes' if n in ans else 'No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<int> p(n);
	int ra[n+1];
	for(int i=0;i<n;i++){
		cin >> p[i];
		ra[p[i]]=i;
	}
	ll ans=0;
	set<int> S;
	S.insert(-1); S.insert(n);
	for(ll d=n;d>=1;d--){
		int i=ra[d];
		auto it=S.lower_bound(i);
		int r=*it;
		it--;
		int l=*it;
		if(r==n&&l==-1){
			S.insert(i);
			continue;
		}
		if(l==-1){
			it++; it++;
			int rr=*it;
			ans+=d*(rr-r)*(i+1);
		}
		else if(r==n){
			it--;
			int ll=*it;
			ans+=d*((l-ll))*(n-i);
		}
		else{
			it--;
			int ll=*it;
			it++;it++;it++;
			int rr=*it;
			ans+=(l-ll)*(r-i)*d;
			ans+=(rr-r)*(i-l)*d;
		}
		S.insert(i);
	}
	cout << ans << endl;
}

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

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

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

    ll gcdr[n], gcdl[n];
    gcdl[0] = a[0];
    gcdr[0] = a[n - 1];

    rep(i, n - 1){
        gcdl[i + 1] = gcd(gcdl[i], a[i + 1]);
    }
    rep(i, n - 1){
        gcdr[i + 1] = gcd(gcdr[i], a[n - i - 2]);
    }

    ll ans = 1;
    rep(i, n - 2){
        ans = max(ans, gcd(gcdl[i], gcdr[n - i - 3]));
    }
    ans = max(gcdl[n - 2], ans);
    ans = max(gcdr[n - 2], ans);
    cout << ans << endl;
}

Measured memory_bytes: 2560
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&d[i])
	}

	sort.Ints(d)

	m := d[(len(d) / 2) - 1]

	for i := len(d) / 2; i < n; i++ {
		if d[i] == m {
			fmt.Println("0")
			return
		}
	}
	count := d[len(d) / 2] - m

	fmt.Println(count)
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mad=1000000007;
ll dp[2005][2005];
int a[2005],b[2005];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    for(int i=1; i<=m; i++)
        scanf("%d",&b[i]);
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
           dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mad;
            if(a[i]==b[j])
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1);


        }
    }

    printf("%lld\n",(dp[n][m]%mad+1+mad)%mad);
    return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m,x;
  cin >> n >> m >> x;
  vector<vector<int>> vec(n,vector<int>(m,0));
  vector<int>c(n);
  
  rep(i,n){
    cin >> c[i];
    rep(j,m) cin >> vec[i][j];
  }
  
  ll ans=INF;
  for(int bit=0;bit<(1<<n);bit++){
    ll res=0;
    vector<int>sum(m,0);
    rep(i,n){
      if(bit &(1<<i)){
        res+=c[i];
        rep(j,m){
          sum[j]+=vec[i][j];
        }
      }
    }
    bool ok=true;
    rep(i,m){
      if(sum[i]<x)ok=false;
    }
    if(ok)ans=min(ans,res);
  }
  if(ans==INF)cout << -1 << endl;
  else cout << ans << endl;
        
  
  return 0;     
}


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

int main(void) {

  double r, a, b;
  scanf("%lf", &r);
  a = r * r * M_PI;
  b = 2 * r * M_PI;
  printf("%.6f %.6f\n", a, b);
 
  return 0;
 
}

Measured memory_bytes: 652
from itertools import*
s,k=open(0)
k,x=int(k),0
g=[len(list(v))for _,v in groupby(s)]
for c in g:x+=c//2
x*=k
if(s[0]==s[-2])*g[0]%2&g[-2]%2:x+=k//2if-len(s)==~g[0]else k-1
print(x)

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

int main()
{
    long long l, r;
    cin >> l >> r;

    if (r - l  >= 2018)
    {
        cout << 0 << endl;
        return 0;
    }

    long long m = 1000000000;

    for (long long i = l; i < r + 1; i++)
    {
        for (long long j = i + 1; j < r + 1; j++)
        {
            long long tmp = ((i % 2019) * (j % 2019)) % 2019;
            if (m > tmp)
            {
                m = tmp;
            }
        }
    }

    cout << m << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();
        final int c = scanner.nextInt();

        System.out.println(c + " " + a + " " + b);
    }
}


Measured memory_bytes: 25428
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,ans=0;
    cin>>n;
    ll b[n+2];
    b[0]=b[n+1]=0;
    set<ll> s;
    set<ll>::iterator itr;
    s.insert(0);
    s.insert(n+1);
    for(int i=1;i<=n;i++){
        cin>>a;
        b[a]=i;
    }
    for(int i=1;i<=n;i++){
        itr=s.lower_bound(b[i]);
        itr--;
        ans+=i*(*(s.lower_bound(b[i]))-b[i])*(b[i]-*itr);
        s.insert(b[i]);
    }
    cout <<ans<<endl;
    return 0;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll solve(ll N) {
    vector<int> d;
    while (N) {
        d.pb(N % 10);
        N /= 10;
    }
    reverse(ALL(d));
    // cerr << d << endl;
    int L = d.size();
    int best = accumulate(ALL(d), 0);
    int s = 0;
    for (int i=0; i<L; ++i) {
        // iの手前まで温存
        // d[i], ...
        // d[i]-1 9 9 9 9 9
        if (d[i] > 0) {
            int nine = s + d[i]-1 + 9*(L-(1+i));
            // printf("%d [%d] 9*%d = %d\n", s, d[i]-1, L-(1+i), nine);
            best = max(best, nine);
        }
        s += d[i];
    }

    return best;
}

int main() {
    ll N; cin >> N;
    cout << solve(N) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int A,B;
  scanf("%d %d",&A,&B);
        
  if( (A*B)%2==1 ){ //A*Bが奇数なら,Cが存在する (C=1 or C=3)
    printf("Yes\n");
  }else{ //A*B が奇数ではない(偶数)なら,Cが存在しない
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1596
/*
ID: Nipun Paul
LANG: C++
PROB: God knows
*/

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

int main()
{
    char a[4];
    cin>>a;
    if(a[0]==a[1] || a[1]==a[2] || a[2]==a[3])
    {
        cout<<"Bad"<<endl;
    }
    else
    {
        cout<<"Good"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n


def lcm(m, n):
    return m // gcd(m, n) * n


a, b = map(int, readline().split())
print(lcm(a,b))

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
from bisect import bisect_right
n=int(input())
X=tuple(map(int,input().split()))
l=int(input())
q=int(input())
D=[[0]*n for _ in range(18)]
for i in range(n):
    D[0][i]=bisect_right(X,X[i]+l)-1
for k in range(1,18):
    for i in range(n):
        D[k][i]=D[k-1][D[k-1][i]]

def query(a,b):
    ret=0
    while True:
        for k in range(18):
            if D[k][a]>=b:
                break
        if k==0:
            ret+=1
            return ret
        k-=1
        ret+=pow(2,k)
        a=D[k][a]

for _ in range(q):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    a-=1; b-=1
    print(query(a,b))

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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> p(n);
  rep(i,n) cin >> p[i].second >> p[i].first;
  sort(p.begin(),p.end());
  ll s = 0;
  rep(i,n){
    s += p[i].second;
    if(s>p[i].first){
      puts("No");
      return 0;
    }
  }
  
  puts("Yes");
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
        int a,b,c,n,i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		scanf("%d",&b);
		scanf("%d",&c);
		if(a<b){
			k=a;
			a=b;
			b=k;
		}
		if(a<c){
			k=a;
			a=c;
			c=k;
		}
		if(a*a==b*b+c*c){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}


Measured memory_bytes: 1984
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

bool b[10000];

Vl frontzero(Vl v){
    reverse(ALL(v));
    v.push_back(0);
    reverse(ALL(v));
    return v;
}

int main() {
    ll n, k; cin >> n >> k;
    Vl p(n+1), c(n+1);
    Rep(i, 1, n) cin >> p[i];
    Rep(i, 1, n) cin >> c[i];

    ll ans = -INF;

    //サイクルに分解
    Rep(i, 1, n){
        if(b[i]) continue;
        ll start = i, now = i;
        Vl v;
        ll cs = 0; // 一周の和
        do{
            b[now] = true;
            v.push_back(c[now]);
            now = p[now];
            cs += c[now];
        }while(now != start);

        if(cs <= 0 || (cs > 0 && k <= sz(v)-1)){
            ll m = min(sz(v)-1, k);
            ll l = sz(v);
            Rep(j, 0, l) v.push_back(v[j]);
            v = frontzero(v);
            rep(j, 1, sz(v)) v[j] += v[j-1];
            rep(j, 0, sz(v)-m){
                Rep(kk, j+1, j+m){
                    ll su = v[kk]-v[j];
                    chmax(ans, su);
                }
            }
        }
        else { // cs >= 0 && k >= sz(v)
            ll m = sz(v);
            Rep(j, 0, m) v.push_back(v[j]);
            v = frontzero(v);
            rep(j, 1, sz(v)) v[j] += v[j-1];
            rep(j, 0, m){
                Rep(kk, j+1, j+m){
                    ll su = v[kk]-v[j];
                    su += cs*((k-(kk-j))/m);
                    chmax(ans, su);
                }
            }
        }
    }

    co(ans);

    return 0;
}
 
 


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int n,k;
int l[55];
int main() {
  int sum;
  cin >> n >> k;
  for(int i(0); i < n; i++)cin >> l[i];
  sort(l, l+n, greater<int>());
  for(int i(0); i < k; i++){
    sum += l[i];
  }
  cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template<class T>
inline void out(T a){cout<<a<<endl; }
inline void out(double a){ printf("%.10f\n", a);} 

ll mod = 1000000007;

ll mmul(ll a, ll b) {
	return ((a % mod) * (b % mod)) % mod;
}

ll mpow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll d = mpow(a, b / 2);
		return (d * d) % mod;
	}
	return (a * mpow(a, b - 1)) % mod;
}

ll mdiv(ll a, ll b) {
	return mmul(a, mpow(b, mod - 2));
}

int main()
{
    ins(s);
    if(s=="Sunny"){
		out("Cloudy");
	}else if(s=="Cloudy"){
		out("Rainy");
	}else{
		out("Sunny");
	}
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;
const lint linf = 0x3f3f3f3f3f3f3f3f;

int n,tar,que[_]={0},he,ta;
lint tim,loc[_],f[_]={0};

int main()
{
	n=ty(),tar=ty(),tim=ty();
	for(int i=1;i<=n;i++)loc[i]=ty();

	lint temp=linf;
	loc[0]=0,he=1,ta=0,que[++ta]=0;
	for(int i=1;i<=n;i++)
	{
		while(he<=ta && 2*(loc[i]-loc[que[he]+1])>tim)
			temp=min(temp,f[que[he]]-loc[que[he]]-2*loc[que[he]+1]),he++;
		f[i]=min(3*loc[i]+temp,tim+f[que[he]]+loc[i]-loc[que[he]]);
		while(he<=ta && f[que[ta]]-loc[que[ta]]>=f[i]-loc[i])ta--;
		que[++ta]=i;
	}

	printf("%lld\n",f[n]+tar-loc[n]);
	
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	int ans = 0;
	int cnt[20] = {};
	int r = 0;
	for(int l = 0; l < n; l++){
		while(r < n){
			bool f = true;
			for(int i = 0; i < 20; i++){
				if(a[r] & (1 << i)){
					if(cnt[i]){
						f = false;
						break;
					}
				}
			}
			if(!f) break;
			for(int i = 0; i < 20; i++){
				if(a[r] & (1 << i)){
					cnt[i]++;
				}
			}
			r++;
		}
		ans += r - l;
		for(int i = 0; i < 20; i++){
			if(a[l] & (1 << i)){
				cnt[i]--;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fill(v, h) memset((v), h, sizeof(v))
using namespace std;
const int MOD = 1000000007;

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

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

int main(void)
{
    string s;
    cin >> s;
    if (s == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int n;
    cin >> n;

    int l[n];
    rep(0, n) cin >> l[i];

    sort(l, l+n);

    int sum = 0;
    rep(0, n-1) sum += l[i];

    cout << (l[n-1] < sum ? "Yes" : "No") << endl;
}

int main() {
    solve();

    return 0;
}


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

int main(){
	int n;
	cin >> n;
	
	vector<ll> h(n);
	rep(i,n) cin >> h[i];
	
	int res = 0;
	int cnt = 0;
	rep(i,n-1){
		
		if(h[i]>= h[i+1]){
			cnt++;
		} else{
			res = max(res,cnt);
			cnt = 0;
		}
	}
	res = max(res,cnt);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define pi pair<long long,long long>
#define mp make_pair
#define mod 1000000007

using namespace std;
string s;
int dp[(int)1.2e5];
int f(int i)
{
    if(dp[i]!=-1)return dp[i];
    if(i==s.length())return 1;
    string a="dreamer",b="eraser";

   // cout<<i<<endl;

    int k=i,j,ans=0;
    //dream
    for( j=0;j<=4;++j)
    {
      if(k==s.length())break;
      if(s[k]==a[j])
            ++k;
      else break;
    }
    if(j==5)ans=ans|f(i+5);
   // cout<<j<<endl;

    k=i;
    for( j=0;j<=6;++j)
    {
      if(k==s.length())break;
      if(s[k]==a[j])
            ++k;
      else break;
    }
    if(j==7)ans=ans|f(i+7);

   // cout<<j<<endl;

    k=i;
    for( j=0;j<=4;++j)
    {
      if(k==s.length())break;
      if(s[k]==b[j])
            ++k;
      else break;
    }

    if(j==5)ans=ans|f(i+5);
       // cout<<j<<endl;

        k=i;
    for( j=0;j<=5;++j)
    {
      if(k==s.length())break;
      if(s[k]==b[j])
            ++k;
      else break;
    }
    if(j==6)ans=ans|f(i+6);
//cout<<j<<endl;

    return dp[i]= ans;

}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
for(int i=0;i<=1.1e5;++i)dp[i]=-1;
    cin>>s;
   if(f(0)==1)cout<<"YES";
   else cout<<"NO";
    return 0;
}


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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 200005;

int n;
int a[N];
int cnt[N];

int main() {
    scanf("%d", &n);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        ans += cnt[a[i]];
        cnt[a[i]]++;
    }
    
    for (int i = 1; i <= n; i++) {
        printf("%lld\n", ans - (cnt[a[i]] - 1));
    }

    return 0;
}


Measured memory_bytes: 3712
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 3005;

pair<int,int> a[N];
int n, t;
int dp[N][N];

int f(int i, int time) {
	if(time >= t) return 0;
	if(i >= n) return 0;
	if(dp[i][time] != -1) return dp[i][time];
	int ret = 0;
	ret = max(ret, f(i+1, time));
	ret = max(ret, f(i+1, time + a[i].first) + a[i].second);
	return dp[i][time]=ret;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) dp[i][j]=-1;
	cin >> n >> t;
	for(int i=0;i<n;i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a+n);
	int ret = 0;
	for(int i=0;i<n;i++)ret=max(ret, f(i, 0));
	cout << ret;
	return 0;
}


Measured memory_bytes: 71040
X, Y, A, B, C = map(int, input().split())
P = list(sorted(map(int, input().split()), reverse=True))
Q = list(sorted(map(int, input().split()), reverse=True))
R = list(sorted(map(int, input().split()), reverse=True))

S = P[:X] + Q[:Y]
S.sort(reverse=True)
S_wa = []
wa = 0
for s in S[::-1]:
    wa += s
    S_wa.append(wa)
big = S_wa[-1]
ans = S_wa[-1]

R_wa = []
wa = 0
for r in R:
    wa += r
    R_wa.append(wa)

for i in range(min(X + Y, C)):
    ans = max(ans, big + R_wa[i] - S_wa[i])
print(ans)


Measured memory_bytes: 112552
// by syu
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var in = NewScanner(os.Stdin, 0)

func main() {
	N, i := in.Int(), in.Int()
	Pln(N - i + 1)
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for start < len(data) && isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func Pln(s ...interface{}) {
	fmt.Println(s...)
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
      	int m = sc.nextInt();
      	int[] a = new int[n];
      	int[] b = new int[n];
      	int[] c = new int[m];
      	int[] d = new int[m];
      	
      	for(int i = 0; i < n; i++){
        	a[i] = sc.nextInt();
          	b[i] = sc.nextInt();
        }
      	for(int i = 0; i < m; i++){
        	c[i] = sc.nextInt();
          	d[i] = sc.nextInt();
        }
      
      	for(int i = 0; i < n; i++){
        	int min = Math.abs(a[i]-c[0]) + Math.abs(b[i]-d[0]);
          	int check = 1;
          	for(int j = 1; j < m; j++){
            	int dist = Math.abs(a[i]-c[j]) + Math.abs(b[i]-d[j]);
              	if(min > dist){
                	min = dist;
                  	check = j + 1;
                }
            }
          	System.out.println(check);
        }
	}
}

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

// tgt より低い要素数を返す
// (例) tgt = 4, list = [0, 1, 2, 3, 4, 5]ならば、4を返す
long long bs_lower(long long tgt, const vector<long long> &list){

    long long left=0, right=list.size();
    long long mid = 0;
    
    while(left<right){
        mid = (left+right)/2;
        if(list[mid]<tgt) left = mid+1;
        if(list[mid]>=tgt) right = mid;
    }

    return (left+right)/2;

}

// tgtより高い要素数を返す
// (例)tgt = 4, list = [0, 1, 2, 3, 4, 5]ならば、1を返す。
long long bs_upper(long long tgt, const vector<long long> &list){
    
    long long left=0, right=list.size();
    long long mid = 0;

    while(left<right){
        mid = (left+right)/2;
        if(list[mid]>tgt) left = mid+1;
        if(list[mid]<=tgt) right = mid;
    }
    return (left+right)/2;

}

int main(){

    // test
    // vector<long long> M{0, 1, 2, 3, 4, 4, 5};
    // cout << bs_lower(6, M) << endl;

    // O(N)
    long long N; cin>>N;
    vector<long long> A(N), B(N), C(N);
    for (long long n=0; n<N; n++) cin>>A[n];
    for (long long n=0; n<N; n++) cin>>B[n];
    for (long long n=0; n<N; n++) cin>>C[n];

    // O(NlogN)
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());

    // O(N) * O(logN)
    long long ans = 0;
    for (long long n=0; n<N; n++){
        
        long long A_lower = bs_lower(B[n], A);
        long long C_upper = bs_upper(B[n], C);

        ans += A_lower * C_upper;

    }

    cout<<ans<<endl;
    
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;



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

    int h,w;
    cin >> h >> w;

    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;

    pair<int,int> s = make_pair(sx,sy), g = make_pair(gx,gy); 
    vector<vector<int>> ans(h,vector<int>(w,mod));
    string sur[h];

    for(int i = 0; i < h; i++) cin >> sur[i];

    auto inout = [&](int x,int y){
        if(0 <= x && x < w && 0 <= y && y < h) return true;
        else return false;
    };

    auto add = [&](pair<int,int> now,int dx,int dy){
        pair<int,int> ret = make_pair(now.first+dx,now.second+dy);
        return ret;
    };

    queue<pair<int,int>> p,q;

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

    p.push(s);
    ans[s.second][s.first] = 0;

    int can = 0;

    while(!p.empty()){
        while(!p.empty()){
            pair<int,int> now = p.front();
            p.pop();
            q.push(now);
            bool first = true;
            for(int i = 0; i < 4; i++){
                pair<int,int> nxt = add(now,dx[i],dy[i]);
                if(inout(nxt.first,nxt.second)){
                    if(sur[nxt.second][nxt.first] == '.'){
                        ans[nxt.second][nxt.first] = can;
                        if(nxt == g){
                            cout << ans[nxt.second][nxt.first] << endl;
                            return 0;
                        }
                        p.push(nxt);
                        sur[nxt.second][nxt.first] = '#';
                    }
                }
            }
        }
        can++;
        while(!q.empty()){
            pair<int,int> now = q.front();
            q.pop();
            for(int i = -2; i < 3; i++){
                for(int j = -2; j < 3; j++){
                    pair<int,int> nxt = make_pair(now.first+i,now.second+j);
                    if(inout(nxt.first,nxt.second)){
                        if(sur[nxt.second][nxt.first] == '.'){
                            ans[nxt.second][nxt.first] = can;
                            p.push(nxt);
                            sur[nxt.second][nxt.first] = '#';
                            if(nxt == g){
                                cout << ans[nxt.second][nxt.first] << endl;
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    int n,k;cin >> n >> k;
    vector<int> a(n),c(n,1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n - k; i++) {
        c[i] = 0;
    }
    LL ans = LINF;
    do{
        LL t = 0, now = a[0];
        for (int i = 1; i < n; i++) {
            if(c[i]){
                if(now < a[i]){
                    now = a[i];
                }
                else{
                    now++;
                    t += now - a[i];
                }
            }
            else{
                if(now < a[i]) now = a[i];
            }
        }
        ans = min(ans, t);
    }while(next_permutation(ALL(c)));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
////////////////////////////////////////////////
int main()
{
	int x,a,b;cin>>x>>a>>b;
	cout<<(x-a)%b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll res = 0;
    ll subsum = 0;
    rep(i, n){
        if(a[i]) subsum += a[i];
        else{
            res += subsum/2;
            subsum = 0;
        }
    }
    if(subsum) res += subsum/2;

    cout << res << endl;

    return 0;
}

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

int functione(int num[], int N);

int main()
{
	int n;
	cin >> n;
	int *num = new int [n];

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

	cout << functione(num, n) << endl;
	return 0;
}

int functione(int num[], int N)
{
	int max = -2000000000;
	int min = num[0];
	for(int i = 1; i<N; i++)
	{
		if(max<num[i]-min)
			max = num[i]-min;
		if(min > num[i])
			min = num[i];
	}
	return max;
}

Measured memory_bytes: 1960
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
prev = -1
for a in A:
    ans += B[a - 1]
    if prev == a - 1:
        ans += C[prev - 1]
    prev = a
print(ans)


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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop freopen(filename ".cik","w",stdout);freopen(filename ".gir","r",stdin)
const int N = ((int)1e5) + 5;
const int M = ((int)1e3) + 5;
typedef long long int lli;

int n;
vector<pair<int,int> > v;

bool cmp (pair<int,int> a, pair<int,int> b)
{
	return a.second < b.second;
}

int main ()
{
	fast;
	//freop;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		v.pb(mp(i,a));
	}
	sort(v.begin(),v.end(),cmp);
	for (auto i : v)
		cout << i.first << " ";
	cout << "\n";
}


Measured memory_bytes: 1780
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

char ch[1000010];

int n;

int main() {
    scanf("%s", ch + 1), n = strlen(ch + 1);
    ll ans = 0, t = 1;
    for(int i = 1; i <= n; i++)
        if(ch[i] == 'W') ans += i - t++;
    printf("%lld\n", ans);
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

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

	int pt = 0, px = 0, py = 0;

	rep(i, n) {
		int t, x, y;
		cin >> t >> x >> y;
		const int need = abs(px - x) + abs(py - y);

		if (need > (t - pt) or need % 2 != (t - pt) % 2 ) {
			puts("No");
			return 0;
		}
		pt = t, px = x, py = y;
	}

	puts("Yes");
	return 0;
}

Measured memory_bytes: 256