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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 998244353;

    constexpr unsigned long mx = 1000001;
    vector<vector<unsigned long>> fact(mx, {1});
    for(unsigned long i = 2; i < mx; ++i)for(unsigned long j = i; j < mx; j += i)fact[j].push_back(i);

    vector<unsigned long> inv(mx, 1);
    for(unsigned long i = 2; i < mx; ++i)inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;

    vector<unsigned long> coef(mx, 1), sieve(mx, 1);
    for(unsigned long i = 2; i < mx; ++i)if(sieve[i])for(unsigned long j = i; j < mx; j += i){
        sieve[j] = 0;
        (coef[j] *= MOD + 1 - i) %= MOD;
    }

    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    copy_n(istream_iterator<unsigned long>(cin), N, A.begin());

    vector<unsigned long> hoge(mx);
    for(const auto& i : A)for(const auto& j : fact[i])hoge[j] += i;
    for(auto& i : hoge)i %= MOD;

    unsigned long ans{MOD - accumulate(A.begin(), A.end(), 0UL) % MOD};
    for(unsigned long i = 1; i < mx; ++i)if(hoge[i])ans += inv[i] * coef[i] % MOD * hoge[i] % MOD * hoge[i] % MOD;
    ans %= MOD;
    (ans += MOD * (ans & 1)) >>= 1;
    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    int N, K; cin >> N >> K;
    vector<int> h(N);

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

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

    int res = 1000000001;
    for (int i = 0; i <= N - K; i++) {
        res = min(res, abs(h[i] - h[i+K-1]));
    }

    cout << res << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//



     signed main(){
  int d;
  clock_t st=clock();
  cin>>d;
    clock_t ed=clock();

  int c[26];
  for(int i=0;i<26;i++)cin>>c[i];
  int t[d],s[d][26],x[26]={};
    vector<int>v[26];
    for(int i=0;i<26;i++)v[i].push_back(-1);

  for(int i=0;i<d;i++)for(int j=0;j<26;j++)cin>>s[i][j];
   // cerr<<'i';
  for(int i=0;i<d;i++){
      for(int j=0;j<26;j++)x[j]+=c[j];
      int k=0;
      for(int j=1;j<26;j++)if(x[k]+s[i][k]<x[j]+s[i][j])k=j;
      t[i]=k;
      x[k]=0;
      v[k].push_back(i);
  }
  for(int i=0;i<26;i++)v[i].push_back(d);
//for(int i=0;i<d;i++)cout<<t[i]+1<<endl;
  // cerr<<double(clock()-st)/CLOCKS_PER_SEC<<endl;
while(double(clock()-st)/CLOCKS_PER_SEC<1.90){
    int p=rand()%d;
    auto q=find(v[t[p]].begin(),v[t[p]].end(),p);
    q++;
  // int m=(p+(*q))/2;
   int m=p+rand()%((*q)-p);
//cerr<<m<<' '<<p<<endl;
   if(m==p)continue;
   auto r1=find(v[t[m]].begin(),v[t[m]].end(),m);
   auto r0=r1-1,r2=r1+1;
   if((m-p)*((*q)-m)*c[t[p]]+s[m][t[p]]>(m-(*r0))*((*r2)-m)*c[t[m]]+s[m][t[m]]){
 
    v[t[p]].insert(q,m);
    v[t[m]].erase(r1);
    t[m]=t[p];
   }




}
     for(int i=0;i<d;i++)cout<<t[i]+1<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 3740
N,Y = map(int,input().split())
Y = int(Y/1000)
a = b = c = 0
flag = True
for a in range(int(Y//10)+1):
  for b in range(int((Y-10*a)//5)+1):
    c = Y-10*a-5*b
    if a+b+c == N and flag:
      flag = False
      print(a,b,c)
if flag:
  print(-1,-1,-1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 1;										/* デバッグプリント 提出時は0 */

int main()
{

	int		N,K;

	scanf("%d %d", &N, &K);
	printf("%d\n",N-K+1);

	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
int N,M;
 
int p[100001];
bool x[100001];

int f(int i){
	if(i==p[i]){
		return i;
	}else{
		return p[i]=f(p[i]);
	}
}
 
main(){
	scanf("%d%d",&N,&M);
	for(int i=1;i<=M;++i){
		p[i]=i;
	}
	for(int i=0;i<N;++i){
		int K,L0;
		scanf("%d%d",&K,&L0);
		x[L0]=true;
		for(int i=1;i<K;++i){
			int L;
			scanf("%d",&L);
			x[L]=true;
			if(f(L0)!=f(L)){
				p[f(L)]=f(L0);
			}
		}
	}
	int a=0;
	for(int i=1;i<=M;++i){
		if(x[i]){
			if(a==0){
				a=f(i);
			}else{
				if(f(i)!=a){
					puts("NO");
					return 0;
				}
			}
		}
	}
	puts("YES");
}

Measured memory_bytes: 768
from collections import deque
n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])
x = deque([])
mn = 10**9
for i in h:
    x.append(i)
    if len(x) >= k:
        mn = min(mn,x[k-1]-x[0])
        x.popleft()
print(mn)

Measured memory_bytes: 8628
#include<stdio.h>
#include<string.h>
int max(int x,int y)
{
    return x>y ? x:y;
}
int min(int x,int y)
{
    return x<y ? x:y;
}
int main()
{
    char ch[100010];
    while(scanf("%s",ch)!=EOF)
    {
        int len=strlen(ch);
        int ans=len;
        for(int i=1;i<=len-1;i++)
        {
            if(ch[i]!=ch[i-1])
                ans=min(ans,max(i,len-i));
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v1(n/2), v2(n/2);
    for(size_t i = 0; i < n; i++)
    {
        if(i%2==0)
            cin >> v1[i/2];
        else
            cin >> v2[(i-1)/2];
    }
    map<int, int> v1map;
    map<int, int> v2map;
    for(size_t i = 0; i < n/2; i++)
    {
        v1map[v1[i]] += 1;
        v2map[v2[i]] += 1;
    }
    auto itv1max = v1map.end();
    auto itv1sec = v1map.end();
    auto itv2max = v2map.end();
    auto itv2sec = v2map.end();
    int v1max(0),v1sec(0),v2max(0),v2sec(0);
    for(auto it = v1map.begin(); it!=v1map.end(); it = next(it, 1)){
        if(it->second > v1max){
            itv1sec = itv1max;
            itv1max = it;
            v1sec = v1max;
            v1max = it->second;
        }
        else if(it->second > v1sec){
            itv1sec = it;
            v1sec = it->second;
        }
    }
    for(auto it = v2map.begin(); it!=v2map.end(); it = next(it, 1)){
        if(it->second > v2max){
            itv2sec = itv2max;
            itv2max = it;
            v2sec = v2max;
            v2max = it->second;
        }
        else if(it->second > v2sec){
            itv2sec = it;
            v2sec = it->second;
        }
    }
    if (itv1max->first != itv2max->first){
        cout << n - v1max - v2max << endl;
    }
    else{
        if (v1sec > v2sec)
            cout << n - v1sec - v2max << endl;
        else
            cout << n - v1max - v2sec << endl;
    }
    return 0;
}

Measured memory_bytes: 5376
N = int(input())
if N == 1:
    print(0)
    exit()
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
ans = 0
l = factorization(N)
for i,j in l:
    k = 1
    while j >= k:
        ans += 1
        j -= k
        k += 1
print(ans)

Measured memory_bytes: 9420
#include <iostream>

using namespace std;

int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  int t = 0;
  while (true) {
    if (s[t].size() == 0) {
      cout << static_cast<char>(t + 'A') << endl;
      return 0;
    }
    int n = s[t][0] - 'a';
    s[t] = s[t].substr(1, s[t].size() - 1);
    t = n;
  }
}


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

int main()
{
	int x; cin>>x;
	if(x>=30) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int solve(){
  int n;
  cin >> n;
  int odd = 0;
  rep(i,n){
    int tmp;
    cin >> tmp;
    if(tmp % 2 != 0)odd++;
  }
  if(odd % 2 == 0)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 


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

int main(int argc, char *argv[])
{
    int n, d;
    int x[10][10];
    int ans;

    std::cin >> n >> d;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            std::cin >> x[i][j];
        }
    }

    ans = 0;

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            int sum = 0;
            for (int k = 0; k < d; k++) {
                sum += std::pow(x[i][k] - x[j][k], 2);
            }
            if (sum == std::pow(std::floor(std::sqrt(sum)), 2)) {
                ans++;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int main(){
  int cnt = 0,n;

  cin >> n;
  
  int *a = new int[n];

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

  bool flag = false;
  int minj;
  for(int i=0;i<n;++i){
    flag = false;
    minj = i;
    for(int j=i+1;j<n;++j){
      if(a[j] < a[minj]){
	minj = j;
	flag = true;
      }
    }
    swap(a[i],a[minj]);
    if(flag) ++cnt;
  }

  for(int i=0;i<n;++i){
    cout << a[i];
    if(i != n-1) cout << " ";
  }
  cout << endl << cnt << endl;
  
  delete[] a;
  return 0;
}



Measured memory_bytes: 3092
N,A,B,C,D=map(int,input().split())
x=N//A
y=N//C
if N<=A*x:
    if N<=C*y:
        if B*x<=D*y:
            print(B*x)
        else:
            print(D*y)
    else:
        if B*x<=D*(y+1):
            print(B*x)
        else:
            print(D*(y+1))
else:
    if N<=C*y:
        if B*(x+1)<=D*y:
            print(B*(x+1))
        else:
            print(D*y)
    else:
        if B*(x+1)<=D*(y+1):
            print(B*(x+1))
        else:
            print(D*(y+1))


Measured memory_bytes: 5596
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()

	if a * b % 2 == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
}

Measured memory_bytes: 640
package main

import (
	"container/heap"
	"fmt"
)

func main() {
	var n, tmp int
	fmt.Scan(&n)

	// v := make([]Job, n)
	pq := new(PriorityQueue)

	for i:=0; i< n; i++ {
		fmt.Scan(&tmp)
		// v[i].A = tmp
		heap.Push(pq, Job{A:tmp})
	}

	for i:= 0; i<n/2-1; i++ {
		heap.Pop(pq)
	}
	a := heap.Pop(pq).(Job)
	b := heap.Pop(pq).(Job)

	fmt.Println(b.A-a.A)

}
type Job struct {
	A int
}

// -----------------------------------------------------------------------------

type PriorityQueue []Job

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].A < pq[j].A
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	old := *pq
	*pq = append(old, x.(Job))
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old) - 1
	x := old[n]
	*pq = old[:n]
	return x
}

Measured memory_bytes: 5504
from collections import deque
n=int(input())
dl=deque(sorted(list(map(int,input().split()))))
m=int(input())
tl=deque(sorted(list(map(int,input().split()))))
while tl:
    t=tl.popleft()
    while(dl):
        d=dl.popleft()
        if t==d:
            break
    else:
        break
else:
    print('YES')
    exit()
print('NO')

Measured memory_bytes: 36200
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

//#define int long long

using namespace std;

void Main()
{
	string s, t;
	int a, b;
	string u;
	cin >> s >> t >> a >> b >> u;

	if (u == s) {
		a--;
	}
	else {
		b--;
	}
	cout << a << " " << b << endl;
}

int32_t main()
{
	Main();
	return 0;
}



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

void printArray(int* A, int N){
  for (int i = 0; i < N; i++) {
    std::cout << A[i];
    if (i!=N-1) {
      std::cout << " ";
    }
  }
  std::cout <<'\n';
}


void selectionSort(int* A, int n){
  int min_j;
  int cnt=0;
  for (int i = 0; i < n; i++) { // A[i] 以降で最小のものを探し, A[i]とswap
    min_j = i;
    for (int j = i; j < n; j++) {
      if (A[j] < A[min_j]) {
        min_j = j;
      }
    }
    if(i!=min_j){
      std::swap(A[min_j], A[i]);
      cnt++;
    }
  }
  printArray(A,n);
  std::cout << cnt << '\n';
}


int main() {
  int n;
  std::cin >> n;
  int* A = new int[n];
  for (int i = 0; i < n; i++) {
    std::cin >> A[i];
  }
  selectionSort(A, n);
  return 0;
}



Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b) {
  int* A = (int*) a;
  int* B = (int*) b;
  
  return
    *A < *B ? -1 :
    *A > *B ? 1 :
    /* else */ 0;
}
#define abs(x) (x < 0 ? -x : x)
int GCM(int x, int y) {
  int z = x % y;
  if (z == 0) return y;
  return GCM(y, z);
}
int main() {
  int N;
  scanf("%d", &N);
  ++N;
  
  int x[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", x + i);
  }
  
  qsort(x, N, sizeof(int), compare_int);
    
  int gcm = x[1] - x[0];
  for (int i = 1; i < N - 1; ++i) {
    gcm = GCM(gcm, x[i + 1] - x[i]);
  }
  printf("%d\n", gcm);
  return 0;
}

Measured memory_bytes: 892
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int x;
    cin >> x;
    if (x >= 30) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
const long double PI=(acos(-1));
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  int vec[n];
  rep(i,n){
    cin>>vec[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans+=vec[i]*vec[j];
    }
  }
  cout<<ans<<endl;
}

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

int main()
{
	long long N,i,j,l;
	char S[1000000],a[1000000];
	while(cin>>N>>S)
	{
		a[0]=S[0];
		for(i=1,j=1;S[j]!='\0';j++)
		{
		    if(a[i-1]==S[j]){
				continue;
			}
			else{
				a[i]=S[j];
				i++;
			}
		}
		l=strlen(a);
		cout<<l<<endl;
		for(i=0;i<l;i++)
		{
			a[i]='\0';
		}
	}
}

Measured memory_bytes: 512
import numpy as np


def main():
    n, m = map(int, input().split())
    ac = np.array([0] * n)
    pena = np.array([0] * n)
    # 
    for _ in range(m):
        p, s = map(str, input().split())
        p = int(p) - 1
        if ac[p] == 0 and s == 'WA':
            pena[p] += 1
        else:
            ac[p] = 1
    print(sum(ac), sum(ac * pena))


if __name__ == '__main__':
    main()

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

#define fi first
#define se second
#define endl '\n'
#define lc (rt<<1)
#define rc (rt<<1|1)
#define mp make_pair
#define pb push_back
#define lowbit(a) (a&(-a))
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define mst(a,v) memset(a,v,sizeof(a))
#define debug(x) cout<<#x": "<<x<<'\n';
#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

const int N=1010;
const int mod=1e9+7;
const ld PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

template<typename T>inline void gmax(T &A,T B)
{
    (A<B)&&(A=B);
}
template<typename T>inline void gmin(T &A,T B)
{
    (A>B)&&(A=B);
}

template <class T>
inline bool re(T &ret)
{
    char c;
    int sgn;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}

char g[N][N];
int dp[N][N];

int main()
{
#ifdef local
    //freopen("in.txt", "r", stdin);
#endif
    IOS;
    int n,m;
    cin>>n>>m;
    for(int i=1; i<=n; i++) cin>>(g[i]+1);
    dp[1][1]=1;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            if(i==1&&j==1) continue;
            if(g[i][j]=='.')
            {
                dp[i][j]=dp[i-1][j]+dp[i][j-1];
                if(dp[i][j]>=mod) dp[i][j]-=mod;
            }
        }
    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 5248
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Card A[] = new Card[n];
		for(int i=0; i<n; i++){
			A[i] = new Card();
			A[i].pic = sc.next();
			A[i].num = sc.nextInt();
			A[i].idx = i;
		}
		quicksort(A, 0, n-1);

		int flg=0, off;
		int I[] = new int[4];
		for(int i=0; i<n; i+=off){
			I[0] = A[i].idx;
			off = 1;
			while(i+off<n && A[i].num==A[i+off].num){
				I[off] = A[i+off].idx;
				off++;
			}
			if(off != 1){
				for(int j=0; j<off-1; j++){
					for(int k=j+1; k<off; k++){
						if(I[j] > I[k]){
							flg = 1;
							break;
						}
					}
					if(flg == 1) break;
				}
			}
			if(flg == 1) break;
		}
		if(flg == 0) System.out.println("Stable");
		else         System.out.println("Not stable");
		for(int i=0; i<n; i++){
			System.out.println(A[i].pic+" "+A[i].num);
		}
	}
	static void quicksort(Card A[], int p, int r){
		if(p < r){
			int q = partition(A, p, r);
			quicksort(A, p, q-1);
			quicksort(A, q+1, r);
		}
	}
	static int partition(Card A[], int p, int r){
		Card work;
		int i = p-1;
		for(int j=p; j<=r-1; j++){
			if(A[j].num <= A[r].num){
				i++;
				work = A[i];
				A[i] = A[j];
				A[j] = work;
			}
		}
		i++;
		work = A[i];
		A[i] = A[r];
		A[r] = work;
		return i;
	}
}
class Card{
	String pic;
	int num;
	int idx;
}

Measured memory_bytes: 97948
#include<iostream>
#define PP std::pair<int,int>
int n,m,a;
int map[101][1010];
int main(){
    while(true){
        std::cin>>n>>m>>a;
        if(n==0)break;
        for(int i=0;i<101;i++){
            for(int j=0;j<1010;j++){
                map[i][j]=0;
            }
        }
        for(int i=0;i<m;i++){
            int h,p,q;
            std::cin>>h>>p>>q;
            map[p][h]=q;
            map[q][h]=p;
        }
        for(int i=1000;i>=1;i--){
            if(map[a][i])a=map[a][i];
        }
        std::cout<<a<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    string S;
    cin >> S;
    for(int i=0;i<S.size();i+=2){
        if(S[i]=='L'){
            GOODBYE;
        }
    }
    for(int i=1;i<S.size();i+=2){
        if(S[i]=='R'){
            GOODBYE;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 
 
    long long n;
    cin >> n;
    long long a[n+1];
    for(int i=1; i<=n; i++) cin >> a[i];
    sort(a+1, a+n+1);
    for(int i=2; i<=n; i++)
    {
        if(a[i]==a[i-1])
        {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    C[i], S[i], F[i] = map(int,input().split())

for i in range(N):
    t = 0
    for j in range(i,N - 1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t = t + F[j] - (t % F[j])
        t += C[j]
    print(t)

Measured memory_bytes: 9076
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		int firstNumber = input.nextInt();
		int[] firstList = new int[firstNumber];

		for (int i = 0; i < firstNumber; i++)
			firstList[i] = input.nextInt();

		int secondNumber = input.nextInt();
		int[] secondList = new int[secondNumber];

		for (int i = 0; i < secondNumber; i++)
			secondList[i] = input.nextInt();

		System.out.println(find(firstList, secondList));

	}

	public static int find(int[] first, int[] second) {
		int sameNumber = 0;
		ArrayList<Integer> alreadyAppear = new ArrayList<>();
		boolean appear = false;

		for (int i = 0; i < first.length; i++) {
			for (int j = 0; j < second.length; j++) {
				if (first[i] == second[j]) {
					for (int k = 0; k < alreadyAppear.size(); k++) {
						if (first[i] == alreadyAppear.get(k))
							appear = true;

					}

					if (!appear) {
						sameNumber++;
						alreadyAppear.add(first[i]);
						break;
					}
				}
			}

			appear = false;
		}

		return sameNumber;
	}

}

Measured memory_bytes: 40620
import java.util.*;
class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	int[]a=new int[3];
	for(int i=0;i<3;i++)a[i]=sc.nextInt();
	for(int i=0;i<2;i++){
	    int min=i;
	    for(int j=i;j<3;j++){
		if(a[min]>a[j]){
		    int c=a[min];
		    a[min]=a[j];
		    a[j]=c;
		}
	    }
	}
	for(int i=0;i<2;i++)System.out.print(a[i]+" ");
	System.out.println(a[2]);
    }
    public static void main(String[]ag){
	new Main().main();
    }
}

Measured memory_bytes: 26300
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
const long long mod=1e9+7;
int main(void){
    string S,T;
    cin>>S>>T;
    bool flag=true;
    
    vector<pair<char,char>> a(S.size()),b(S.size());
    for(int i=0;i<S.size();i++){
         a.at(i)=make_pair(S.at(i),T.at(i));
         b.at(i)=make_pair(T.at(i),S.at(i));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int j=0;
    for(int i=0;i<S.size();i++){
        char c1=a.at(i).first;
        char c2=a.at(i).second;
        j=i;
        while(j<S.size()&&c1==a.at(j).first){
             if(c2!=a.at(j).second){
                 flag=false;
             }
             j++;
             if(j>=S.size())break;
        }
        i+=j-i-1;
    }
    for(int i=0;i<S.size();i++){
        char c1=b.at(i).first;
        char c2=b.at(i).second;
        j=i;
        while(j<S.size()&&c1==b.at(j).first){
             if(c2!=b.at(j).second){
                 flag=false;
             }
             j++;
        }
        i+=j-i-1;
    }
if(flag)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 1544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
void Main(){
    int N;cin>>N;
    vector<int> A(N),S(100010,0);
    For(i,0,N) cin>>A[i];
    For(i,0,N){
        S[A[i]]++;
        S[A[i]+1]++;
        S[A[i]+2]++;
    }
    int ans=0;
    For(i,0,100001) ans=max(ans,S[i]);
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	Int temp = (N + 1) / 2;
	long double ans = (long double)temp / N;

	cout << ans << "\n";
}

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

int main(){
  int n; cin >> n;
  vector<double> x(n), y(n);
  for(int i = 0; i < n; i++){
  	cin >> x[i] >> y[i];
  }
  
  vector<vector<double>> p(n, vector<double>(n));
  
  for(int i = 0; i < n; i++){
  for(int j = 0; j < n; j++){
  
    double xx = x[i] - x[j]; double yy = y[i] - y[j];
    xx = xx*xx; yy = yy*yy;
  	p[i][j] = sqrt(xx + yy);
  }
  }
  
  double ans = 0;
  double m = 1;
  for(int i = 1; i < n; i++) m *= i;
  
  for(int i = 0; i < n; i++){
  for(int j = 0; j < n; j++){
  
  	ans += p[i][j]*m;
  }
  }
  int N = 1;
  for(int i = 1; i <= n; i++) N *= i;
  
  cout << fixed << setprecision(10);
  cout << ans/N << endl;
} 

Measured memory_bytes: 256
dx = [[0, 1, 0, -1, 0], [1, 1, -1, -1], [2, 0, -2, 0]]
dy = [[0, 0, 1, 0, -1], [-1, 1, 1, -1], [0, 2, 0, -2]]
a = [[0 for i in range(14)] for j in range(14)]
try:
    while True:
        x, y, s = map(int, raw_input().split(','))
        x += 2
        y += 2
        for i in range(s):
            for j in range(len(dx[i])):
                a[x + dx[i][j]][y + dy[i][j]] += 1
except:
    pass
ct = mx = 0
for b in a[2:-2]:
    for p in b[2:-2]:
        mx = max(mx, p)
        if p == 0:
            ct += 1
print ct
print mx

Measured memory_bytes: 4272
const main = input =>{
    const IN = parseInt(input);
    count = 0;
    result =0;
    for(var i=1; i<=IN; i++){
        if(i % 2 !==0){
            count++;
        }
    }
    console.log(count/IN);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21956
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
cnt = 0
for i in range(n):
    b[i] = abs(a[i])
    if a[i] < 0:
        cnt += 1
if cnt % 2 == 0:
    print(sum(b))
else:
    print(str(sum(b) - 2 * min(b)))


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

int n, m, a[333];

int main(void) {
  scanf("%d%d", &n, &m);
  if(m == 1) {
    if(n == 1) {
      printf("1\n1\n1\n");
    } else {
      printf("%d\n2\n1 %d\n", n, n - 1);
    }
    return 0;
  }
  int cnt = 0;
  for(int i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    cnt += a[i] & 1;
  }
  if(cnt > 2) {
    return puts("Impossible"), 0;
  }
  for(int i = 2; i <= m; i++) {
    if(a[i] & 1) {
      if(~a[1] & 1) {
	swap(a[1], a[i]);
      } else {
	swap(a[m], a[i]);
      }
    }
  }
  for(int i = 1; i <= m; i++) {
    printf("%d%c", a[i], i == m ? '\n' : ' ');
  }
  int i = 1;
  if(a[1] == 1) {
    i++;
  }
  printf("%d\n", m - i + 1);
  for(; i < m; i++) {
    printf("%d ", i == 1 ? a[i] - 1 : a[i]);
  }
  printf("%d\n", a[m] + 1);
  return 0;
}


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

int main() {
	int H, W, D;
	cin >> H >> W >> D;
	vector<int> px(H*W+1), py(H*W+1);
	for(int i=0;i<H;i++) {
		for(int j=0;j<W;j++) {
			int a;
			cin >> a;
			px[a] = i;
			py[a] = j;
		}
	}
	// 累積和
	vector<int> wa(H*W+1, 0);
	for(int i=1;i<=H*W;i++) {
		if(i+D <= H*W) wa[i+D] = wa[i] + (abs(px[i] - px[i+D]) + abs(py[i] - py[i+D]));
	}
	int Q;
	cin >> Q;
	for(int i=0;i<Q;i++) {
		int l, r;
		cin >> l >> r;
		cout << wa[r] - wa[l] << endl;
	}
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int N;

  string s = "";

  cin >> N;

  for (int i = 1; i <= N; ++i) {
    s += to_string(i);
  }

  string p = "";

  for (int i = 0; i < N; ++i) {
    int pi;
    cin >> pi;

    p += to_string(pi);
  }

  string q = "";

  for (int i = 0; i < N; ++i) {
    int qi;
    cin >> qi;

    q += to_string(qi);
  }

  bool found_p = false;
  bool found_q = false;

  int pnum = 1;
  int pnum_p = -1;
  int pnum_q = -1;
  while (!found_p || !found_q) {
    if (s == p) {
      found_p = true;
      pnum_p = pnum;
    }

    if (s == q) {
      found_q = true;
      pnum_q = pnum;
    }
    
    next_permutation(s.begin(), s.end());
    pnum++;
  }

  cout << abs(pnum_p-pnum_q) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int a[25][25];
ll dp[30][(1<<21)+1];
ll F(int M ,int W,int n)
{
    if(M==n){
        return 1;
    }
        
    
    if(dp[M][W]!=-1)
        return dp[M][W];
    
    ll ans =0;
   
    for(int i=0;i<n;i++){
        if(W & (1<<i) && a[M][i]==1){
            ans +=(F(M+1,W^(1<<i),n))%MOD;
            ans%=MOD;
        }
    }

    return dp[M][W] = ans;
    

}
int main()
{
    int n;
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];
//cout<<((1<<n)-1)<<endl;


    cout<<F(0,(1<<n) -1,n);

    return 0;
}

Measured memory_bytes: 495168
#include<bits/stdc++.h>
#define ll long long

using namespace std;

ll n,k,a[110],dp[25000],cnt,ans,d[25000];

int main()
{
	ll i,j;
	scanf("%lld%lld",&n,&k);
	for(i=1; i<=n; i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1);
	dp[0]=d[0]=1;
	for(i=1; a[i]<k&&i<=n; i++)
	{
		a[i]=k-a[i];
		for(j=3000; j>=a[i]; j--)
		{
			dp[j]+=dp[j-a[i]];
		}
	}
	for(; a[i]==k&&i<=n; i++)cnt++;
	for(; i<=n; i++)
	{
		a[i]-=k;
		for(j=3000; j>=a[i]; j--)
		{
			d[j]+=d[j-a[i]];
		}
	}
	for(i=0; i<=3000; i++)
	{
		ans+=dp[i]*d[i]*(1ll << cnt);
	}
	printf("%lld",ans-1);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int x[1000000],y[1000000];
char d[1010][1010]={0};
int Y[]={1,1,0,-1,-1,-1,0,1};
int X[]={0,1,1,1,0,-1,-1,-1};
int main(){
  int w,h,i,j,t=0,r=0,rr=0,ny,nx;
  scanf("%d %d",&h,&w);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      scanf(" %c",&d[i][j]);
      if(d[i][j]=='.'){
	d[y[r]=i][x[r]=j]=0;
	r++;
      }
    }
  }
  for(i=0;r-rr;i++){
    for(rr=r;rr-t;t++){
      for(j=0;j<8;j++){
	ny=y[t]+Y[j];
	nx=x[t]+X[j];
	if(d[ny][nx]==0)continue;
	d[ny][nx]--;
	if(d[ny][nx]=='0'){
	  d[y[r]=ny][x[r]=nx]=0;
	  r++;
	}
      }
    }
  }
  printf("%d\n",i-1);
  return 0;
}

Measured memory_bytes: 9400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1
{
    class ITP1_2_D
    {
        static void Main(string[] args)
        {
            int W, H, x, y, r;

            List<int> numberList = Console.ReadLine().Split().Select(int.Parse).ToList<int>();

            W = numberList[0];
            H = numberList[1];
            x = numberList[2];
            y = numberList[3];
            r = numberList[4];

            if (0 <= (y - r) && H >= (y + r) && 0 <= (x - r) && W >= (x + r))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



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

int main() {
    char c;
    cin >> c;
    
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPX(op, t, x) operator op(CRP(t, x))
#define OPL(t, x) bool OPX(<, t, x) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef int64_t ll, i64;
typedef uint64_t ull, u64;
template <typename T>
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
template <typename T>
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
inline char getchar(int)
{
    static char buf[64 << 20], *S = buf, *T = buf;
    if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + S;
    return S == T ? EOF : *S++;
}
template <typename T, typename = enable_if_integral<T>>
inline void read(T &x)
{
    int ch = x = 0, f = 1;
    while (!isdigit(ch = getchar()))
        if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
template <typename T, typename... Args, typename = enable_if_integral<T>>
inline void read(T &x, Args &... args) { read(x), read(args...); }
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fpow(ll a, ll b, ll m)
{
    ll r = 1;
    for (; b; b >>= 1, a = a * a % m)
        if (b & 1) r = r * a % m;
    return r;
}
constexpr double eps = 1e-8;
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
int main()
{
    string s;
    cin >> s;
    u64 zc = count(s.begin(), s.end(), '0');
    cout << (min(zc, s.size() - zc) << 1);
    return 0;
}

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

#define ll long long
#define pb push_back

#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)

void solve()
{
    int x,n,a;
    cin >>x >>n;
    int cnt[110]= {0};
    rep(i,n)
    {
        cin >> a;
        cnt[a]=1;
    }
    for(int i=x,k=x;; i--,k++)
    {
        if(cnt[i]==0)
        {
            cout << i << "\n";
            return;
        }
        if(cnt[k]==0)
        {
            cout << k << "\n";
            return;
        }
    }

}

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

    int tt=1;
    ///cin >> tt;
    while(tt--)
    {
        solve();
    }
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using ll = long long int;
using ld = long double;
using str = string;

int main(){
  kyopro;
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  vector<int> a{};
  if(S.at(0) == '0') a.push_back(0);
  char kensaku = S.at(0);
  int renzoku{};
  for(auto&& i : S){
    if(kensaku == i){
      renzoku++;
    }
    else{
      kensaku = i;
      a.push_back(renzoku);
      renzoku = 1;
    }
  }
  a.push_back(renzoku);
  if(S.at(N-1) == '0') a.push_back(0);
  for(auto&& i : a){
    //cout << i << rt;
  }
  int sumax{};
  if(a.size()/2 < K) K = a.size()/2;
  for(int i{}; i < a.size()/2 + 1 - K; i++){
    int sum{};
    for(int j{}; j < K*2 + 1; j++){
      sum += a.at(i*2 + j);
    }
    //cout << sum << rt;
    sumax = max(sum,sumax);
  }
  cout << sumax << rt;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define  ft   ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  ll   long long
#define  pb   push_back
#define  ll   long long
#define  mk   make_pair
#define  msi  map<string,int>
#define  mii  map<int,int>
#define  pii  pair<int,int>
const int N=2e5+3;
ll a[N];
int main()
{
    ft
    ll t,i,j,n,m,ans=2e15;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(j=1;j<101;j++)
    {
        ll s=0;
        for(i=0;i<n;i++)
        {
            ll d=(a[i]-j);
            s+=(d*d);
        }
        ans=min(ans,s);
    }
    cout<<ans<<"\n";
    return 0;
}


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

int main(){
  int ans=0;
  string S;
  cin >> S;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; i++){
    int N1 = i % 10;
    int N2 = (i % 100)/10;
    int N4 = (i % 10000)/1000;
    int N5 = i / 10000;
    if (N1 == N5 && N2 == N4){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
// 5/10 リアルタイム参加
#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>;
using Graph = vector<vector<int>>;

const int mod = 998244353;
// const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}
 
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    ll N, M, K;
    cin >> N >> M >> K;

    // ll ans = 100;
    // rep(i, 99) {
    //     ans = (ans * 99) % MOD;
    //     // cout << ans << endl;
    // }

    // cout << (ll)(100.0 * pow(99.0, 99.0)) % 998244353 << endl;
    // cout << ans << endl;

    // mint ans(0);
    // mint m(M);

    // ans += m * (m - 1).pow(N - 1);

    // for (int i = 1; i <=K; i++) {
    //     ans += m * choose(N - 1, i) * (m - 1).pow(N - i - 1);
    // }
    
    // rep(i, K) {

    // }

    // cout << m.x << endl;
    // cout << (m - 1).x << endl;

    // cout << ans.x << endl;

    // 以下、6/13に解き直し。
    combination comb(1e6);

    mint ans = 0;

    for (int i = 0; i <= K; i++) {
      ans += mint(M) * comb(N - 1, i) * mint(M - 1).pow(N - 1 - i);
    }

    cout << ans.x << endl;
}


Measured memory_bytes: 18840
s = input()
K = int(input())
ans = ''
for i in s[:-1]:
    if i == 'a':
        ans += 'a'
        continue
    if 123 - ord(i) <= K:
        ans += 'a'
        K -= 123 - ord(i)
    else:
        ans += i
ans += chr((ord(s[-1])-97+K)%26 +97)
print(ans)

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T1,typename T2> using M = map< T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;
using Mci = M<char, int>;

int main(){
    int n;
    cin>>n;
    Vi p(n);
    REP(i,n) cin>>p[i];
    
    int cnt = 0;
    REP2(i,1,n-1){
        if((p[i-1]<p[i] && p[i]<p[i+1]) || 
            (p[i-1]>p[i] && p[i]>p[i+1])) cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<random>
using namespace std;
int D=366;
int K=26;
int main()
{
  int d,cc=0,i,j,r,rj,x,x1,x2,time,inf,infk,di,dik,th;
  int c[K],s[D][K],t[D],m[D],l[D][K],res[D],
  t2[D],m2[D],l2[D][K],res2[D];
  bool f;
  random_device seed_gen;
  mt19937 engine(seed_gen());
  uint32_t ra;
  cin >> d;
  for(i=0;i<K;i++){
    cin >> c[i];
    cc+=c[i];
  }
  for(i=1;i<=d;i++)
    for(j=0;j<K;j++)
      cin >> s[i][j];
  fill(l[0],l[0]+K,0);
  m[0]=0;
  res[0]=0;
  di=INT_MAX/(D-1);
  inf=di*(D-1);
  dik=INT_MAX/K;
  infk=dik*K;
  th=(int)(INT_MAX*0.7);
  for(i=1;i<=d;i++){
    r=0;
    rj=-1;
    copy(l[i-1],l[i-1]+K,l[i]);
    for(j=0;j<K;j++)
      if(s[i][j]+c[j]*(i-l[i][j])>r){
        r=s[i][j]+c[j]*(i-l[i][j]);
        rj=j;
      }
    m[i]=m[i-1]+cc-c[rj]*(i-l[i][rj]);
    t[i]=rj;
    l[i][rj]=i;
    res[i]=res[i-1]+s[i][rj]-m[i];
  }
  for(time=0;time<100000;time++){
    ra=engine();
    if(ra>th) f=0;
    else f=1;
    ra=engine();
    while(ra>=inf)
      ra=engine();
    x1=ra/di;
    if(f==1){
      ra=engine();
      while(ra>=inf)
        ra=engine();
      x2=ra/di;
      if(x1==x2)
        continue;
      x=min(x1,x2);
      copy(t,t+D,t2);
      t2[x1]=t[x2];
      t2[x2]=t[x1];
    }else{
      ra=engine();
      while(ra>=infk)
        ra=engine();
      x2=ra/dik;
      x=x1;
      copy(t,t+D,t2);
      t2[x1]=x2;
    }
    copy(m,m+D,m2);
    for(j=0;j<=d;j++)
      copy(l[j],l[j]+K,l2[j]);
    copy(res,res+D,res2);
    for(i=x;i<=d;i++){
      copy(l2[i-1],l2[i-1]+K,l2[i]);
      m2[i]=m2[i-1]+cc-c[t2[i]]*(i-l2[i][t2[i]]);
      l2[i][t2[i]]=i;
      res2[i]=res2[i-1]+s[i][t2[i]]-m2[i];
    }
    if(res2[d]>res[d]){
      copy(t2,t2+D,t);
      copy(m2,m2+D,m);
      for(j=0;j<=d;j++)
        copy(l2[j],l2[j]+K,l[j]);
      copy(res2,res2+D,res);
    }
  }
  for(i=1;i<=d;i++)
    cout << t[i]+1 << endl;
  return 0;
}

Measured memory_bytes: 3768
import math
K = int(input())
ans_t = 0
ans = [0] * (200+1)
for i in range(1,K+1):
    for j in range(1,K+1):
        ans[math.gcd(i, j)] += 1
        
for i in range(1,K+1):
    for j in range(1,K+1):
        if ans[i] != 0:
            ans_t += ans[i] * math.gcd(i, j)

print(ans_t)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define vec vector<int,int> 
#define int long long 
int visited[100001];


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
	int t=1;
//	cin>>t;
	while(t--){
		int h,w;
		cin>>h>>w;
		int arr[h][w];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				char a;
				cin>>a;
				if(a=='.') arr[i][j]=1;
				else arr[i][j]=0;
			}
		}
		int **dp=new int *[h];
		rep(i,h){
			dp[i]=new int[w];
			rep(j,w){
				dp[i][j]=0;
			}
		}
		dp[h-1][w-1]=1;
		for(int i=w-2;i>=0;i--){
			if(arr[h-1][i]==1){
				dp[h-1][i]=dp[h-1][i+1];
			}
		}
	
		for(int i=h-2;i>=0;i--){
			if(arr[i][w-1]==1){
				dp[i][w-1]=dp[i+1][w-1];
			}
		}
		
		for(int i=h-2;i>=0;i--){
			for(int j=w-2;j>=0;j--){
				if(arr[i][j]!=0){
					dp[i][j]=dp[i+1][j]+dp[i][j+1];
					dp[i][j]%=mod;
				}
			}
		}
		
		cout<<(dp[0][0]%mod)<<endl;
	}
	//exit();
	return 0;
}


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

std::vector<int> vecArray[3];

int main(){
    int n;
    std::cin >> n;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < n; j++){
            int input;
            std::cin >> input;
            vecArray[i].push_back(input);
        }
        std::sort(vecArray[i].begin(), vecArray[i].end());
    }

    long long ans = 0;
    for(int b : vecArray[1]){
        long long a = std::lower_bound(vecArray[0].begin(), vecArray[0].end(), b) - vecArray[0].begin();
        long long c = vecArray[2].end() - std::upper_bound(vecArray[2].begin(), vecArray[2].end(), b);
        ans += a * c;
    }
    std::cout << ans << std::endl;
}


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

// #include<cstdio>

int main(){
  int H, W;

  while(1){
    cin >> H >> W;
    if (H==0 && W==0) break;
    for (int i=0; i<H; i++){
      for (int j=0; j<W; j++){
	if ((i+j)%2==0) cout << '#';
	else cout << '.';
      }
      cout << "\n";
    }
    cout << "\n";
  }

  return 0;
}

Measured memory_bytes: 3100
n = gets.chomp.to_i
a = [0]
a += gets.chomp.split(" ").map(&:to_i)
a1 = []
a2 = []
(1..n).each do |i|
  if i.even?
    a1 << a[i]
  else
    a2 << a[i]
  end
end
if n.even?
  puts (a1.reverse + a2).join(" ")
else
  puts (a2.reverse + a1).join(" ")
end


Measured memory_bytes: 29820