akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;
char s[100005],ans[100005];
int n;
char fir[5]={'S','S','W','W'};
char sec[5]={'S','W','S','W'};
int judge()
{
	for(int i=1;i<=n;i++)
	{
		int left,right;
		left=i-1>=1?i-1:n;
		right=i+1<=n?i+1:1;
		if(s[i]=='o')
		{
			if(ans[i]=='W')
			{
				if(ans[left]==ans[right])
				return 0;	
			}
			else
			{
				if(ans[left]!=ans[right])
				return 0;
			}
		}
		else
		{
			if(ans[i]=='W')
			{
				if(ans[left]!=ans[right])
				return 0;
			}
			else
			{
				if(ans[left]==ans[right])
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	cin>>n;
	scanf("%s",s+1);	
	int flag=0;
	for(int k=0;k<4;k++)
	{
		ans[1]=fir[k];
		ans[2]=sec[k];
		for(int i=2;i<n;i++)
		{
			if(s[i]=='o')
			{
				if(ans[i]=='S')
				ans[i+1]=ans[i-1];
				else
				{
					if(ans[i-1]=='W')
					ans[i+1]='S';
					else
					ans[i+1]='W';
				}	
			}
			else
			{
				if(ans[i]=='S')
				{
					if(ans[i-1]=='S')
					ans[i+1]='W';
					else
					ans[i+1]='S';
				}
				else
				ans[i+1]=ans[i-1];
			}
		}
		if(judge()==1)
		{
			for(int i=1;i<=n;i++)
			cout<<ans[i];
			cout<<endl;	
			flag=1;
		}
		if(flag)
		break;
	}
	if(flag==0)
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define MOD 1000000007

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int y,m,d;
    scanf("%d/%d/%d",&y,&m,&d);
    if (y<2019||(y==2019&&m<=4)) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.length(); ++i) {
        while (s[i] == s[i+1]) {
            s.erase(i, 1);
        }
    }
    cout << s.length();
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int m = scan.nextInt();
		int f = scan.nextInt();
		int r = scan.nextInt();
		while(m!=-1||f!=-1||r!=-1){
			if(m+f<30||m==-1||f==-1)
				System.out.println("F");
			else if(m+f>=80)
				System.out.println("A");
			else if(m+f<80 && m+f>=65)
				System.out.println("B");
			else if(m+f<65 && m+f>=50)
				System.out.println("C");
			else if(m+f<50 &&m+f>=30 && r<50)
				System.out.println("D");
			else
				System.out.println("C");
			m = scan.nextInt();
			f = scan.nextInt();
			r = scan.nextInt();
		}
	}
}

Measured memory_bytes: 19280
n=int(input())
m=list(map(int,input().split()))

for i in range(n-1):
  m[i+1]+=m[i]
a=m[n-1]

for i in range(n):
  if m[i]>=a/2:
    a1=m[i]
    a2=m[i-1]
    break

a1=abs(a1*2-a)
a2=abs(a2*2-a)
print(min(a1,a2))

Measured memory_bytes: 88272
n = int(input())
s = input()
a = "SS"
ct=1
while ct<7:    
    for i in range(n-1):
        p=a[i]
        q="A"
        if a[i]=="S":
            q="W"
        else:
            q="S"
        if a[i+1]=="S":
            if s[i+1] == "o":
                a=a+a[i]
            else:
                a=a+q
        else:
            if s[i+1] == "o":
                 a=a+q
            else:
                a=a+a[i]
    if a[0]==a[n]:
        if a[0]=="S" and s[0]=="o" and a[n-1]==a[1]:
            print(a[0:n])
            break
        elif a[0]=="S" and s[0] !="o" and a[n-1]!=a[1]:         
            print(a[0:n])
            break
        elif a[0]=="W" and s[0] =="o" and a[n-1]!=a[1]: 
            print(a[0:n])
            break
        elif a[0]=="W" and s[0] !="o" and a[n-1]==a[1]: 
            print(a[0:n])
            break
        else:
            ct=ct+1
            if ct==2:
                a="SW"
            elif ct==3:
                a="WS"
            elif ct==4:
                a="WW"
            else:
                print(-1)
                break
    else:
        ct=ct+1
        if ct==2:
            a="SW"
        elif ct==3:
            a="WS"
        elif ct==4:
            a="WW"
        else:
            print(-1)
            break

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k,c;
	cin>>n>>k>>c;
	char ch;
	vb v(n);
	rep(i,n){
		cin>>ch;
		v[i]=(ch=='o');
	}
	vl a(k),b(k);
	ll cnt=-1,rest=0;
	rep(i,n){
		if(v[i]&&rest<=0){
			cnt++;
			if(cnt<k)a[cnt]=i;
			rest=c;
		}
		else rest--;
	}
	cnt=k;rest=0;
	rrep(i,n){
		if(v[i]&&rest<=0){
			cnt--;
			if(cnt>=0)b[cnt]=i;
			rest=c;
		}
		else rest--;
	}
	rep(i,k){
		if(a[i]==b[i])puta(a[i]+1);
	}
}


Measured memory_bytes: 6276
#include <iostream>
 
using namespace std;
 
int niz[30];
string a;
long long int sol;
 
inline long long int povrh(int a,int b)
{
    long long int nazivnik=1;
    long long int brojnik=1;
    for(int i=1;i<=b;i++)
    {
        nazivnik*=(a-i+1);
        brojnik*=i;
    }
    return nazivnik/brojnik;
}
 
int main()
{
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        niz[a[i]-'a']++;
    }
    sol=povrh(a.size(),2);
    for(int i=0;i<30;i++)
    {
        if(niz[i]!=0)
        sol-=povrh(niz[i],2);
    }
    cout<<sol+1;
   
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;




int main(){
	int H,W; cin >> H >> W;
	vector<vector<char>> a(H,vector<char>(W));
	int cnt = 0;;
	rep(i,H)rep(j,W){
		cin >> a[i][j];
		if(a[i][j] == '#') cnt++;
	}
	cout << (cnt == H+W-1 ? "Possible" : "Impossible") << endl;
}



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

int main(){
  double N;
  cin >> N;
  long long int mind = D;
  int maxh = (int)ceil(sqrt(N)+1);
  long long int K = (long long int)N;
  for(int i=1;i<maxh;i++){
    if(K%i==0){
      //cout << i << " " << i+(K/i) << endl;
      if(mind > i+(K/i)){
        mind = i+(K/i);
      }
    }
  }
  cout << mind-2 << endl;
  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = N;
  int sum = 0;
  for(int i = 0; i < N; ++i) {
    if(sum + a[i] <= x) {
      sum += a[i];
    } else {
      cout << i << endl;
      return 0;
    }
  }
  if(sum == x) {
    cout << N << endl;
  } else {
    cout << N - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int p = sc.nextInt();
		int answer = (a*3 + p)/2;
		System.out.println(answer);
	}

}


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


int main(){
    int a, b;
    char op;
    while(1){
        
    cin >> a >> op >> b ;
    
    if ( op  == '?' ) break;
    
    if ( op == '+'){
        cout << a + b << endl;
    }else if ( op == '-'){
        cout << a - b << endl;
    }else if (op == '*'){
        cout << a*b << endl;
    }else if ( op  == '/' ){
        cout << a/b << endl;
    }
    
    
    }
    
    return 0;
    
}

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define WMAX 10000
#define HMAX 10000
 
//コメントアウトするとdebug()を実行しない
#define DEBUG
 
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
typedef pair<int ,int > P;
typedef long long ll;
 
int K,S,ans = 0,X =0, Y =0, Z = 0;
 
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};
 
void solve(){
 
}
 
void debug(){
 
}
 
void answer(){
	cout << ans << "\n";
}
 
int main(){
	cin >> K >> S;
	for (int X = 0; X <= K; ++X)
	{
		for (int Y = 0; Y <= K; ++Y)
		{
			if(S-X-Y <= K && S-X-Y >= 0){
				ans++;
			}
		}
	}
	answer();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;cin >> n;
    long int B[n-1]; for (int i=0;i<n-1;i++) cin >>B[i];
    long long ans=B[0]+B[n-2];
    for (int i=1;i<n-1;i++) {
      ans += min(B[i-1],B[i]);
    }
    cout << ans << endl;
}

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


unsigned long long int GCM(unsigned long long int a,unsigned long long int b){
	while(a!=b){
		a>b? a-=b:b-=a;
	}
	return a;
}

int main()
{
	unsigned long long int a,b,L,G;
	
	cin>>a;
	do{
	cin>>b;
	if(a!=0&&b!=0){
	G=GCM(a,b);
	L=a*b/G;
	cout<<G<<" "<<L<<endl;
	}
	}while(cin>>a);
	cin>>a;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll ans = 0;
  if (a + b >= 2 * c) {
    ll z = min(x, y);
    ans += 2 * c * z;
    x -= z;
    y -= z;
  }
  if (a >= 2 * c) ans += 2 * c * x;
  else ans += a * x;
  if (b >= 2 * c) ans += 2 * c * y;
  else ans += b * y;
  cout << ans << endl;
}

Measured memory_bytes: 256
import bisect

N = input()
N = int(N)
L = list(map(int,input().split()))

L_sorted = sorted(L, reverse = False)#昇順

count = 0
for i in range(N):#aの選び方
    for j in range(i+1,N):#bの選び方
        a = L_sorted[i]
        b = L_sorted[j]#b <= c < a+b
        count += bisect.bisect_left(L_sorted, a+b) - j -1
print(count)

Measured memory_bytes: 9288
#include <stdio.h>
#include <stdlib.h>

#define N 50

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int d[ N ] = { };
    int n, p;
    int r;

    scanf ( "%d%d", &n, &p );
    if ( n == 0 && p == 0 )
      break ;
    
    r = p;
    for ( i = 0; ; i = ( i + 1 ) % n )
    {
      if ( r == 0 )
      {
        r = d[ i ];
        d[ i ] = 0;
      }
      else
      {
        --r;
        ++d[ i ];
      }

      if ( d[ i ] == p )
      {
        printf ( "%d\n", i );
        break ;
      }
    }
  }


  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

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

       int n=ob.nextInt();
        if (n<30) {
            System.out.println("No");
        }
        else {
            System.out.println("Yes");
        } 
    }
}


Measured memory_bytes: 26968
rows = int(input())
judge = [input() for i in range(rows)]
AC = str(judge.count('AC'))
WA = str(judge.count('WA'))
RE = str(judge.count('RE'))
TLE = str(judge.count('TLE'))
print('AC x ' + AC) 
print('WA x ' + WA) 
print('TLE x ' + TLE) 
print('RE x ' + RE) 

Measured memory_bytes: 16188
let levenshtein_distance s t =
  let m = String.length s in
  let n = String.length t in
  let d = Array.make_matrix (m + 1) (n + 1) 0 in
  let rec dudu i =
    if i <= m then begin
      d.(i).(0) <- i;
      dudu (i + 1)
    end in
  let rec wa i =
    if i <= n then begin
      d.(0).(i) <- i;
      wa (i + 1)
    end in
  let rec doit = function
    | (i, _) when i > m -> d.(m).(n)
    | (i, j) when j > n -> doit (i + 1, 1)
    | (i, j) ->
      let c = if s.[i-1] = t.[j-1] then 0 else 1 in
      d.(i).(j) <- if d.(i-1).(j) + 1 < d.(i).(j-1) + 1 then d.(i-1).(j) + 1 else d.(i).(j-1) + 1;
      d.(i).(j) <- if d.(i-1).(j-1) + c < d.(i).(j) then d.(i-1).(j-1) + c else d.(i).(j);
      doit (i, j + 1) in
  dudu 1; wa 1; doit (1, 1)

let () =
  let s1 = read_line () in
  let s2 = read_line () in
  Printf.printf "%d\n" (levenshtein_distance s1 s2)

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

int main(void){
    string s,t;
	int cnt=0;
    cin >> s;
	cin >> t;
	if(s[0] == t[0]){
		cnt++;
	}
	if(s[1] == t[1]){
		cnt++;
	}
	if(s[2] == t[2]){
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
def main():
	a,b,c,d,e=(int(x) for x in input().split())
	count = 0
	if 0 <= c+e <= a and 0 <= c-e <= a:
				count+=1
	if 0 <= d+e <= b and 0 <= d-e <= b:
				count+=1
	if count == 2:
		print("Yes")
	else:
		print("No")
	
if __name__ == "__main__":
	main()


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

int main() {
  vector<string> weather = {"Sunny", "Cloudy", "Rainy"};
  string s;
  cin >> s;
  cout << weather[ (distance(weather.begin(), find(weather.begin(), weather.end(), s)) + 1) % weather.size() ] << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
 
using namespace std;
typedef long long ll;
 
int main(){
  string s;
  bool f1 = false;
  bool f2 = false;
  cin >> s;
  int n = s.length();
  for(int i = 0;i < n; i++){
    if(s[i] == 'C'){
      f1 = true;
    }
    if(s[i] == 'F' && f1 == true){
      f2 = true;
    }
  }
  if(f1 == true && f2 == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define fr first
#define sc second
using namespace std;
#define INF 10000000
typedef pair<int,int> iiP;
typedef pair<int,iiP> P;
struct edge{
  int to,cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
int c,n,m;
int S,G;
int min_cost[101][10];
bool used[101][10];
vector< vector<edge> > info;
int solve();
int main(){
  while(cin >> c >> n >> m >> S >> G && (c||n||m||S||G)){
  for(int i=0;i<101;i++){
    for(int j=0;j<10;j++){
      min_cost[i][j] = INF;
      used[i][j] = false;
    }
  }
  info.resize(n + 1);
  for(int i=0,a,b,f;i<m;i++){
    cin >> a >> b >> f;
    info[a].push_back(edge(b,f));
    info[b].push_back(edge(a,f));
  }
  cout << solve() << endl;

  for(int i=0;i<=n;i++) info[i].clear();
  }
}
int solve(){
  priority_queue< P,vector<P>,greater<P> > que;

  min_cost[S][c] = 0;
  que.push(P(0,iiP(S,c)));

  while(!que.empty()){
    P p = que.top();
    int cost = p.fr,now = p.sc.fr,KEN = p.sc.sc;
    que.pop();

    if( now == G) return cost;

    if( used[now][KEN] ) continue;
    used[now][KEN] = true;

    for(int i = 0,l = info[now].size();i < l;i++){
      edge e = info[now][i];
      if(cost + e.cost < min_cost[e.to][KEN]){
        min_cost[e.to][KEN] = cost + e.cost;
        que.push(P(min_cost[e.to][KEN],iiP(e.to,KEN)));
      }
      if(KEN != 0){
        if( cost + e.cost/2 < min_cost[e.to][KEN-1] ){
          min_cost[e.to][KEN-1] = cost + e.cost/2;
          que.push(P(min_cost[e.to][KEN-1],iiP(e.to,KEN-1)));
        }
      }
    }
  }
}

Measured memory_bytes: 1248
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct data{
    int key;
    int time;
};

int main(){
    int n;
    while(cin >> n, n){
        struct data d[1000005];
        rep(i,n){
            int key, m1, s1, m2, s2, m3, s3, m4, s4;
            cin >> d[i].key >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            d[i].time = (m1 + m2 + m3 + m4) * 60 + s1 + s2 + s3 + s4;
        }
        rep(i,n){
            for(int j = n - 1; j > i; j--){
                if(d[j].time < d[j - 1].time){
                    struct data g = d[j];
                    d[j] = d[j - 1];
                    d[j - 1] = g;
                }
            }
        }
        cout << d[0].key << endl << d[1].key << endl << d[n - 2].key << endl;
    }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;



int main(){
    int A,B;cin >> A >> B;
    int Q;cin >> Q;
    vector<LL> s,t;
    vector<LL> x;
    for(int a = 0;a < A;a++){
        LL w;cin >>w;s.push_back(w);
    }
    for(int a = 0;a < B;a++){
        LL w;cin >> w;t.push_back(w);
    }
    for(int i = 0;i < Q;i++){
        LL w ;cin >> w;
        int idx_s = upper_bound(s.begin(),s.end(),w)-s.begin();
        int idx_t = upper_bound(t.begin(),t.end(),w)-t.begin();
        LL ans = 1e18;
        for(int a = max(idx_s-3,0);a < min((int)s.size(),idx_s+3);a++){
            for(int b = max(idx_t-3,0);b < min((int)t.size(),idx_t+3);b++){
                LL q = w-s.at(a);
                LL p = w-t.at(b);
                if(p > 0 && q > 0){
                    ans = min(max(p,q),ans);
                }else if(p < 0 && q < 0){
                    ans = min(-min(q,p),ans);
                }else{
                    ans = min(abs(p)+abs(q) + min(abs(p),abs(q)),ans);
                }
               // cout<<a<<" "<<b<<" "<<ans<<endl;
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)cout<<"x";
	cout<<endl;
	return 0;
}

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


    int solve(int n){
        int i = 1;
        int cnt = 0;
        for(i = 1;i*i<=n;i++){
            if(n%i == 0){
                if((n/i) != i) cnt += 2;
                else cnt++;
            }
        }
        return cnt;
    }
    
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,i,res = 0;
    cin >> n;
    for(i = 1;i<=n-1;i++){
        res += solve(i);
    }
      cout << res << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main(){
    int N,d;
    cin>>N>>d;
    int ans=0;
    for(int i=0;i<N;i++){
        int p;
        cin>>p;
        if(p>d)ans+=p-d;
    }
    if(ans)cout<<ans<<endl;
    else cout<<"kusoge"<<endl;
    return 0;
}

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

struct captile {
    char& c;
    captile(char& c):c(c) {}
    void captilize() {
        if('A' <= c && c <= 'Z') return;
        c = 'A'+(c-'a');
    }
    void in_captilize() {
        if('a' <= c && c <= 'z') return;
        c = 'a'+(c-'A');
    }
    bool isCaptile() {
        return 'A' <= c && c <= 'Z';
    };
};

int main() {
    string s;
    cin >> s;
    bool ok = true;
    if(s[0] != 'A') ok = false;
    int cnt = 0;
    rep2(i,2,s.size()-1) {
        if(s[i] == 'C') cnt++;
    }
    if(cnt != 1) ok = false;
    rep(i,s.size()) {
        char c = s[i];
        if(c != 'A' && c != 'C' && captile(c).isCaptile()) ok = false;
    }
    if(ok) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
import sys
import time


def main():
    n = int(sys.stdin.readline().strip())
    a = [[0] * n for _ in range(n)]
    for i in range(n):
        a[i] = [int(s) for s in sys.stdin.readline().strip().split(' ')]

    loc = [n-2] * n

    ans = 0
    game_count = 0
    total_game_count = n * (n-1) // 2
    start = time.time()
    while game_count != total_game_count:
        now = time.time()
        if (now - start > 1):
            print(n * (n-1) // 2)
            return

        found = False
        used = [False] * n
        for i in range(n):
            if loc[i] == -1:
                continue
            if used[i]:
                continue
            target = a[i][loc[i]] - 1
            if used[target]:
                continue
            if loc[target] == -1:
                continue
            if a[target][loc[target]] - 1 == i:
                used[i] = True
                used[target] = True
                loc[i] -= 1
                loc[target] -= 1
                found = True
                game_count += 1
        ans += 1
        if not found:
            print(-1)
            return
    print(ans)


main()


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

long long a,b;

int main(){
    cin>> a >> b;
    if(0<a){
        cout<<"Positive"<<endl;
    }else if(b<0){
        if((b-a+1)%2==0){
            cout<<"Positive"<<endl;
        }else{
            cout<<"Negative"<<endl;
        }
    }else{
        cout<<"Zero"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>


using namespace std;

int main(){
  int a;

  cin >> a;
  if(a == 22)
  cout << "Christmas Eve Eve Eve"<< endl;
  else if(a == 23)
  cout << "Christmas Eve Eve" << endl;
  else if(a == 24)
  cout << "Christmas Eve" << endl;
  else if(a == 25)
  cout << "Christmas" << endl; 
}


Measured memory_bytes: 256
def dfs(i,d,c):
    global n,f,ans
    c2=c.copy()
    c2[d]=1
    #print("#",i,d,c2)
    if i==n:
        ans+=1
        return
    for j in range(n):
        #print(d,j,c2)
        if (f[d][j]==1 or f[j][d]==1) and c2[j]==0:
            #print(d,j)
            dfs(i+1,j,c2)

n,m=map(int,input().split())
f=[[0]*n for _ in range(n)]
c1=[0]*n
ans=0
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    f[a][b]=1
#print(f)
dfs(1,0,c1)
print(ans)

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

typedef tuple<int, int, int> ti;
int main() {
  int h, w;
  cin>>h>>w;
  string s[h];
  for (int i=0; i<h; i++) {
    cin>>s[i];
  }
  if (s[0][0] == '#' || s[h-1][w-1] == '#') {
    cout<<-1<<endl;
    return 0;
  }
  int cnt[h][w];
  bool arrived[h][w];
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cnt[i][j] = 0;
      arrived[i][j] = false;
    }
  }
  priority_queue<ti, vector<ti>, greater<ti> > pq;
  pq.push(make_tuple(1, 0, 0));
  while (!pq.empty()) {
    auto top = pq.top();
    pq.pop();
    int c, y, x;
    tie(c, y, x) = top;
    if (arrived[y][x]) {
      continue;
    }
    arrived[y][x] = true;
    cnt[y][x] = c;
    if (y > 0 && s[y-1][x] == '.') {
      pq.push(make_tuple(c + 1, y-1, x));
    }
    if (y < h-1 && s[y+1][x] == '.') {
      pq.push(make_tuple(c + 1, y+1, x));
    }
    if (x > 0 && s[y][x-1] == '.') {
      pq.push(make_tuple(c + 1, y, x-1));
    }
    if (x < w-1 && s[y][x+1] == '.') {
      pq.push(make_tuple(c + 1, y, x+1));
    }
  }
  if (cnt[h-1][w-1] == 0) {
    cout<<-1<<endl;
    return 0;
  }
  int w_cnt = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (s[i][j] == '.') {
        ++w_cnt;
      }
    }
  }
  cout<<w_cnt - cnt[h-1][w-1]<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n, a, b; cin >> n >> a >> b;
  int d = b - a - 1;
  if (d % 2 == 1) outl("Alice");
  else outl("Borys");
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k,q;cin>>k>>q;
    vector<ll> d(k); rep(i,k)cin>>d[i];
    vector<ll> a(k);//本当のa_jはこれにx_iとかいろいろ足す
    a[0]=0;
    for(int i=0; i<k-1; i++){
        a[i+1]=a[i]+d[k];
    }


    for(int i=0; i<q; i++){
        ll n,x,m;cin>>n>>x>>m;
        //繰り上がり回数を数える
        //足してって最後に割ればOK
        //O(n)はだめなので繰り返しはまとめて
        vector<ll> e(k);
        rep(i,k){
            e[i]=(d[i]-1+m)%m+1;
        }//d_iに0もあるらしい
        ll sumc = 0, sump = 0, sumcc = 0, sumpp = 0;
        ll A = (n-1)/k, B=(n-1)%k;
        for(int j=0; j<k; j++){
            sumc += e[j];
            //if(e[j]==0)sumcc++;
            if(j<B){
                sump+=e[j];
                //if(e[j]==0)sumpp++;
            }
        }
        ll sum = sumc*A+sump+x;
        cout<<n-1-(sum/m-x/m)-sumcc*A-sumpp<<endl;
    }

    


    
    return 0;
}

Measured memory_bytes: 384
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> pos;
    pos.push_back(0);
    for(int i=0; i<N; i++) {
        int val; cin >> val;
        pos.push_back(val);
    }

    int base = 0;
    for(int i=1; i<N+2; i++) {
        base += abs(pos[i-1] - pos[i]);
    }

    for(int i=1; i<N+1; i++) {
        int tmp = base;
        tmp -= abs(pos[i-1] - pos[i]);
        tmp -= abs(pos[i+1] - pos[i]);
        tmp += abs(pos[i-1] - pos[i+1]);
        cout << tmp << endl;
    }
    return 0;
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a >>b;
  if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------
const ll MAX_V = 200010;

class dijkstra {
public:

    struct edge {
        ll to;
        ll cost;
    };

    vector<edge> E[MAX_V];
    ll d[MAX_V];

    void calc(ll s) {
        priority_queue <pll, vector<pll>, greater<pll> > que;
        rep(i, MAX_V) d[i] = LINF;
        que.emplace(0LL, s);
        d[s] = 0LL;
        while (!que.empty()) {
            pll p = que.top();
            que.pop();
            ll v = p.second;
            if (d[v] < p.first) continue;

            for (auto&& e : E[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.emplace(d[e.to], e.to);
                }
            }
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    dijkstra ds;

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        ds.E[a].push_back({b, 1});
        ds.E[b].push_back({a, 1});
    }
    ds.calc(0);
    int v, max_d = -1;

    rep(i, n) {
        if (ds.d[i] > max_d) {
            max_d = ds.d[i];
            v = i;
        }
    }
    ds.calc(v);
    ll diameter = 0;
    rep(i, n) diameter = max(diameter, ds.d[i]);
    cout << (diameter % 3 == 1 ? "Second" : "First") << endl;
    return 0;
}



Measured memory_bytes: 23476
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=1000000007;

int sumd(ll n)
{
    int d=0;
    while(n>0)
    {
        d+=(n%10);
        n/=10;
    }
    return d;
}
int main()
{
    ll n;cin>>n;
    int d=sumd(n);
    if(n%d==0)
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 3000 + 20, mod = 1e9 + 7;
int n, m, dp[2][N][N], ans;

inline void add (int &a, int b)
{
	a += b;
	if (a >= mod) a -= mod;
}

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

	cin >> n >> m;

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

	for (int i = 0; i <= m; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			for (int id : {0, 1})
			{
				if (j == 0 && id == 0)
				{
					add(dp[1][i][j], dp[0][i][j]);
					dp[0][i][j] = 0;
					continue;
				}

				if (i == m) continue;

				if (j != n)
				{
					add(dp[id][i + 1][j], dp[id][i][j]);
					add(dp[id][i + 1][j + 1], dp[id][i][j]);
				}
				if (j != 0)
				{
					if (j == 1 && id == 0)
						add(dp[1][i + 1][j], dp[0][i][j]);
					else
						add(dp[id][i + 1][j], dp[id][i][j]);
					add(dp[id][i + 1][j - 1], dp[id][i][j]);
				}
			}
		}
	}

	for (int i = 0; i <= n; i++) add(ans, dp[1][m][i]);

	cout << ans << '\n';
}


Measured memory_bytes: 71296
#include <iostream>
#include <cmath>
#include <string.h>

using namespace std;
 
int main(){
    char KUPC[301];
    int cnt1=0,cnt2=0,cnt3=0,cnt4=0,ans;
 
    cin >> KUPC;
    for( int i = 0 ; i < strlen(KUPC) ; i++ ){   
	if( KUPC[i] == 'K') cnt1++;
	else if(KUPC[i] == 'U') cnt2++;
	else if(KUPC[i] == 'P') cnt3++; 
	else if(KUPC[i] == 'C') cnt4++;
    }
    ans = min( cnt1 , min( cnt2 , min( cnt3 , cnt4 ) ) );
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3088
input_lines = input().split()
N = int(input_lines[0])
A = int(input_lines[1])
B = int(input_lines[2])

ans = 0
if (B-A)%2 == 0:
    print(int((B-A)//2))
else:
    print(min(A-1,N-B)+1+int((B-A-1)//2))
    #A+ans=B+N-B-(ans-1-N+B)=2N-ans+1-B
    #ans=(2N-A-B+1)/2

    #B-ans=A-(A-1)+(ans-1-(A-1))=ans-A+1
    #ans=(A+B-1)/2
    #print(min(int((2*N-A-B+1)/2),int((A+B-1)/2)))
    
#    if A-1 < N-B:
#        ans = A-1+1
#        A = 1
#        B -= (ans)
#    else:
#        ans = N-B+1
#        A += (ans)
#        B = N
#    print(int((B-A-1)/2)+ans)

#    ans = int((A-B-1)/2)
#    A+=ans
#    B-=ans
#    print(min(N-A,B-1)+ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n,k,q;
  cin >> n >> k >>q;
  vector<int>P(n);
  for(int i=0;i<q;i++){
    int a;
    cin >> a;
    a--;
    P[a]++;
  }
  for(int i=0;i<n;i++){
    if(P[i]>q-k) cout<< "Yes" <<endl;
    else cout<< "No" <<endl;
  }
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
using namespace std;

using pii=pair<int, int>;
#define X first
#define Y second
const int N=1e5+5;
int n, m;

int main(){
	scanf("%d%d", &n, &m);
	map<int, int> mp;
	for(int i=0,d;i<n;++i){
		scanf("%d", &d);
		++mp[d];
	}
	auto cmp = [](pii &a, pii &b) {return a.X > b.X;};
	priority_queue<pii, vector<pii>, decltype(cmp)> q(cmp);
	for(auto itr=mp.rbegin(); itr!=mp.rend(); ++itr){
		q.push({itr->X, itr->Y});
	}
	for(int i=0,a,b;i<m;++i){
		scanf("%d%d", &a, &b);
		int c = 0;
		while(q.size() && q.top().X < b && c<a){
			auto t = q.top(); q.pop();
			c += t.Y;
			if(c>=a){
				q.push({b, a});
				if(c>a) q.push({t.X, c-a});
				c = 0;
				break;
			}
		}
		if(c) q.push({b, c});
	}
	long long ans = 0;
	while(q.size()){
		ans += 1LL * q.top().X * q.top().Y;
		q.pop();
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 6136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//Get the highest value and key from a map.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

const ll MAX = 1e18;

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

  vector<ll> vi(n);
  bool flg = false;
  rep(i, n) {
    cin >> vi[i];
    if (vi[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll res = 1;
  for (auto i : vi) {
    if (MAX/res < i) {
      cout << -1 << endl;
      return 0;
    } else {
      res *= i;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 4016
s = str(input())
n = len(s)

for i in range(len(s)):
    if s[i-1] != s[-i]:
        print('No')
        exit()

pre = list(s[0:int((n-1)/2)])
rear = list(s[int((n+3)/2-1):int(n)])

for i in range(len(pre)):
    if pre[i-1] != pre[-i]:
        print('No')
        exit()

for i in range(len(rear)):
    if rear[i-1] != rear[-i]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3064
N = int(input())
h = [int(i) for i in input().split()]

li = [0]*N
li[0] = 0
li[1] = abs(h[1] - h[0])

for i in range(2, N):
    sub1 = li[i-1] + abs(h[i]- h[i-1])
    sub2 = li[i-2] + abs(h[i] - h[i-2])
    li[i] = min(sub1, sub2)

print(li[N-1])


Measured memory_bytes: 13928
open System

let n, k =
    let l = Console.ReadLine().Split(' ')
    let n = l.[0] |> int
    let k = l.[1] |> Int64.Parse
    n, k

let a =
    Console.ReadLine().Split(' ')
    |> Array.map (fun x -> int(x) - 1)

let ans =
    let loopOrigin, path =
        let mutable towns = Set<int> []

        let rec search (path: int list) =
            let tail =
                match path with
                | tail :: _ -> tail
                | _ -> -1
            let next = a.[tail]

            if towns.Contains next then
                let path = path |> List.rev
                let loopOrigin =
                    path |> List.findIndex (fun t -> t = next)
                loopOrigin, path
            else
                towns <- towns.Add next
                search (next :: path)

        search [0]

    let ans =
        let idx =
            let loopOrigin = int64 loopOrigin
            let freq = int64 (List.length path) - loopOrigin
            if k < loopOrigin then
                k |> int
            else
                loopOrigin + (k - loopOrigin) % freq |> int
        path.[idx] + 1

    ans

ans |> Console.WriteLine


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

using namespace std;

int A, B;
vector<int> CardsA, CardsB;

void solve() {
	int k, res;

	res = 0;
	for (int i = 0; i < B; ++i) {
		k = 0;
		for (int j = 0; j < A; ++j) {
			if (i + k < B && CardsA[j] == CardsB[i + k]) {
				++k;
			}
		}
		res = max(res, k);
	}
	cout << res << endl;
}

int main() {
	int num;

	cin >> A >> B;
	for (int i = 0; i < A; ++i) {
		cin >> num;
		CardsA.push_back(num);
	}
	for (int i = 0; i < B; ++i) {
		cin >> num;
		CardsB.push_back(num);
	}
	solve();

	return 0;
}


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

int main() {
  int n , k , q ;
  cin >> n >> k >> q ;
  vector<int> a(n) , b(q) ;
  
  for (int i = 0; i < q; i++) {
    cin >> b.at(i) ;
    int c=b.at(i);
    a.at(c-1)++;
  }

  for(int i = 0 ;i<n ;i++){
    if(k-q+a.at(i)>0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1408
#pragma warning( disable : 6031)

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
//const long long mod = 1000000007;
const long long mod = 998244353;
using std::vector;
using std::pair;
using std::string;
using std::map;
char left(char i, char j) {
	if (i == 'R') {
		if (j == 'G')return 'B';
		else return 'G';
	}
	else if (i == 'G') {
		if (j == 'R')return 'B';
		else return 'R';
	}
	else {
		if (j == 'R')return 'G';
		return 'R';
	}
}
int main() {
	int N;
	char S[4001];
	scanf("%d", &N);
	scanf("%s", S);
	long long R = 0, G = 0, B = 0;
	for (int i = 0; S[i] != 0; i++) {
		switch (S[i])
		{
		case 'R':
			R++;
			break;
		case 'G':
			G++;
			break;
		case 'B':
			B++;
			break;
		}
	}
	long long res = R * G * B;
	for (int i = 0; S[i] != 0; i++) {
		for (int j = i + 1; S[j] != 0; j++) {
			int k = 2 * j - i;
			if (S[i] != S[j] && k < N) {
				if (S[k] == left(S[i], S[j])) {
					res--;
				}
			}
		}
	}
	printf("%lld", res);
	return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;cin >> h >> w;
	char a[2*h][w];
	for(int i=0;i<2*h;i+=2){
		rep(j,w){
			cin >> a[i][j];
			a[i+1][j]=a[i][j];
		}
	}
	rep(i,2*h){
		rep(j,w){
			cout << a[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
  var x = chunk.split(" ");
  x[0] = Number(x[0])
  x[1] = Number(x[1])
  var op = "=="
  if (x[0] < x[1]) {
    op = "<"
  }else if (x[0] > x[1]) {
    op = ">"
  }
  console.log("a " + op + " b");
});

Measured memory_bytes: 15672
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    char x, y;
    cin >> x >> y;

    cout << ((x < y) ? '<' : (x == y) ? '=' : '>') << endl;

    return 0;
}



Measured memory_bytes: 384
// Problem : D - Preparing Boxes
// Contest : AtCoder - AtCoder Beginner Contest 134
// URL : https://atcoder.jp/contests/abc134/tasks/abc134_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
template <class T>
vector<T> divisor(T n) {
    vector<T> r;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            r.push_back(i);
            if (i * i != n)
                r.push_back(n / i);
        }
    }
    sort(r.begin(), r.end());
    return r;
}
void solve(){
	int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    rep(i,0, n) cin >> a[i + 1];
    vector<int> sum(n + 1, 0);
    set<int> s;
    for (int i = n; i; i--) {
        if (a[i] == sum[i] % 2)
            continue;
        else {
            s.insert(i);
            auto v = divisor(i);
            for (auto j : v)
                sum[j]++;
        }
    }
    cout << s.size() << endl;
    for (auto i = s.begin(); i != s.end(); i++)
        cout << *i << endl;
    return ;
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 12072