akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
 
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define F first
#define S second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
#define ld long double 
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pii > vpii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef map<char,int> mci;
 
#define itv for(auto it= v.begin(); it != v.end(); ++it )
 
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
 
 
#define bs binary_search
#define  lb(v,val)  lower_bound(ALL(v), val); 
 
#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl "\n";
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18 
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define vin(v,n)   vi v(n); rep(i,0,n)  cin>>v[i];
//#define siz  (int)1e8
#define N 300000



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

   vi h(n+1);

   rep(i,1,n+1)
   cin>>h[i];

   int dp[n+1];

   dp[1]=0;

   dp[2]=abs(h[2]-h[1]);

   rep(i,3,n+1)
   {


    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));




   }

   cout<<dp[n];

  




 
}
 
 
 
 
signed main()
{
 
 
   FAST
   
   int t; 
      t=1;              
  // cin>>t;
    while(t--)
    {
    
      quickly_quickly_kro();
      cout<<nl;
          
}
 
 
 

 
 
 
   return 0;
}

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

int main()
{
  unsigned long long jpy = 0;
  double btc = 0;
  int n;
  cin >> n;
  for(int i=0; i<n; i++)
  {
    double x;
    string u;
    cin >> x >> u;
    if(u == "JPY")
      jpy += x;
    else
      btc += x;
  }
  
  cout << fixed << setprecision(6) << (double)jpy + btc * 380000 << endl;
  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
//KASRA FOULADI;
int main(){
    bool b = true;
    int n, m;
    cin >> n >> m;
    char s[52][52];
    for(int i = 0; i < n; ++i)
        cin >> s[i];
    for(int i = 0; i < n && b; ++i)
        for(int j = 0; j < m && b; ++j)
            if(s[i][j] == '#')
                b = (i && s[i - 1][j] == '#') || (j && s[i][j - 1] == '#') || (i != n - 1 && s[i + 1][j] == '#') || (j != m - 1 && s[i][j + 1] == '#');
    if(b)
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
}

Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int, int> pii;

int m, n, N;
char mat[1002][1002];
int d[1002][1002];
int sx[10], sy[10];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int ans;

int bfs(int sx, int sy, int tx, int ty) {
  memset(d, -1, sizeof(d));
  d[sx][sy] = 0;
  queue<pii> q;
  q.push(make_pair(sx, sy));
  int x, y, xx, yy;
  while (!q.empty()) {
    pii cur = q.front();
    q.pop();
    x = cur.first;
    y = cur.second;
    for (int i = 0; i < 4; ++i) {
      xx = x + dx[i];
      yy = y + dy[i];
      if (xx >= 0 && xx < m && yy >= 0 && yy < n && mat[xx][yy] != 'X' && d[xx][yy] == -1) {
        d[xx][yy] = d[x][y] + 1;
        if (xx == tx && yy == ty) {
          return d[xx][yy];
        }
        q.push(make_pair(xx, yy));
      }
    }
  }

}

void solve() {
  ans = 0;
  for (int i = 0; i < m; ++i) {
    cin >> mat[i];
    for (int j = 0; j < n; ++j) {
      if (mat[i][j] == 'S') {
        sx[0] = i;
        sy[0] = j;
      } else if (mat[i][j] >= '1' && mat[i][j] <= '9') {
        int t = mat[i][j] - '0';
        sx[t] = i;
        sy[t] = j;
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    int tmp = bfs(sx[i - 1], sy[i - 1], sx[i], sy[i]);
    ans += tmp;
  }
}

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


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

using namespace std;

int main(void){

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

    vector<vector<char>> a(h, vector<char>(w));
    vector<bool> hv, wv;

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

    bool flag = true;
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(a[i][j] == '#') flag = false;
        }
        if(flag) wv.push_back(true);
        else wv.push_back(false);
        flag = true;
    }

    for(int i = 0;i < w;i++){
        for(int j = 0;j < h;j++){
            if(a[j][i] == '#') flag = false;
        }
        if(flag) hv.push_back(true);
        else hv.push_back(false);
        flag = true;
    }

    flag = true;
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(wv[i] == 0 && hv[j] == 0){
                cout << a[i][j];
                flag = false;
            }
        }
        if(!flag) cout << endl;
        flag = true;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
    int A,B,C,x,y;
    scanf("%d%d%d%d%d",&A,&B,&C,&x,&y);
    int ans = 0;
    int z = min(x,y), m = max(x,y);
    int tmp = C*2*m;
    if(A+B < C*2){
        ans += z*(A+B);
    }
    else ans += z*C*2;
    x -= z;
    y -= z;
    while(x) {
        ans += A;
        x --;
    }
    while(y){
        ans += B;
        y --;
    }
    ans = min(ans,tmp);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[n + 2] = {};

    int sum = 0;
    for( int i = 1; i <= n; ++i ) {
        cin >> a[i]; 
        sum += abs( a[i] - a[i - 1]);
    
    }
    sum += abs( 0 - a[n] );

    for( int i = 1; i <= n; ++i ) {
        int tmp = sum;
        tmp -= abs( a[i] - a[i - 1] );
        tmp -= abs( a[i + 1] - a[i] );
        tmp += abs( a[i + 1] - a[i - 1] );
        cout << tmp << endl;

    }
    
    
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>

int main() {
  std::string s, t, u;
  int a, b;
  std::cin >> s >> t >> a >> b >> u;
  if (s == u) --a;
  else --b;
  std::cout << a << " " << b << std::endl;
  
  return 0;
}

Measured memory_bytes: 3576
#include<stdio.h>
int Y[]={1,0,-1,0};
int X[]={0,1,0,-1};
int main(){
  int h,w,i,j,r=1,t,ny,nx,gx,gy,x[100010],y[100010],d[100][100]={};
  char s,g,m[100][100]={};
  scanf("%d %d %c %c",&h,&w,&s,&g);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      scanf(" %c",&m[i][j]);
      if(m[i][j]==g){
	gy=i;
	gx=j;
      }
      if(m[i][j]==s)m[y[t=0]=i][x[0]=j]='.';
    }
  }
  for(r=1;r-t;t++){
    for(i=0;i<4;i++){
      ny=y[t]+Y[i]*2;
      nx=x[t]+X[i]*2;
      if(m[ny][nx]!='-'&&i%2   )continue;
      if(m[ny][nx]!='|'&&i%2==0)continue;
      for(j=1;1;j++){
	if(m[ny+Y[i]*j][nx+X[i]*j]=='o')break;
      }
      ny=ny+Y[i]*(j+1);
      nx=nx+X[i]*(j+1);
      if(m[ny][nx]=='.')continue;
      m[y[r]=ny][x[r]=nx]='.';
      d[y[r]][x[r]]=d[y[t]][x[t]]+1;
      r++;
    }
  }/*printf("\n");
  for(i=0;i<h;i++)printf("%s\n",m[i+1]+1);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++)printf("%d",d[i][j]);
    printf("\n");
    }printf("%d %d\n",gy,gx);//*/
  printf("%d\n",d[gy][gx]);
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 10e9

using namespace std;
using P = pair<int, int>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

int A, B;
int main () {
  cin >> A >> B;

  if ((1 <= A && A <= 9) && (1 <= B && B <= 9)) {
    cout << A * B << "\n";
  } else {
    cout << -1 << "\n";
  }
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
ans = [-1]*n
A = [0]+A+[0]
s = 0
for i in range(1, n+2):
    s += abs(A[i]-A[i-1])
#print(s)
for i in range(n):
    temp = s
    temp -= abs(A[i+1]-A[i])
    temp -= abs(A[i+2]-A[i+1])
    temp += abs(A[i+2]-A[i])
    ans[i] = temp
for i in range(n):
    print(ans[i])


Measured memory_bytes: 58732
#!/usr/bin/env ruby

while n = gets.to_i
  # ????????????
  break if n.zero?

  # ??\???????????°?????????????????????
  ar = []
  n.times { ar << gets.to_i }

  len = ar.length
  total = []

  # ?°???????
  len.times do |offset|
    tmp = 0
    (len - offset).times do |n|
      tmp += ar[offset+n]
      total << tmp
    end
  end

  puts total.max
end

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int pow2(int x, int i) {
  rep(j, i) x *= 2;
  return x;
}

int main() {
  in(int, a, b, c, K);
  for (int i = 0; i <= K; ++i) {
    for (int j = 0; i + j <= K; ++j) {
      for (int k = 0; i + j + k <= K; ++k) {
        if (pow2(a, i) < pow2(b, j) && pow2(c, k) > pow2(b, j)) {
          out("Yes");
          return 0;
        }
      }
    }
  }
  out("No");
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;
int rank[7]={};
int judge(double m){
	if(m<165.0)rank[1]++;
	else if(m>=165.0&&m<170.0)rank[2]++;
	else if(m>=170.0&&m<175.0)rank[3]++;
	else if(m>=175.0&&m<180.0)rank[4]++;
	else if(m>=180.0&&m<185.0)rank[5]++;
	else rank[6]++;
}	
int main(){
	int n;
	double m;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>m;
		judge(m);
	}
	for(int i=1;i<7;i++){
		cout<<i<<':';
		for(int j=0;j<rank[i];j++)cout<<'*';
		cout<<endl;
	}
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i+=2)
    {
        int divCnt = 0;
        for (int j = 1; j <= i; j++)
        {
            if (i % j == 0)
            {
                divCnt++;
            }
        }
        if (divCnt == 8)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
const int N=10005;
int n,m,p,u,v,d,cnt,ee,head[N],dis[N],tot[N],to[N*2],nxt[N*2],dd[N*2];
queue<int> q;
bool inq[N];
void adde(int u,int v,int d){
	to[++cnt]=v;
	nxt[cnt]=head[u];
	dd[cnt]=d;
	head[u]=cnt;
}
int spfa(){
	while(!q.empty()){
		q.pop();
	}
	for(int i=1;i<=n;i++){
		dis[i]=-2e9;
		inq[i]=false;
		tot[i]=0;
	}
	dis[1]=0;
	inq[1]=true;
	q.push(1);
	tot[1]=1;
	while(!q.empty()){
		ee++;
		if(ee>1e7){
			break;
		}
		int u=q.front(),v;
		q.pop();
		inq[u]=false;
		for(int i=head[u];i;i=nxt[i]){
			v=to[i];
			if(dis[u]+dd[i]>dis[v]){
				dis[v]=dis[u]+dd[i];
				if(!inq[v]){
					inq[v]=true;
					q.push(v);
					tot[v]++;
					if(tot[n]>n){
						return -2e9;
					}
				}
			}
		}
	}
	if(tot[n]>n){
		return -2e9;
	}
	return dis[n];
}
int main(){
	scanf("%d%d%d",&n,&m,&p);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&u,&v,&d);
		adde(u,v,d);
	}
//	if(spfa()==-2e9){
//		puts("-1");
//		return 0;
//	}
	for(int i=1;i<=m;i++){
		dd[i]-=p;
	}
	printf("%d\n",spfa()==-2e9?-1:max(0,dis[n]));
	return 0;
}
/*
4 4 0
1 2 1
2 3 1
3 2 1
1 4 1
*/


Measured memory_bytes: 384
import java.util.*;
public class Main{
   

  public static long ways(char matrix[][],int n,int m,int i,int j,long dp[][])
  {
	  
	  if(matrix[i][j]=='#') {
		  dp[i][j]=0;
		  return 0;}
	  if(i==n-1&&j==m-1)
		  return 1;
	  if(dp[i][j]==-1) {
	  int dx=i+1;
	  int dy=j;
	  int rx=i;
	  int ry=j+1;
	  long op1=0,op2=0;
	  if(dx<n&&dy<m)
	  {
		if(dp[dx][dy]==-1)
			op1=(ways(matrix,n,m,dx,dy,dp))%1000000007;
		else
			op1=dp[dx][dy];
	  }
	  if(rx<n&&ry<m)
	  {
		if(dp[rx][ry]==-1)
			op2=ways(matrix,n,m,rx,ry,dp)%1000000007;
		else
			op2=dp[rx][ry];
	  }
	  dp[i][j]=(op1+op2)%1000000007;
	  
	  
	  }
	  return dp[i][j];
  }
	
  public static void main(String[] args)
  {
     
  Scanner s=new Scanner(System.in);
  int n=s.nextInt();
  int m=s.nextInt();
  char matrix[][]=new char[n][m];
  for(int i=0;i<n;i++)
  {
	String line=s.next();
	String str[]=line.split("");
	  for(int j=0;j<m;j++) {
		  matrix[i][j]=str[j].charAt(0);}
  }
  long dp[][]=new long[n][m];
  for(int i=0;i<n;i++)
  {
	  for(int j=0;j<m;j++)
	  {
		  dp[i][j]=-1;
	  }
  }
//  for(int p=0;p<n;p++)
//  {
//	  for(int q=0;q<m;q++)
//		 System.out.print(matrix[p][q]+" ");
//	  System.out.println();
//  }
// 
  System.out.println( ways(matrix,n,m,0,0,dp));
  
  s.close();
    
  }
}


Measured memory_bytes: 64292
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ax = sc.nextInt();
        int ay = sc.nextInt();
        int bx = sc.nextInt();
        int by = sc.nextInt();

        int dx = bx-ax;
        int dy = by-ay;

        System.out.print((bx + (-1)*dy) + " " + (by + dx)+ " ");

        int cx = (bx + (-1)*dy);
        int cy = (by + dx);

        int tmp = dx;
        dx = (-1)*dy;
        dy = tmp;


        System.out.print((cx+(-1)*dy) + " " + (cy + dx));
        System.out.println();


    }
}

Measured memory_bytes: 25300
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};


int main(){
  ll k;cin>>k;
  string s;cin>>s;
  if(s.size()<=k){
    cout<<s<<endl;

  }
  else {
    rep(i,k)cout<<s[i];
    cout<<"."<<"."<<"."<<endl;
  }
}

Measured memory_bytes: 3632
def solve():
    S = input()
    N = len(S)
    MOD = 10 ** 9 + 7

    dp = [[0] * 13 for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(13):
            if S[i] != '?':
                dp[i+1][(10 * j + int(S[i])) % 13] += dp[i][j] % MOD
            else:
                for k in range(0,10):
                    dp[i+1][(10 * j + k) % 13] += dp[i][j] % MOD
    
    print(dp[-1][5] % MOD)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 88220
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
    int mountains[10];
    for(int i=0;i<10;++i){
        cin >> mountains[i];
    }
    sort(mountains, mountains+10, greater<int>());
    for(int i=0;i<3;++i){
        cout << mountains[i] << endl;
    }
}

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


struct node{
  int base=-2;
  int lx=10000;
  int rx=-1000;
  double g=0;
};
int w,h;

vector<node> node;

bool isok;
bool isrange(int i,int j){return 0<=i && i<h && 0<=j && j<w;};
int dh[]={1,-1,0,0};
int dw[]={0,0,1,-1};

pair<int,double> check(int base){

  int cnt=0;
  for(int i=0;i<node.size();i++){
    if(node[i].base==base){
      cnt++;
    }
  }
  
  if(cnt==0){
    if(!(node[base].lx<node[base].g && node[base].g<node[base].rx)) isok=false;
    return {1,node[base].g};
  }
  double g=0;
  int cn=0;
  for(int i=0;i<node.size();i++){
    if(node[i].base==base){
      auto ret=check(i);
      cn+=ret.first;
      g+=ret.second*ret.first;
    }
  }
  g/=cn;
  g=(g*cn+node[base].g)/(cn+1);
  isok&=(node[base].lx<g && g<node[base].rx);
  return {cn+1,g};
}

void make_node(int num,vector<vector<int>> &c){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(c[i][j]==num){
	node[num].g+=j+1.0/2;
	if(i==0){
	  node[num].base=-1;
	  node[num].lx=min(node[num].lx,j);
	  node[num].rx=max(node[num].rx,j+1);
	}
	else if(c[i-1][j]>=0 && c[i-1][j]!=num){

	  node[num].base=c[i-1][j];
	  node[num].lx=min(node[num].lx,j);
	  node[num].rx=max(node[num].rx,j+1);
	}
      }
    }
  }
  node[num].g/=4;
  return;
}

void nummer(int i,int j,int num,const char org,vector<vector<char>> &b,vector<vector<int>> &c){
  if(c[i][j]!=-1) return;
  c[i][j]=num;
  for(int dir=0;dir<4;dir++){
    int toh=i+dh[dir];
    int tow=j+dw[dir];
    if(isrange(toh,tow) && b[toh][tow]==org){
      nummer(toh,tow,num,org,b,c);
    }
  }
  return;
}

int main(){
  while(cin>>w>>h,w){
    vector<vector<char>> b(h,vector<char>(w));
    for(int i=h-1;i>=0;i--){
      for(int j=0;j<w;j++){
	cin>>b[i][j];
      }
    }
    vector<vector<int>> c(h,vector<int>(w,-1));
    int number=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(c[i][j]==-1 && isdigit(b[i][j])){
	  nummer(i,j,number,b[i][j],b,c);
	  number++;
	}
      }
    }
    node.clear();
    node.resize(number);
    for(int i=0;i<number;i++){
      make_node(i,c);
    }
    isok=true;

    int base=-2;

    for(int i=0;i<number;i++){
      if(node[i].base==-1){
	base=i;
	break;
      }
    }

    check(base);
    cout<<(isok?"STABLE":"UNSTABLE")<<endl;
  }
  return 0;
}

Measured memory_bytes: 2968
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i <= ((int)s.length() - 1) / 2; i++) if (s[i] != s[(int)s.length() - 1 - i]) ans++;
	cout << ans;

	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    n+=1;
    vector <int> a(n);
    int s = 0;
    for(int i =0; i <n; ++i){
        cin >> a[i];
        s += a[i];
    }
    int o = 1;
    int q=1;    
    int r=1;
    for(int i = 0; i < n; ++i){
        if(s == 0)break;
        if(a[i] > r){
            q = 0;
        }
        else {
            r -= a[i];
            s -= a[i];
        }
        if(s == 0)break;
        /*if(r == s){
            for(int j = i+1; j < n; ++j){
                o += (a[j])*(j-i);
            }
            break;
        }
        else */
        if(2*r >= s){
            for(int j = i+1; j < n; ++j){
                o += (a[j])*(j-i);
            }
            break;
        }
        o += 2*r;
        r *= 2;

    }
    if(q)cout << o << '\n';
    else cout <<"-1\n";
}


Measured memory_bytes: 3988
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define revrep(i, n) for (int i=int(n)-1; i>=0; i--)
#define all(c) (c).begin(), (c).end()

#define MAX_N 1010
#define MAX_M 1010
int N, M;
int D[MAX_N];
int C[MAX_M];

int dp[MAX_N][MAX_M];

const int INF = 1<<29;

int main() {
  cin >> N >> M;

  rep(i, N) cin >> D[i];
  rep(i, M) cin >> C[i];

  rep(i, MAX_N) rep(j, MAX_M) dp[i][j] = INF;
  dp[0][0] = 0;

  //for (int pos=N+1; pos>=0; pos--) {
    //for (int day=M-1; day>=0; day--) {
  for (int pos=0; pos<N; pos++) {
    for (int day=0; day<M; day++) {
      dp[pos  ][day+1] = min(dp[pos][day+1],   dp[pos][day]);
      dp[pos+1][day+1] = min(dp[pos+1][day+1], dp[pos][day] + D[pos]*C[day]);
    }
    //rep(i, M+1) cout << ": " <<dp[N][i] <<"\n"; // DEBUG
    //cout << "###########\n";
  }
  int ans = INT_MAX;
  rep(i, M+1) ans = min(ans, dp[N][i]);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7096
#include <iostream>

main(){
        int a, b;
        std::cin >> a >> b;

        if( a < b ){
                std::cout << "a < b" << std::endl;
        } else if ( a == b ) { 
                std::cout << "a == b" << std::endl;
        } else {
                std::cout << "a > b" << std::endl;
        }

}

Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include <bitset>


//#define int long long
using namespace std;

int g[132000],h[132000];
int t[30];
int MAX = 0, Max = 0;
int Stay[100], Change[100];
int NS, NC;
int Check[132000];

int c(int a) {
	if (a == 0) {
		return 1;
	}
	else if (a == 1) {
		return 0;
	}
	else {
		cout << "error input is not 0 nor 1" << endl;
	}
}

void T(int i) {
	if (i == 0) {
		t[0] = 1;
	}
	else {
		t[i] = t[i - 1] * 2;
	}
}

void H(int i) {
	if (i == t[Max]) {
		Max++;
		h[i] = Max;
	}
	else {
		h[i] = h[i - t[Max - 1]];
	}
}

bool flag = false;
void G(int i) {
	static int C = 0;
	if (g[i] != 0) return;
	if (i == t[MAX]) {
		MAX++;
		g[i] = MAX;
		flag = false;
		if (MAX%2==1 && i > 2) {
			g[i + 1] = MAX - 1;
			g[i * 3 / 2 + 1] = MAX - 1;
			flag = true;
			C = i;
		}
	}
	else {
		if (flag) {
			g[i] = h[i - C - 1];
			if (i > C * 3 / 2) {
				g[i] = g[i - C * 3 / 2] -1;
				if (g[i] == 0) {
					g[i] = MAX -2;
				}
			}
		}
		else {
			g[i] = g[i - t[MAX - 1]];
		}
	}
}

int N, A, B;
int C;
int COUNT;
int ans;

signed main()
{
	for (int i = 0; i < 25; i++)T(i);
	for (int i = 1; i < 132000; i++)H(i);
	for (int i = 1; i < 132000; i++)G(i);
	/*
	for (int i = 1; i < 20; i++) {
		cout << g[i] << " ";
	}*/

	cin >> N >> A >> B;

	C = A ^ B;
	for (int i = 0; i < N; i++) {
		if (C&(1 << i)) {
			COUNT++;
			NC++;
			Change[NC]= i;
		}
		else {
			NS++;
			Stay[NS]=i;
		}
	}
	if (COUNT % 2 == 0) {
		cout << "NO" << endl;
		return 0;
	}
	else {
		cout << "YES" << endl;
	}
	ans = A;

	
	for (int i = 1; i <= t[NC]; i++) {
		for (int j = 1; j < t[NS]; j++) {
			//cout << bitset<10>(ans) << endl;
			cout << ans << " ";
			Check[ans]++;
			if (Check[ans] == 2) {
				cout << "OUT" << endl;
				system("pause");
				return 0;
			}
			ans = ans ^ (1 << (Stay[g[j]]));
		}
		//cout << bitset<10>(ans) << endl;
		cout << ans << " ";
		Check[ans]++;
		if (Check[ans] == 2) {
			cout << "OUT" << endl;
			system("pause");
			return 0;
		}
		ans = ans ^ (1 << (Change[g[i]]));
	}
	cout << endl;
	//system("pause");
    return 0;
}



Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, a: "List[int]", b: "List[int]"):
    conn = [[] for _ in range(N)]
    for i in range(N - 1):
        conn[a[i] - 1].append(b[i] - 1)
        conn[b[i] - 1].append(a[i] - 1)

    def dfs(idx, cur, conn, dis):
        dis[idx] = cur
        for nex in conn[idx]:
            if dis[nex] is None:
                dfs(nex, cur + 1, conn, dis)
        return None

    f_dis = [None] * N
    f_dis[0] = 0
    dfs(0, 0, conn, f_dis)

    s_dis = [None] * N
    s_dis[N - 1] = 0
    dfs(N - 1, 0, conn, s_dis)

    cnt = 0
    for i in range(N):
        if f_dis[i] <= s_dis[i]:
            cnt += 1

    if cnt > (N - cnt):
        ret = 'Fennec'
    else:
        ret = 'Snuke'
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 224860
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map(String::toInt)
    var count = 0
    for (i in a..b) {
        val chars = i.toString().toCharArray()
        if (chars[0] == chars[4] && chars[1] == chars[3]) count++
    }
    println(count)
}

Measured memory_bytes: 40436
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int A, B;
	cin >> A >> B;

	if (A == B) cout << "Draw" << endl;
	else if ((A == 1) || (A > B && B != 1)) cout << "Alice" << endl;
	else cout << "Bob" << endl;

	return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let s: String = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    };
    let t: String = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    };

    let A = s.len();
    let B = t.len();
    let ans = A + B - (1..(std::cmp::min(s.len(), t.len()) + 1)).rev().find(|&k| s[A - k..] == t[..k]).unwrap_or(0);

    println!("{}", ans);
}

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

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

const ll mod = 1e9+7;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    vector<int>c(3, -1);
    ll ans = 1;

    for(int i = 0 ; i < n; i++){
        int cnt = 0;
        for(int j = 0; j < 3; j++){
            if(a[i] == c[j]+1) cnt++ ;
        }
        ans *= cnt;
        ans %= mod;

        if(a[i] == c[0]+1) c[0]++;
        else if(a[i] == c[1]+1) c[1]++;
        else c[2]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin >> s;
    bool bad = false;
    rep(i, 0, sz(s) - 1) {
        if (s[i] == s[i + 1]) {
            bad = true;
        }
    }
    cout << (bad ? "Bad" : "Good") << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int n, m;
    cin >> n >> m;

    vector<pair<int,int>> a(n + 2);

    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }

    a[n] = {0, 0};
    a[n + 1] = {1000000001, 0};

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

    n += 1;

    for (int i = 0; i < n; ++i)
        a[i].second ^= a[i + 1].second;

    vector<vector<pair<int,int>>> adj(n);
    vector<bool> seen(n);

    for (int i = 0; i < m; ++i) {
        int l, r; cin >> l >> r;
        auto li = lower_bound(a.begin(), a.end(), pair<int,int>(l, 0)) - a.begin() - 1;
        auto ri = upper_bound(a.begin(), a.end(), pair<int,int>(r, 1)) - a.begin() - 1;

        adj[li].push_back({ri, i + 1});
        adj[ri].push_back({li, i + 1});
    }

    set<int> ans;

    function<bool(int)> go = [&](int u) {
        seen[u] = true;

        for (auto e : adj[u]) {
            if (seen[e.first])
                continue;

            if (go(e.first)) {
                ans.insert(e.second);
                a[u].second ^= 1;
            }
        }

        return a[u].second;
    };

    for (int i = 0; i < n; ++i) {
        if (seen[i])
            continue;

        if (go(i)) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans.size() << endl;

    for (auto x : ans)
        cout << x << " ";
    cout << endl;


    return 0;
}

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

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


int main(){
    int A,B;
    cin >> A >> B;
    int AB = A+B;
    if(AB<24)cout << AB << endl;
    else cout << AB-24 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int h, n; scanf("%d%d", &h, &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	int sum = 0;
	for(auto v: a) sum += v;

	if(h <= sum) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 640
//ksun48 - just to mark ac
#include <bits/stdc++.h>
using namespace std;


int main(){
	int n;
	cin >> n;
	vector<int> b(n);
	for(int i = 0; i < n; i++){
		cin >> b[i];
		b[i]--;
	}
	vector<int> ans;
	while(b.size() > 0){
		int z = -1;
		for(int i = 0; i < b.size(); i++){
			if(b[i] == i) z = i;
		}
		if(z == -1){
			cout << -1 << endl;
			exit(0);
		}
		ans.push_back(z);
		b.erase(b.begin() + z);
	}
	reverse(ans.begin(), ans.end());
	for(int x : ans){
		cout << x + 1 << '\n';
	}
}


Measured memory_bytes: 256
import scala.math._
import scala.collection.mutable.ListBuffer

object Main {
  //rt.gc()??§??¬??????????????¬?????????????????????
  //val rt = Runtime.getRuntime()
  val sc = new java.util.Scanner(System.in)
  def isPrime(n: Int): Boolean =  {
    if(n == 1) {
      return false
    }
    var i = 2
    while(i*i <= n) {
      if(n % i == 0) {
        return false
      }
      i += 1
    }
    return true
  }
  def main(args: Array[String]) {
    val twinPrimes = (for {
      i <- 5 to 10000
      if isPrime(i)
        if isPrime(i-2)
      } yield {
      (i-2, i)
    }).toList
    while(true) {
      val n = sc.nextInt
      if(n == 0) {
        return
      }
      val (p, q) = twinPrimes.filter(_._2 <= n).last
      println(p + " " + q)
    }
  }
}

Measured memory_bytes: 92820
from heapq import *
n,m,s=map(int,input().split())
c=[0]*n
d=[0]*n
g=[[]for i in range(n)]

for i in range(m):
    u,v,a,b=map(int,input().split())
    u-=1
    v-=1
    g[u].append((v,a,b))
    g[v].append((u,a,b))
for i in range(n):
    c[i],d[i]=map(int,input().split())

flag=0 #if this == (1<<n)-1 then finish roop
lasttime=[[10**15]*2501 for i in range(n)]
lasttime[0][min(2500,s)]=0
mintimes=[10**15]*n
hp=[(0,min(2500,s),0)]#(time,silver,node)

while flag!=((1<<n)-1):
    time,silver,node = heappop(hp)
    flag=flag|(1<<node)
    mintimes[node]=min(mintimes[node],time)

    for atnode,costmoney,costtime in g[node]:
        nexttime,nextsilver=time+costtime,silver-costmoney
        if costmoney<=silver and lasttime[atnode][nextsilver]>nexttime:
            heappush(hp,(nexttime,nextsilver,atnode))
            lasttime[atnode][nextsilver]=min(lasttime[atnode][nextsilver],nexttime)

    nexttime,nextsilver=time+d[node],min(silver+c[node],2500)
    if silver!=2500 and lasttime[node][nextsilver]>nexttime:
        heappush(hp,(nexttime,min(silver+c[node],2500),node))
        lasttime[node][nextsilver]=min(lasttime[node][nextsilver],nexttime)
        
print(*mintimes[1:],sep="\n")

Measured memory_bytes: 91520
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = k; i < n; i++) {
            if(a[i - k] < a[i]) System.out.println("Yes");
            else System.out.println("No");
        }
    }
}

Measured memory_bytes: 60656
#i文字目を見て，それより前のAの個数，ABの個数，ABCの個数を持っておく

S=input()
N=len(S)
dp=[0,0,0]

mod=10**9+7


count=0#?の数
for i in range(N):
    if S[i]=="A":
        dp[0]=(dp[0]+pow(3,count,mod)) %mod
    elif S[i]=="B":
        dp[1]=(dp[1]+dp[0])%mod
    elif S[i]=="C":
        dp[2]=(dp[2]+dp[1])%mod
    else:
        dp[2]=(dp[2]*3+dp[1])%mod
        dp[1]=(dp[1]*3+dp[0])%mod
        dp[0]=(dp[0]*3+pow(3,count,mod))%mod
        count+=1
        
print(dp[2]%mod)   







Measured memory_bytes: 40304
a = list(input())
b = list(input())

c = []

aa = len(a)
bb = len(b)

if aa == bb:
    for i in range(aa):
        x = a[i] 
        y = b[i]
        c.append(x)
        c.append(y)
else:
    m = a.pop(-1)
    for i in range(aa -1):
        x = a[i] 
        y = b[i]
        c.append(x)
        c.append(y)
    c.append(m)
        
print(''.join(c))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  double w,h,x,y,k=2;
  cin >>w>>h>>x>>y;
  printf("%.16f ",(w*h)/k);
  if(w/k==x&&h/k==y) cout <<1<<endl;
  else cout <<0<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>

int main()
{
  int N;
  std::cin >> N;
  std::map<std::string, int> point;
  for ( int i = 0; i < N; i++ ) {
    std::string s;
    std::cin >> s;
    point[s]++;
  }

  int M;
  std::cin >> M;
  for ( int i = 0; i < M; i++ ) {
    std::string s;
    std::cin >> s;
    point[s]--;
  }
  int max = 0;
  for ( auto it = point.begin(); it != point.end(); it++ ) {
    int count = it->second;
    if ( max < count ) {
      max = count;
    }
  }
  if (max < 0) max = 0;
  std::cout << max << std::endl;
  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}
int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    vector<ll> tel(1000100);

    rep(i,1000100){
        if(i==0) tel[i] = 1;
        else{
            tel[i] = a[tel[i-1]-1];
        }
    }

    ll x = 0;
    ll ans1;

    rrep(i,1000100){
        if(i == 1000099) x++;
        else if(tel[i] == tel[1000099]){
            ans1 = x;
            break;
        }
        else x++;
    }

    ll ans2 = 0;

    rep(i,1000100){
        if(tel[i] == tel[i+ans1]) ans2 = i;
    }

    ll an = (k - ans2) % ans1;

    if(k <= 1000100) cout << tel[k] << endl;

    else cout << tel[ans2 + an] << endl;


    return 0;
}

Measured memory_bytes: 12728
#include<iostream>
using namespace std;
const int mod=998244353;
int n;
long long ans,ji[10000007];
long long qpow(long long a,long long b) {
	long long res=1;
	long long now=a%mod;
	while (b) {
		if (b&1) res=res*now%mod;
		now=now*now%mod;
		b>>=1;
	}
	return res;
}
void init(){
	ji[0]=1;
	for (int i=1; i<=n; i++) ji[i]=ji[i-1]*i%mod;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	init();
	ans=qpow(3,n);
	for (int i=(n/2)+1; i<=n; i++) {
		ans=(ans-2*(((((ji[n]*qpow(ji[i],mod-2))%mod)*qpow(ji[n-i],mod-2))%mod)*qpow(2,n-i)%mod))%mod;
	}
	cout<<(ans+mod)%mod<<endl;
	return 0;
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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;}


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

  if(N%2==1){
    cout << 0 << endl;
    return 0;
  }

  N/=2;
  ll ans=0;
  for(ll i=5;i<=N;i*=5){
    ans+=N/i;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3620
from collections import deque
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

Q = deque([A[0]])
for a in A[1:]:
    if a <= Q[0]:
        Q.appendleft(a)
    else:
        idx = bisect.bisect_left(Q,a)
        Q[idx-1] = a

print(len(Q))

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

typedef struct{
	int num;
	double money;
}bank;

int main(void){
	while(1){
		int n, y, r, t, i;
		bank b[50];
		
		scanf(" %d", &n);
		if(n==0) break;
		
		scanf(" %d", &y);
		for(i=0; i<n; i++){
			scanf(" %d %d %d", &b[i].num, &r, &t);
			
			if(t==1){
				b[i].money = 1 + y*r/100.0;
			}
			else if(t==2){
				b[i].money = pow( (1+r/100.0), y);
			}
			
		}
		
		double max = b[0].money;
		int index = 0;
		
		for(i=0; i<n; i++){
			if(max < b[i].money){
				max=b[i].money;
				index = i;
			}
		}
			
		printf("%d\n", b[index].num);
	
	}

	return 0;
}

Measured memory_bytes: 692
using System;

public class Hello{
    public static void Main(){
        string[] str = Console.ReadLine().Split();
       int a = int.Parse(str[0]);
       int b = int.Parse(str[1]);
       int c = int.Parse(str[2]);
        if(a<b&& b<c){
           Console.WriteLine("Yes");
        }else{  
           Console.WriteLine("No");
           
       }
    }
}


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

using namespace std;
typedef long long LL;

int main(){
    int N, M;
    LL T[101], X[101];
    int P[101];

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

    cin >> M;
    for(int i = 1; i <= M; ++i){
        cin >> P[i] >> X[i];
    }

    LL ans = 0;
    for(int i = 1; i <= N; ++i){
        ans += T[i];
    }

    for(int i = 1; i <= M; ++i){
        cout << ans - T[P[i]] + X[i] << endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if (a >= b && a >= c) {
        a *= 10;
    } else if (b >= a && b >= c) {
        b *= 10;
    } else {
        c *= 10;
    }
    printf("%d\n",a + b + c);
    return 0;
}


Measured memory_bytes: 128
n = int(input())
a = [int(i) for i in input().split()]

b = []

for i in range((n+1)//2):
    #print(i)
    b.append(a[n-1-2*i])

even = False

if n % 2 == 0:
    even = False
else:
    even = True

if even == True:
    for i in range(n//2):
        b.append(a[1+2*i])
else:
    for i in range(n//2):
        b.append(a[2*i])
    

print(*b)

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

vector<pair<int, int> > x;

int main(void)
{
	int N;

	cin >> N;

	int i;
	for (i = 0; i < N; i++)
	{
		int a, b;
		cin >> a >> b;
		x.emplace_back(b,a);
	}
	std::sort(x.begin(),x.end());

	int time = 0;
	bool flag = true;
	for ( auto v : x )
	{
		time += v.second;
		if (time > v.first)
		{
			flag = false;
			break;
		}
	}
	if (flag)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int d[2002][2002];
int sa[4002][2002], sb[4002][2002], n;
int oa[2002], ob[2002];

int f(int i1, int i2) {
	if(i1>n && i2>n) return 0;
	if(d[i1][i2]>=0) return d[i1][i2];
	int res=(1<<30);
	if(i1<=n) {
		int cost=abs(oa[i1]+sa[2*n][i1-1]-sa[oa[i1]][i1-1]+
				sb[2*n][i2-1]-sb[oa[i1]][i2-1]-(i1+i2-1));
		res=min(res,f(i1+1,i2)+cost);
	}
	if(i2<=n) {
		int cost=abs(ob[i2]+sa[2*n][i1-1]-sa[ob[i2]][i1-1]+
				sb[2*n][i2-1]-sb[ob[i2]][i2-1]-(i1+i2-1));
		res=min(res,f(i1,i2+1)+cost);
	}
	return d[i1][i2]=res;
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++) {
		char c;
		int w;
		scanf(" %c %d",&c,&w);
		if(c=='W') {
			sa[i][w]=1;
			oa[w]=i;
		} else {
			sb[i][w]=1;
			ob[w]=i;
		}
	}
	memset(d,-1,sizeof(d));
	for(int i=1;i<=2*n;i++) {
		for(int j=1;j<=n;j++) {
			sa[i][j]=sa[i][j-1]+sa[i-1][j]-sa[i-1][j-1]+sa[i][j];
			sb[i][j]=sb[i][j-1]+sb[i-1][j]-sb[i-1][j-1]+sb[i][j];
		}
	}
	printf("%d\n",f(1,1));
	return 0;
}

Measured memory_bytes: 78720