akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

class Triangle {
public:
  ll x0, x1, x2;
  ll y0, y1, y2;
  ll s;

  Triangle(ll _x0, ll _y0, ll _x1, ll _y1, ll _x2, ll _y2, ll _s) {
    x0 = _x0; x1 = _x1; x2 = _x2;
    y0 = _y0; y1 = _y1; y2 = _y2;
    s = _s;
  }

  ll area2() {
    return abs((x0-x2)*(y1-y2) - (x1-x2)*(y0-y2));
  }

  ll diff() {
    return y2*y2 - s;
  }

  void out() {
    printf("%lld %lld %lld %lld %lld %lld\n", x0, y0, x1, y1, x2, y2);
  }
};

ll bs(ll s) {
  ll ng = 0, ok = 1e9;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (mid*mid - s >= 0) {
      ok = mid;
    } else {
      ng = mid;
    }
    // cout << ng << ", " << mid << ", " << ok << endl;
  }
  return ok;
}

int main() {
  ll s; cin >> s;
  Triangle t(0,0,1,0,0,1, s);
  t.x1 = t.y2 = bs(s);
  if (t.diff() == 0)  {
    t.out();
    return 0;
  }
  t.y1 = 1; t.x2 = 1;
  ll n = t.x1, d = t.diff() - 1;
  if (d >= n) {
    t.x1--;
    d %= n;
  }
  t.y1 += d;
  t.out();
  return 0;
}


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

bool isArithmeticProgression(const vector<int>& grasses)
{
  int diff = grasses[1] - grasses[0];
  for (int i = 1, size = grasses.size(); i < size - 1; ++i)
  {
    if (grasses[i+1] - grasses[i] != diff) return false;
  }
  return true;
}

int solve(const vector<int>& grasses)
{
  for (int i = 0, size = grasses.size(); i < size; ++i)
  {
    vector<int> grasses2 = grasses;
    grasses2.erase(grasses2.begin() + i);
    if (isArithmeticProgression(grasses2))
    {
      return grasses[i];
    }
  }
  return -1;
}

int main(void)
{
  while (true)
  {
    int n;
    cin >> n;
    if (n == 0) break;

    vector<int> grasses(n+1);
    for (auto& g : grasses)
    {
      cin >> g;
    }

    cout << solve(grasses) << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s)
	for i := 1; i < len(s); i++ {
		t = s[:len(s)-i]
		if t[:len(t)/2] == t[len(t)/2:] {
			fmt.Println(len(t))
			return
		}
	}
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{

	int h, m, s, i;
	int time[3];

	for(i = 0; i < 3; i++) {
		scanf("%d %d %d", &h, &m, &s);
		time[i] = (h * 3600) + (m * 60) + s;
		scanf("%d %d %d", &h, &m, &s);
		time[i] = ((h * 3600) + (m * 60) + s) - time[i];
	}

	for(i = 0; i < 3; i++) {
		printf("%d %d %d\n", time[i] / 3600, (time[i] % 3600) / 60, time[i] % 3600 % 60);
	}

	return 0;

}

Measured memory_bytes: 600
#include "bits/stdc++.h"
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 reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll a, b, c, k;

	cin>>a>>b>>c>>k;

	if(k%2){
		cout<<b-a<<endl;
	}else{
		cout<<a-b<<endl;
	}
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        boolean ans = false;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j < m; j++) {
                int t = i * j + (n-i)*(m-j);
                if(t == k) ans = true;
                if(ans)break;
            }
            if(ans)break;
        }
        System.out.println(ans ? "Yes" : "No");
        sc.close();

    }

}


Measured memory_bytes: 23764
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    for(int i=0;i<n;i++){
      arr[i]=sc.nextInt();
    }
    int c =arr[0];
    for(int i=1;i<n;i++){
      c=(c^arr[i]);
    }
    if(c==0){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}



Measured memory_bytes: 50420
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, k;
  cin >> n >> k;
  vld p(n);
  rep(i, n){
    cin >> p[i];
  }
  rep(i, n){
    p[i] = (p[i]+1)/2;
  }
  dump(p);
  ld tmp = 0;
  ld ans = -INF;
  rep(i, k){
    tmp += p[i];
  }
    chmax(ans, tmp);
  repr(i, k, n){
    dump(tmp);
    chmax(ans, tmp);
    tmp += p[i];
    tmp -= p[i-k];
    chmax(ans, tmp);
    dump(tmp);
  }
  print(ans);
}


Measured memory_bytes: 3456
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class APoor {
public:
    void solve(std::istream& in, std::ostream& out) {
        int a, b, c;
        in >> a >> b >> c;
        bool yes = a == b && a != c || b == c && a !=c || a == c && b != c;
        out << (yes ? "Yes" : "No") << "\n";
    }
};


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


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

template <class T> inline T square(T x) {
  T result;
  result = x * x;
  return result;
};

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

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

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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  auto start = chrono::steady_clock::now();
#endif

  string s,t;cin >> s>>t;auto n = s.size();

  for(auto i = 0;i<n;++i){
  	if(s[i] != t[i]){
  		print("No");
  		return 0;
  	}
  }

  print("Yes");

#ifdef LOCAL
      auto end = chrono::steady_clock::now();
  auto diff = end - start;

  cout << "Duration: " << chrono::duration<double, milli>(diff).count() << " ms"
       << '\n';
#endif

  return 0;
}


Measured memory_bytes: 3608
package main

import "fmt"
import "math"

func main(){
	var N, min int;
	fmt.Scan(&N);

	x := int(math.Sqrt(float64(N)));

	for i := x+1 ; i>= 1; i--{
		if N%i == 0 {
			min = (i-1)+(N/i-1);
			break;
		}
	}
	fmt.Println(min);
}

Measured memory_bytes: 512
N = int(input())
D_list = list(map(int, input().split()))
if D_list[0]:
    print(0)
    exit()

branchs = [0] * N
MOD = 998244353

for d in D_list:
    branchs[d] += 1

if branchs[0] != 1:
    print(0)
    exit()

cnt = 1
for v1,v2 in zip(branchs, branchs[1:]):
    cnt *= v1**v2 % MOD
    
print(cnt%MOD)


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

using namespace std;

int sq(int x)
{
	return x*x;
}

int getzsq(int h, int w)
{
	return sq(h)+sq(w);
}

int main()
{
	while(1)
	{
		int h, w;
		float z;
		cin >> h >> w;
		if (h==0&&w==0) break;
		float zsq=getzsq(h, w);
		float minzsq=20000;
		int ansh,answ;
		for (int i=1;i<=100;i++)
		{
			int wmin = ceil(sqrt(zsq-sq(i)));
			if ((float)wmin==sqrt(zsq-sq(i))&&(i>h)&&(wmin>i))
			{
				ansh = i;
				answ = wmin;
				break;
			}
			for (int j=max(wmin, i+1);j<=150;j++)
			{
				if((getzsq(i, j)>zsq)&&(getzsq(i, j)<minzsq)&&!(i==h&&j==w))
				{
					minzsq=getzsq(i, j);
					ansh = i;
					answ = j;
					break;
				}
			}
		}
		cout << ansh << " " << answ << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
#define MAXN 101
int A[MAXN];
int N;
void solve(){

    for(int i=0;i<N;i++){
        if(A[i]%2 ==0){
            if(A[i]%3 != 0 && A[i]% 5 != 0){
                puts("DENIED");
                return;
            }
        }
    }
    puts("APPROVED");
}

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


    return 0;
}

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

int main() {

  string S;
  cin >> S;

  if(S == "Sunny") {
    cout << "Cloudy" << endl;
  }else if(S == "Cloudy") {
    cout << "Rainy" << endl;
  }else {
    cout << "Sunny" << endl;
  }

}


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

using namespace std;

void funca()
{
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";
}

void funcb()
{
    int x;
    cin >> x;

    int u = 0;
    u += x / 500 * 1000;
    x %= 500;
    u += x / 5 * 5;

    cout << u;


}

void funcc2()
{
    int k, n;
    cin >> k;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    
    int max_len = 0;
    int max_point = -1;
    vector<int> length(n); //各家間の距離を求める
    for (int i = 1; i < n; ++i) {
        length[i] = a[i] - a[i - 1];
        if (length[i] > max_len) { //距離が最大となる家を記録
            max_len = length[i];
            max_point = i;
        }
    } 
    length[0] = a[0] + k - a[n - 1];
    if (length[0] > max_len) {
        max_len = length[0];
        max_point = 0;
    }

    long long sum = 0;
    for (int i = max_point+1; i < n; ++i) {
        sum += length[i];
    }

    if (max_point != 0) {
        for (int i = 0; i < max_point; i++) {
            sum += length[i];
        }
    }

    cout << sum;

}

void funcc()
{
    int k, n;
    cin >> k;
    cin >> n;

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

    long long length = 0;
    int judge; //時計回りか反時計回りか
    if(a[n - 1] - a[0] <= k/2) judge = 1; //時計周り
    else judge = 0; //反時計回り
    
    if (judge) {
        for (int i = 1; i < n; ++i) {
            length += a[i] - a[i - 1];
        }
    }
    else {
        for (int i = n - 2; i >= 0; --i) {
            
        }
    }

    /*
    for (int i = 0; i < n; i++) {
        length = 0;
        if()
        for (int j = 0; j < n; j++) {
            if (i == j) continue;

            int temp;
            temp = a[n - 1] - a[i];

            if (temp >= k / 2) {//北端を通るとき更新
                if (a[i] < a[j]) temp = a[i] + (k - a[j]);
                else temp = a[j] + (k - a[i]);
            }

            length += temp;
        }
        if (l_min > length) l_min = length;
    }*/

    cout << length;

}

int main()
{
    //funca();
    //funcb();
    //funcc();
    funcc2();

    return 0;
}

Measured memory_bytes: 1792
x = int(input())

ans = 0

while 1:
    if x == 0:
        print(ans)
        break
    if x % 500 == 0:
        ans += 1000
        x -= 500
    elif x % 5 == 0:
        ans += 5
        x -= 5
    else:
        x -= 1


Measured memory_bytes: 2940
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    S = input()

    T = S[0]
    for i in range(1, len(S)):
        if S[i] != T[-1]:
            T += S[i]

    print(len(T) - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4072
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int rocks[100101];
int dp[100101];
const int INF = 0x3f3f3f3f;

int main()
{
    int n, k, in;
    scanf("%d%d", &n, &k);
    for(int i=1; i<=n; i++)
    {
        scanf("%d", &in);
        rocks[i] = in;
    }
    for(int i=2; i<=n; i++)
    {
        dp[i]= INF;
    }
    dp[1]=0;
    for (int i=1; i<=n; i++)
    {
        for(int j=1; j<=k; j++)
        {
            dp[i+j] = min(dp[i+j], dp[i]+abs(rocks[i+j]-rocks[i]));
        }
    }
    printf("%d", dp[n]);
}


Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
int main()
{
   long long int A,B,c,K;
    scanf("%lld %lld",&A,&B);
    c=A+B;
    K=(A+B)/2;
    if(c%2==0)
    {
printf("%lld",K);
    }
    else
    {
        printf("IMPOSSIBLE");
    }

}


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

using namespace std;

#define FOR(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
#define vP          vector<P>
#define vvP         vector<vP>

int main(){
    int n,y;cin>>n>>y;
    bool can=false;
    REP(yukichi,n+1){
        int x=y-10000*yukichi;
        int num=n-yukichi;
        if(x<0)break;
        if((5000*num-x)%4000==0 and 0<=(5000*num-x)/4000 and (5000*num-x)/4000<=num){
            cout<<yukichi<<" "<<num-(5000*num-x)/4000<<" "<<(5000*num-x)/4000<<"\n";
            can=true;
            break;
        }
    }
    if(can==false){
        cout<<"-1 -1 -1\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5+5;
typedef long long ll;
const ll INF = 1e4;
ll n, X, x[max_n]; 
void solve(){
    ll ans = 0;
    for(int i=0 ; i+1<n ; i++){
        if(x[i] == x[i+1]){
            x[i+1] = INF;
            ans++;
        }
    }
    cout << ans << endl;
}

int main(){
    cin >> n;
    for(int i=0 ; i<n ; i++){
        cin >> x[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

unsigned long long fact(unsigned long long i){
	if(i==0){
		return 1;
	}else{
		return i*fact(i-1);
	}
}

int main(){
	unsigned long long i;
	
	cin >> i;
	cout << fact(i) << endl;

	return 0;
}

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

#define ull unsigned long long

using namespace std;

const int N = 15;
const int base = 233;

int n, m, a[N][N], id1[N], id2[N];
ull hash1[N], hash2[N], Hash[N], Pow[N];
char s[N][N], s1[N];

inline void add(int x, int y)
{
	y--;
	for(int i = 1; i <= m; i++)
	{
		hash1[i] += (s[x][i] - 'a' + 1) * Pow[y];
		hash2[i] += (s[x][i] - 'a' + 1) * Pow[n - y - 1];
	}
}

inline void del(int x, int y)
{
	y--;
	for(int i = 1; i <= m; i++)
	{
		hash1[i] -= (s[x][i] - 'a' + 1) * Pow[y];
		hash2[i] -= (s[x][i] - 'a' + 1) * Pow[n - y - 1];
	}
}

inline int cmp1(int a, int b)
{
	if(hash1[a] != hash1[b])return hash1[a] < hash1[b];
	return a < b;
}

inline int cmp2(int a, int b)
{
	if(hash2[a] != hash2[b])return hash2[a] < hash2[b];
	return a > b;
}

void dfs(int deep)
{
	if(deep * 2 + 1>= n)
	{
		int cnt = 0;
		for(int i = 1; i <= m; i++)
			id1[i] = id2[i] = i;
		sort(id1 + 1, id1 + 1 + m, cmp1);
		sort(id2 + 1, id2 + 1 + m, cmp2);
		for(int i = 1; i <= m; i++)
			if(hash1[id1[i]] != hash2[id2[i]])return;
			else if(id1[i] == id2[i])
			{
				if(m & 1)cnt++;
				if((m & 1) && cnt <= 1)continue;
				return;
			}
		puts("YES");
		exit(0);
	}
	int nown = n - deep * 2;
	for(int i = 1; i <= nown; i++)
		for(int j = i + 1; j <= nown; j++)
		{
			int x = a[deep][i], y = a[deep][j];
			if(Hash[x] != Hash[y])continue;
			int cnt = 0;
			for(int k = 1; k <= nown; k++)
				if(a[deep][k] != x && a[deep][k] != y)a[deep + 1][++cnt] = a[deep][k];
			add(x, deep + 1);
			add(y, n - deep);
			dfs(deep + 1);
			del(x, deep + 1);
			del(y, n - deep);
		}
}

int main()
{
	scanf("%d%d", &n, &m);
	Pow[0] = 1;
	for(int i = 1; i <= n; i++)
		Pow[i] = Pow[i - 1] * base;
	for(int i = 1; i <= n; i++)
	{
		scanf("%s", s[i] + 1);
		for(int j = 1; j <= m; j++)
			s1[j] = s[i][j];
		sort(s1 + 1, s1 + 1 + m);
		ull nowhash = 0;
		for(int j = 1; j <= m; j++)
			nowhash = nowhash * base + (s1[j] - 'a' + 1);
		Hash[i] = nowhash;
		a[0][i] = i;
	}
	dfs(0);
	puts("NO");
}

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

void fnInput(int &rnMaxSiz, vector<int> &rvnSort)
{
  cin >> rnMaxSiz;

  rvnSort.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
    cin >> rvnSort[i];
}

void fnMerge(vector<int> &rvnSort, int &rnSortCnt, int nLeft, int nMid, int nRight)
{
  vector<int> vLeft, vRight;
  int nLeftSiz = nMid - nLeft;
  int nRightSiz = nRight - nMid;

  vLeft.resize(nLeftSiz + 1);
  vRight.resize(nRightSiz + 1);

  for (int i = 0; i < nLeftSiz; i++)
    vLeft[i] = rvnSort[nLeft + i];
  for (int i = 0; i < nRightSiz; i++)
    vRight[i] = rvnSort[nMid + i];

  vLeft[nLeftSiz] = INT_MAX;
  vRight[nRightSiz] = INT_MAX;
  int i = 0, j = 0;

  for (int n = nLeft; n < nRight; n++)
  {
    if (vLeft[i] <= vRight[j])
      rvnSort[n] = vLeft[i++];
    else
      rvnSort[n] = vRight[j++];
    rnSortCnt++;
  }
}

void fnMergeSort(vector<int> &rvnSort, int &rnSortCnt, int nLeft, int nRight)
{
  if (nLeft + 1 < nRight)
  {
    int nMid = (nLeft + nRight) / 2;
    fnMergeSort(rvnSort, rnSortCnt, nLeft, nMid);
    fnMergeSort(rvnSort, rnSortCnt, nMid, nRight);
    fnMerge(rvnSort, rnSortCnt, nLeft, nMid, nRight);
  }
}

void fnResult(const vector<int> &cnrvnSort, int nSortCnt)
{
  for (int i = 0; i < cnrvnSort.size(); i++)
  {
    if (i != 0)  cout << " ";
    cout << cnrvnSort[i];
  }
  cout << endl;
  cout << nSortCnt << endl;
}

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

  int nMaxSiz;
  vector<int> vnSort;

  fnInput(nMaxSiz, vnSort);

  int nLeft = 0;
  int nRight = nMaxSiz;
  int nSortCnt = 0;
  fnMergeSort(vnSort, nSortCnt, nLeft, nRight);

  fnResult(vnSort, nSortCnt);

  return 0;
}

Measured memory_bytes: 5068
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>s;
	long long ans=0;
	for(long long i=0;i<(1<<s.size()-1);i++){
		long long lst=-1;
		long long cnt=0;
		for(long long j=0;j<s.size();j++){
			if(i&(1<<j)){
				long long cnt2=0;
				for(long long k=lst+1;k<=j;k++){
					cnt2=cnt2*10+(long long)(s[k]-'0');
				}
				cnt+=cnt2;
				lst=j;
			}
		}
		long long cnt2=0;
		for(int j=lst+1;j<s.size();j++){
			cnt2=cnt2*10+(long long)(s[j]-'0');
		}
		cnt+=cnt2;
		ans+=cnt;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <fstream> //ofstream
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int mini,tmp,ct=0;
int n;
std::vector<int> p;
void solve(){
        mini=p.at(0);
        rep(i,n){
                if(p.at(i)<=mini) {
                        mini=p.at(i);
                        ct++;
                }
        }
        cout<<ct<<endl;
}

int main(){
        cin>>n;
        rep(i,n){
                cin>>tmp;
                p.push_back(tmp);
        }
        solve();
        return 0;
}


Measured memory_bytes: 1400
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int mul(int n,int m,int Matrix[][100],int matrix[][1]);

int main() {
	int Matrix[100][100] = { 0 };
	int matrix[100][1] = { 0 };
	int i, j;
	int n, m;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d",&Matrix[i][j]);
	for (i = 0; i < m; i++) scanf("%d", &matrix[i][0]);
	for (i = 0; i < n; i++) {
		printf("%d\n", mul(i, m, Matrix, matrix));
	}
	return 0;
}

int mul(int n, int m, int Matrix[][100], int matrix[][1]) {
	int i;
	int sum=0;
	for (i = 0; i < m; i++) {
			sum += Matrix[n][i] * matrix[i][0];
	}
	return sum;
}

Measured memory_bytes: 648
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# MOD = 10**9+7
# MOD = 998244353

k = int(input())
s = input()

if len(s) <= k:
    print(s)
else:
    print(s[:k] + "...")


Measured memory_bytes: 68092
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		StringBuilder ans = new StringBuilder(); 
		for(int i = 0; i < s.length();i++) {
			ans.append("x");
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 35636
s=input()
t=input()
import bisect
res=0
if len(set(t)-set(s)) > 0:
    res=-1
else:
    pos={}
    set_t=set(t)
    for e_t in t:
        pos[e_t]=[]
    for i in range(len(s)):
        if s[i] in set_t:
            pos[s[i]].append(i+1)
    cur = 0
    nxt=0
    for e_t in t:
        nxt=bisect.bisect_left(pos[e_t], cur+1)
        if nxt < len(pos[e_t]):
            cur=pos[e_t][nxt]
        else:
            cur=pos[e_t][0]
            res+=len(s)
    res+=cur
print(res)

Measured memory_bytes: 7668
#include <cstdio>
#include <queue>
using namespace std;

int main()
{
  int h,w;
  scanf("%d%d",&h,&w);
  static char M[1000][1001];
  for(int i=0;i<h;i++){
    scanf("%s",M[i]);
  }
  static int K[1000][1001]={0};
  int dx[8]={1,1,1,0,0,-1,-1,-1},dy[8]={-1,0,1,-1,1,-1,0,1};
  queue<pair<int,int> > Q[2];
  bool b=0;
  for(int i=1;i<h-1;i++){
    for(int j=1;j<w-1;j++){
      for(int v=0;v<8;v++){
	int x=i+dx[v],y=j+dy[v];
	if(M[x][y]=='.'){
	  K[i][j]++;
	}
      }
      if(M[i][j]!='.'&&K[i][j]>=M[i][j]-'0'){
	Q[b].push(make_pair(i,j));
      }
    }
  }
  int t=0;
  while(!Q[b].empty()){
    while(!Q[b].empty()){
      pair<int,int> p=Q[b].front();
      Q[b].pop();
      int i=p.first,j=p.second;
      for(int v=0;v<8;v++){
	int x=i+dx[v],y=j+dy[v];
	K[x][y]++;
	if(M[x][y]!='.'&&K[x][y]==M[x][y]-'0'){
	  Q[!b].push(make_pair(x,y));
	}
      }
    }
    t++;
    b=!b;
  }
  printf("%d\n",t);
  return 0;
}

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

#define ll long long

int main() {
  ll A, B;
  cin >> A >> B;
  
  ll count = 0;
  while (A <= B) {
    count++;
    A *= 2;
  }
  
  cout << count << endl;
  
  
}

Measured memory_bytes: 3592
import java.util.Scanner;

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

        int[] x = new int[5];

        for (int i = 0; i < 5; i++) {
            x[i] = sc.nextInt();
        }

        for (int i = 0; i < 5; i++) {
            if (x[i] == 0) {
                System.out.println(i + 1);
            }
        }
        sc.close();
    }
}

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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rd(n) scanf("%d", &n)

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int h, w, n;
ll k;
int board[50][50];

int ask(int sx, int sy, int ex, int ey)
{
    out << "? ";
    out << sx << " ";
    out << sy << " ";
    out << ex << " ";
    out << ey << endl;

    int ret; in >> ret;
    return ret;
}

void fill(int sx, int sy, int ex, int ey)
{
    REPE(i, sx, ex) REPE(j, sy, ey) board[i][j] = 1;
}

void f(int sx, int sy, int ex, int ey, int bomb)
{
    int mx = (sx+ex+1)/2;
    int my = (sy+ey+1)/2;

    int bombLeft = bomb;

    int ans1 = ask(sx, sy, mx-1, my-1);
    int area1 = ((mx-1)-(sx)+1)*((my-1)-(sy)+1);
    if(ans1 == area1) fill(sx, sy, mx-1, my-1);
    else if(ans1 != 0)
    {
        f(sx, sy, mx-1, my-1, ans1);
    }

    bombLeft -= ans1;
    if(bombLeft == 0) return;

    int ans2 = ask(sx, my, mx-1, ey);
    int area2 = ((mx-1)-(sx)+1)*((ey)-(my)+1);
    if(ans2 == area2) fill(sx, my, mx-1, ey);
    else if(ans2 != 0 && bombLeft > 0)
    {
        f(sx, my, mx-1, ey, ans2);
    }

    bombLeft -= ans2;
    if(bombLeft == 0) return;

    int ans3 = ask(mx, sy, ex, my-1);
    int area3 = ((ex)-(mx)+1)*((my-1)-(sy)+1);
    if(ans3 == area3) fill(mx, sy, ex, my-1);
    else if(ans3 != 0 && bombLeft > 0)
    {
        f(mx, sy, ex, my-1, ans3);
    }

    bombLeft -= ans3;
    if(bombLeft == 0) return;

    int ans4 = ask(mx, my, ex, ey);
    int area4 = ((ex)-(mx)+1)*((ey)-(my)+1);
    if(ans4 == area4) fill(mx, my, ex, ey);
    else if(ans4 != 0 && bombLeft > 0)
    {
        f(mx, my, ex, ey, ans4);
        bombLeft -= ans4;
    }
}

int main()
{
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif

    in >> h >> w >> n >> k;

    REP(i, 5) REP(j, 5)
    {
        f(i*10, j*10, i*10+9, j*10+9, ask(i*10, j*10, i*10+9, j*10+9));
    }

    ll p2 = 1LL;
    ll res = 0;
    REP(i, h) REP(j, w)
    {
        res = (res + board[i][j] * p2) % k;
        p2 = (2LL * p2) % k;
    }

    out << "! " << res << "\n";

    return 0;
}


Measured memory_bytes: 720
N, M = map(int, input().split())
l = 1
r = N
for i in range(M):
  tmp_l ,tmp_r = map(int, input().split())
  l = max(l, tmp_l)
  r = min(r, tmp_r)
if r>=l:
  print(r-l+1)
else:
  print(0)

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

/// Defining variable types.
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

/// Defining usable key words
#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

/// Defining constant variables.
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

/// Defining some useful lines.
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);


/// Code of debugger.
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
    optimize();

    int a[]={1,3,5,7,8,10,12};
    int b[]={4,6,9,11};
    int cnt=0;
    int x,y;
    cin>>x>>y;

    if(x==2 || y==2)
    {
        cout<<"No"<<endl;
        return 0;
    }


    for(int i=0;i<7;i++)
    {
        if(a[i]==x)cnt++;
        if(a[i]==y)cnt++;
    }

    if(cnt==2)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(cnt==1)
    {
        cout<<"No"<<endl;
        return 0;
    }

   else
    cout<<"Yes";

   /* for(int i=0;i<4;i++)
    {
        if(b[i]==x)cnt++;
        if(b[i]==y)cnt++;
    }

    if(cnt==2)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    else
    {
        cout<<"No"<<endl;
        return 0;
    }
*/












    return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;
int h[102];

bool ok(vector<int> &vec) {
    int d = vec[0]-vec[1];
    rep(i,vec.size()) {
        if(i==0) continue;
        if(vec[i-1]-vec[i]!=d) return false;
    }

    return true;
}

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

    rep(i,n+1) {
        vector<int> vec;
        rep(j,n+1) {
            if(i!=j) vec.pb(h[j]);
        }
        if(ok(vec)) {
            cout<<h[i]<<endl;
break;
        }
    }

}

int main() {
    while(cin>>n) {
        if(n==0) break;
        solve();
    }

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int>H(N);
  for(int i=0; i<N; i++)cin >> H.at(i);
  
  int ans =0;
  int count =0;
  
  for(int i=0; i<N-1; i++){
    if(H.at(i)>=H.at(i+1)){
      count ++;
      ans = max(ans, count);
    }
    else{
      ans = max(ans, count);
      count=0;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

struct Segment_Tree{  //区間和の遅延評価セグ木
    int N;
    vector<ll> data,lazy;
    vector<bool> flag;

    Segment_Tree(vector<ll> vec){
        int n_ = vec.size();
        N = 1;
        while(n_ > N){
            N *= 2;
        }
        data.resize(2*N - 1);
        lazy.resize(2*N - 1, 0);
        flag.resize(2*N - 1, false);
        REP(i,n_){
            int q = i + N -1;
            data[q] = vec[i];
        }
        for(int i = N -2; i >= 0; i--){
            data[i] = min(data[2*i + 1], data[2*i + 2]);
        }
    }

    void eval_min(int k, int l, int r){  //遅延評価　k: k番目のノードについての遅延評価  
        if(lazy[k] != 0){
            data[k] += lazy[k];

            if(r - l > 1){
                lazy[2*k + 1] += lazy[k];
                lazy[2*k + 2] += lazy[k];
            }
            lazy[k] = 0;
        }
    }

    void add_min_sub(int a,int b, ll x, int k, int l, int r){ //[a,b)間の区間加算
        if(r <0) r = N;
        eval_min(k,l,r);  //遅延評価を行う

        if(b <= l || r <= a){ //もし[l,r)と[a,b)が交わらない ->なんもしない
            return;
        }
        else if(a <= l && r <= b){
            lazy[k] += x;
            eval_min(k,l,r);
        }
        else{
            add_min_sub(a, b, x, 2*k+1, l, (l+r)/2);
            add_min_sub(a, b, x, 2*k+2, (l+r)/2, r);
            data[k] = min(data[2*k+1], data[2*k+2]);
        }

    }

    void add_min(int a,int b, ll x){
        add_min_sub(a,b,x,0,0,N);
    }


    ll getmin_sub(int a, int b, int k, int l, int r){
        if(b <= l || a >= r){
            return INF; //maxに絶対ならない値を返す？
        }
        
        eval_min(k,l,r); //ここで遅延評価
        if(a <= l && r <= b){
            return data[k];
        }
        else{
            ll chl = getmin_sub(a, b, 2*k + 1, l, (l+r) / 2);
            ll chr = getmin_sub(a, b, 2*k + 2, (l+r) / 2, r);
            return min(chl, chr);
        }
    }

    ll getmin(int a,int b){
        return getmin_sub(a, b, 0, 0, N);
    }
};

int main(){
    int N,Q; cin>>N>>Q;
    vector<ll> vec(N,0);
    Segment_Tree tree(vec);
    vector<ll> ans;

    REP(i,Q){
        int a; cin >> a;
        if(a == 0){
            int s, t; ll x;
            cin >> s >> t >> x;
            tree.add_min(s, t+1, x);
        }
        else{
            int s,t; cin>>s>>t;
            ans.push_back(tree.getmin(s,t+1));
        }
    }

    REP(i,ans.size()){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 9428
n,y=map(int,input().split())
i,j,f=0,0,0
for i in range(y//10000+1):
    a=y-10000*i
    for j in range(a//5000+1):
        p=a-5000*j
        if i+j+p//1000==n:
            print(i,j,p//1000)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;



int main() {
	string s;
	cin >> s;

	cout << s.at(0) << s.size() - 2 << s.back() << endl;
}

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

struct Box
{
  int num = 1;
  bool can_be_red = false;

  Box() {};

  Box(int num, bool can_be_red)
    : num(num), can_be_red(can_be_red) {};
};

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

  map<int, Box> mp;
  mp[1] = Box{1, true};
  rep(i,0,M-1) {
    int x, y;
    cin >> x >> y;
    mp[y].num++;
    if (mp[x].can_be_red)
      mp[y].can_be_red = true;
    mp[x].num--;
    if (mp[x].num == 0)
      mp[x].can_be_red = false;
  }

  int ans = count_if(begin(mp), end(mp), [](pair<int, Box> p) { return p.second.can_be_red; });
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main(){
  string s;
  cin>>s;
  if(s=="MON"){
    cout<<6<<endl;
  }else if(s=="TUE"){
    cout<<5<<endl;
  }else if(s=="WED"){
    cout<<4<<endl;
  }else if(s=="THU"){
    cout<<3<<endl;
  }else if(s=="FRI"){
    cout<<2<<endl;
  }else if(s=="SAT"){
    cout<<1<<endl;
  }else{
    cout<<7<<endl;
  }
  return 0;
}


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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

ll N;
ll sft[3] = {3, 5, 7};
ll ans = 0;

void dfs(ll sum, map<ll, ll> m){
    if(sum <= N){
        if(m[3] && m[5] && m[7]) ans++;

        for(auto n : sft){
            map<ll, ll> m2 = m;
            m2[n]++;
            dfs(sum * 10 + n, m2);
        }
    }
}

int main() {
    cin >> N;
    map<ll, ll> m;
    dfs(0, m);
    cout << ans << endl;

}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let s: String = read(&mut stdin_lock, &mut buf, b'\n');
    let tbl: Vec<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
        .chars()
        .collect();
    let cs: Vec<char> = s.chars().collect();

    for i in 0..cs.len() {
        let mut c2 = ' ';
        let c = cs[i];
        for j in 0..tbl.len() {
            if tbl[j] == c {
                c2 = tbl[j + n];
                break;
            }
        }
        print!("{}", c2);
    }
    println!();
}


Measured memory_bytes: 4352
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		
		while(true){
			final int n = sc.nextInt();
			final int r = sc.nextInt();
			
			if(n == 0 && r == 0){
				break;
			}
			
			LinkedList<Integer> deck = new LinkedList<Integer>();
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			LinkedList<Integer> tmp2 = new LinkedList<Integer>();
			for(int i = 0; i < n; i++){
				deck.add(n - i);
			}
			
			for(int i = 0; i < r; i++){
				final int p = sc.nextInt();
				final int c = sc.nextInt();
				
				for(int j = 0; j < p - 1; j++){
					tmp.add(deck.removeFirst());
				}
				
				for(int j = 0; j < c; j++){
					tmp2.add(deck.removeFirst());
				}
				
				for(int j = 0; j < p - 1; j++){
					deck.addFirst(tmp.removeLast());
				}
				
				for(int j = 0; j < c; j++){
					deck.addFirst(tmp2.removeLast());
				}
			}
			
			System.out.println(deck.peekFirst());
		}
		
	}
}

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

int main() {
  int N;
  cin >> N;
  
  int a;
  int min = 1000000;
  int max = -1000000;
  int64_t sum = 0;
  for (int i=0; i<N; i++) {
    cin >> a;
    sum += a;
      if (min > a) min = a;
      if (max < a) max = a;
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}


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

int main() {
  std::string op; int a,b = 0;

  while (std::cin >> a >> op >> b, op != "?") {
    if (op == "+")
      std::cout << a + b;
    else if (op == "-")
      std::cout << a - b;
    else if (op == "*")
      std::cout << a * b;
    else if (op == "/")
      std::cout << a / b;
    std::cout << "\n";
  }

  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  int i;
  for(i=0;i<n;i++) cin >> v[i];
  sort(v.begin(),v.end());
  int max = 0;
  int cnt = 0;
  for(i=0;i<n;i++){
    if(max<v[i]){
      cnt++;
      max = v[i];
    }
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int x; cin >> x;
    cout << ((x == 0) ? 1 : 0) << endl;


    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b;
    cin>>a>>b;
    if((b+a)&1)
        cout<<"IMPOSSIBLE"<<'\n';
    else{
        cout<<(long long int)((a+b)/2)<<'\n';
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque

def a():
    H,W = map(int,input().split())
    S = ["" for _ in range(H)]
    for _ in range(H):
        S[_] = input()
    b = lambda n:S[n//W][n%W] == '.'
    v = list(filter(b,range(H*W)))
    u = list(map(lambda n:(n%W,n//W),v))

    le = len(v)

    def bfs(root):
        i = 0
        depth = [[-1]*W for _ in range(H)]
        in_que = [[0]*W for _ in range(H)]
        q = deque()
        q.append((root,0))
        xx,yy = root
        in_que[yy][xx] = 1
        while i < le:
            r,d = q.popleft()
            x,y = r
            depth[y][x] = d
            i += 1
            for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):
                dx += x
                dy += y
                if 0 <= dx < W and 0 <= dy < H and in_que[dy][dx] == 0 and S[dy][dx] == ".":
                    q.append(((dx,dy),d+1))
                    in_que[dy][dx] = 1
        return depth
    
    print(max([max([max(y) for y in x]) for x in map(bfs,u)]))

a()





Measured memory_bytes: 44636
#!/usr/bin/env python3

def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    x = [0] * M
    y = [0] * M
    c = [0] * M
    for i in range(M):
        x[i], y[i], c[i] = map(int, input().split())

    # without discount
    total = min(a) + min(b)

    # with discount
    for i in range(M):
        t = a[x[i] - 1] + b[y[i] - 1] - c[i]
        if t < total:
            total = t

    print(total)

main()


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

int main() {
  int N;
  cin >> N;
  vector<double> p(N);
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
  }

  vector<vector<double>> dp(N + 1, vector<double>(N + 1));
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      dp[i + 1][j + 1] += dp[i][j] * p[i];
      dp[i + 1][j] += dp[i][j] * (1 - p[i]);
    }
  }

  double ans = 0;
  for (int i = (N + 1) / 2; i <= N; ++i) {
    ans += dp[N][i];
  }

  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70784
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }

        long sum = 0;
        for(int i = 0; i < N; i++){
            if(A[i]/2 > 0){
                sum += A[i]/2;
                A[i] %= 2;
            }
            if(i != N-1){
                if(A[i] > 0 && A[i+1] > 0){
                    int min = Math.min(A[i], A[i+1]);
                    sum += min;
                    A[i] -= min;
                    A[i+1] -= min;
                }
            }
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 52160
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	string s;
	ll k;
	cin >> s >> k;
	string ans = "1";
	for(int i=0;i<s.size();++i)if (s[i] != '1'&&i<=k-1) {
		ans = s[i];
		break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256