akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n;
    ll x;
    cin>>n>>x;
    vector<ll> psum(n+1), len(n+1);
    psum[0]=1; len[0]=1;
    rep(i,n){
        psum[i+1]=2*psum[i]+1;
        len[i+1]=2*len[i]+3;
    }
    ll ans=0;
    while(x>0){
        if(n==0){
            if(x==1) ans++;
            x--;
        }
        else{
            if(x>(len[n-1]+1)){
                ans+=(psum[n-1]+1);
                x-=(len[n-1]+2);
                n--;
            }
            else if(x==(len[n-1]+1)){
                ans+=psum[n-1];
                x-=(len[n-1]+1);
                n--;
            }
            else{
                x--;
                n--;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
i1=[input() for _ in range(n)]
i2=[input() for _ in range(m)]
ans="No"
for i in range(n-m+1):
    for j in range(n-m+1):
        count=0
        for k in range(m):
            if i1[i+k][j:m+j]==i2[k]:
                count+=1
                if count==m:
                    ans="Yes"
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Enemy {
  ll cnt;
  ll attack;
  int after;
  Enemy() {;}
  Enemy(ll cnt, ll attack, int after)
    : cnt(cnt), attack(attack), after(after) {;}
  bool operator<(const Enemy &rhs) const {
    return rhs.cnt * attack < cnt * rhs.attack;
  }
};

int n;
ll h, a, d, s;
int main() {
  while (scanf("%d", &n) > 0) {
    scanf("%lld %lld %lld %lld", &h, &a, &d, &s);
    ll attackSum = 0;
    vector<Enemy> enemys;
    bool ng = false;
    REP(i, n) {
      ll eh, ea, ed, es;
      scanf("%lld %lld %lld %lld", &eh, &ea, &ed, &es);
      ll attack = ea - d;
      ll damage = a - ed;
      if (attack <= 0) { continue; }
      if (damage <= 0) { ng = true; continue; }
      ll cnt = (eh + damage - 1) / damage;
      int after = 0;
      if (es < s) { after = 1; }
      attackSum += attack;
      enemys.push_back(Enemy(cnt, attack, after));
    }
    if (ng) { puts("-1"); continue; }
    ll ans = 0;
    sort(enemys.rbegin(), enemys.rend());
    FORIT(it, enemys) {
      attackSum -= it->attack;
      ans += attackSum * it->cnt;
      ll cnt = it->cnt;
      if (it->after) { cnt--; }
      ans += it->attack * cnt;
      if (ans >= h) { break; }
    }
    if (h <= ans) {
      puts("-1");
    } else {
      printf("%lld\n", ans);
    }
  }
}

Measured memory_bytes: 1756
import java.util.Arrays;
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[] p = new int[n];
			int ret =0;
			
			for(int i=0;i<n;i++) {
				p[i] = sc.nextInt();
			}
			
			Arrays.sort(p);
			
			for(int i=0;i<k;i++) {
				ret += p[i];
			}
			
			System.out.println(ret);
		}
	}


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

signed main() {
	string s;
	while (cin >> s and s != "0") {
		int sum = 0;
		for (int i = 0; i < s.size(); ++i) {
			sum += s[i] - '0';
		}
		cout << sum << endl;
	}
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    cin>>n;
    double v[100];
    for(int i=0;i<n;i++) cin>>v[i];
    sort(v,v+n);
    double ans=v[0];
    for(int i=1;i<n;i++){
        ans=(ans+v[i])/2;
    }
    printf("%.10f\n",ans);
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

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

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	ll x;
	cin >> x;

	x = abs(x);

	int ans = 0;
	for (int i = 0; ; i++)
	{
		ll t = i * (i + 1) / 2;
		if (t >= x)
		{
			ans = i;
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
	int a, b, h, m;

	cin >> a >> b >> h >> m;

	long double dis;
	long double h_kaku, m_kaku;

	h_kaku = 30*h + 0.5*m;
	m_kaku = 6*m;

	if(m_kaku == h_kaku){
		cout << setprecision(20) << abs(a-b) << endl;
	}else if(m_kaku > h_kaku){
		long double rad = (m_kaku - h_kaku)*M_PI/180.0;
		dis = sqrt(a*a + b*b - 2*a*b*cos(rad));
		cout << setprecision(20) << dis << endl;
	}else if(m_kaku < h_kaku){
		long double rad = (h_kaku - m_kaku)*M_PI/180.0;
		dis = sqrt(a*a + b*b - 2*a*b*cos(rad));
		cout << setprecision(20) << dis << endl;
	}

	

	return 0;
}

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

string shuffle(string str, int h ){
  string head = str.substr(0, h);
  string tail = str.substr(h, str.size()-h);
  return tail + head;
}

int main(){
 string cards;
 int m, h;
    
    while(1){
      cin >> cards;
      if ( cards == "-" ) break;
        
    cin >> m;
       for ( int i = 0; i < m; i++ ){
          cin >> h;
          cards = shuffle(cards, h);
        }
        cout << cards << endl;
        
    }

 return 0;
}    

Measured memory_bytes: 1216
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;
ll INF=100000000000001;
vector<ll> value; // ノードの値を持つ配列
ll N;             // 葉の数
 
void update(ll i, ll x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
 
ll query(ll a, ll b, ll k, ll l, ll r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}

signed main(){
    llin(k);
    llin(n);
    vllin(a,n);
    ll t;
    t=a[0]+k-a[n-1];
    FOR(i,1,n-1){
        if(a[i]-a[i-1]>t) t=a[i]-a[i-1];
    }
    sal(k-t)
}

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

int main()
{
	string s,t="";
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='1')t+="1";
		else if(s[i]=='0')t+="0";
		else if(t.size()>0)t.erase(t.size()-1,1);
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
object Main extends App {
  import scala.io.StdIn._

  loop()
  @tailrec def loop(): Unit = {
    val n = readInt()
    if (n == 0) return
    val member = Array.fill(n) {
      val prob :: m :: list = readLine.trim.split(' ').toList
      (prob.toDouble, list.map(_.toInt - 1))
    }
    val inverseEdge = Array.fill(n) {Nil: List[Int]}
    for (i ← member.indices; j ← member(i)._2) inverseEdge(j) ::= i
    val lastTime = Array.fill(n) {0}
    val isDiscovery = Array.fill(n) {false}
    def setLastTIme(current: Int, time: Int = 0): Int = {
      if (!isDiscovery(current)) {
        isDiscovery(current) = true
        lastTime(current) = member(current)._2.foldLeft(time) { case (t, next) ⇒ setLastTIme(next, t) } + 1
        lastTime(current)
      } else time
    }
    (0 until n).foldLeft(0){case (t, r) ⇒ setLastTIme(r, t)}
    isDiscovery.indices.foreach(i ⇒ isDiscovery(i) = false)
    val union = new UnionFind(n + 1)
    def mergeStrongConnect(current: Int): Unit = {
      isDiscovery(current) = true
      for (next ← inverseEdge(current) if !isDiscovery(next)) {
        union.merge(current, next)
        mergeStrongConnect(next)
      }
    }
    for (i ← lastTime.indices.sortBy(lastTime)(Ordering.Int.reverse) if !isDiscovery(i)) {
      mergeStrongConnect(i)
    }
    var result = 1d
    val inEdgeCount= inverseEdge.indices.map(i ⇒ inverseEdge(i).count(j ⇒ !union.isSame(i, j)))
    for (i ← inverseEdge.indices if !union.isSame(i, n)) {
      var res = 1d
      var inEdge = 0
      for (j ← 0 until n if union.isSame(i, j)) {
        res *= member(j)._1
        inEdge += inEdgeCount(j)
      }
      if (inEdge == 0) result *= (1 - res)
      union.merge(i, n)
    }
    println(f"$result%.9f")
    loop()
  }
}
class UnionFind(val size: Int) {
  private[this] val array = Array.fill(size){-1}
  def find(a: Int): Int = {
    if (array(a) < 0) a
    else {
      array(a) = find(array(a))
      array(a)
    }
  }
  def isSame(a: Int, b: Int): Boolean = find(a) == find(b)
  def merge(a: Int, b: Int): Unit = {
    val ar = find(a)
    val br = find(b)
    if (ar != br){
      if (array(ar) < array(br)) {
        array(ar) += array(br)
        array(br) = ar
      }else {
        array(br) += array(ar)
        array(ar) = br
      }
    }
  }
}


Measured memory_bytes: 63484
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(){
    double N,A;
    
cin >> N >> A;
    
    cout << (N*N) - A  << endl;

    return 0;

}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, H; cin >> N >> H;
    int maxA = 0;
    vector<int> B;
    int b[100010];
    rep(i, N) {
        int a;
        cin >> a >> b[i];
        maxA = max(maxA,a);
    }
    rep(i, N) {
        if (maxA < b[i]) B.push_back(b[i]);
    }
    sort(B.begin(), B.end(), greater<int>());
    int cnt = 0;
    rep(i, B.size()) {
        H -= B[i];
        cnt++;
        if(H <= 0) {
            cout << cnt << endl;
            return 0;
        }
    }
    cout << cnt + (H + maxA - 1)/maxA << endl;


    return 0;
}


Measured memory_bytes: 2168
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
    ini(K, S);

    int ret = 0;
    rep(i, K + 1) {
        rep(j, K + 1) {
            if (S - i - j >= 0 && S - i - j <= K)
                ret++;
        }
    }
    out(ret);
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s; cin >> s;
  if (all_of(s.begin(), s.end(), [&](char c) { return c == s[0]; })) puts("No");
  else puts("Yes");
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	char str[10];
	int n;
	int asdf[10];
	int max=0;
	int count=0;
	
	for(n=0;n<=10;n++){
	    asdf[n]=0;
	}
	
	scanf("%s", str);
	

	
	for(n=0;n<=10;n++){
	    if(str[n]=='A')asdf[n]=1;
	    if(str[n]=='C')asdf[n]=1;
	    if(str[n]=='G')asdf[n]=1;
	    if(str[n]=='T')asdf[n]=1;
	}
	
	for(n=0;n<=10;n++){
	    if(asdf[n]==1)count++;
	    if(max<count)max=count;
	    if(asdf[n]==0)count=0;
	    
	}
	
	printf("%d", max);
	
	return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
          int a , b , c ;
          scanf("%d" , &a ) ;
          scanf("%d" , &b) ;
          scanf( "%d" , &c) ;
           if ((a == b && a != c)||
                    (a == c && a!=b ) ||
                    (b == c && b!= a))
          {
                    printf("Yes") ;
          }
          else printf("No") ;

                    return 0 ;
}



Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            int n = sc.nextInt();
            boolean[] useColors = new boolean[3200 / 8];
            int over3200 = 0;
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                if (a >= 3200) {
                    over3200++;
                } else {
                    useColors[a / 400] = true;
                }
            }
            int useColorsCount = 0;
            for (boolean use : useColors) {
                if (use) useColorsCount++;
            }
            System.out.printf("%s %s", useColorsCount == 0 ? 1 : useColorsCount, useColorsCount + over3200);
        }
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long

int out6(ll x){
  int tmp =100000;
  while(tmp>0){
    cout << x/tmp;
    x=x%tmp;
    tmp/=10;
  }
  return 0;
}

int main(){
    ll N,M;
    cin >> N >> M;
    vector< pair < pair<ll,ll> ,ll > > cities(M);
    ll i;
    for(i=0;i<M;i++){
      cin >> cities[i].first.second >> cities[i].first.first;
      cities[i].second=i;
    }
    sort(cities.begin(),cities.end());
    vector< pair<ll,ll> >ans(M);
    ll numbers[N];
    for(i=0;i<N;i++){
      numbers[i]=0;
    }
    for(i=0;i<M;i++){
      numbers[cities[i].first.second-1]++;
      ans[cities[i].second].second=numbers[cities[i].first.second-1];
      ans[cities[i].second].first=cities[i].first.second;
    }
    for(i=0;i<M;i++){
      out6(ans[i].first);
      out6(ans[i].second);
      cout << endl;
    }
    return 0;
}


Measured memory_bytes: 6144
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		ArrayList<Integer> arr = new ArrayList<Integer>();
		for(int i = 0; i < n; i++)
			arr.add(in.nextInt());
		Collections.sort(arr);
		Collections.reverse(arr);

		long sum = 0;
		for(int i = 0; i < n; i++)
			sum += arr.get(i / 2);
		
		System.out.println(sum - arr.get(0));
		

	}
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
queue<int> quex,quey;
const int MOD = 1000000007;



int main(){
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;  cin >> k;
    cout << a[k-1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <deque>
using namespace std;

const int N = 2e5;

deque<int> q;

int n;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        if (i & 1) q.push_back(x);
            else q.push_front(x);
    }
    if ((n & 1) == 0) {
        for (deque<int>::iterator it = q.begin(); it != q.end(); ++it) {
            printf("%d ", *it);
        }
        return 0;
    } else {
        deque<int>::iterator it = q.end();
        --it;
        for (; it != q.begin(); --it) {
            printf("%d ", *it);
        } printf("%d\n", q.front());
        return 0;
    }
    return 0;
}

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

using namespace std;

int main(){

	int N,d[105],ans,c=0;

	cin >> N;

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

		cin >> d[i];

	}


	int num[110]={0};

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

		num[d[i]]++;

		//cout <<i <<num[i] <<endl;

	}
	ans=0;

	for(int i=0; i<=100; i++){
		if(num[i]>0) ans++;


	}

	cout <<ans <<endl;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll calc(string & S) {
    ll ans = 0;
    ll same_num = 1;
    if (S.size() == 0) return 0;
    REP(i, 0, S.size() - 1) {
        if (S[i] == S[i + 1]) {
            same_num++;
        }
        else {
            ans += same_num / 2;
            same_num = 1;
        }
    }
    ans += same_num / 2;
    return ans;
}

int main() {
    string S;
    cin >> S;
    ll K;
    cin >> K;
    set<char> St;
    rep(i, S.size()) {
        St.insert(S[i]);
    }
    if (St.size() == 1) {
        cout << S.size() * K / 2 << endl;
        return 0;
    }
    int i = 0;
    for(i = 0; i < S.size(); i++) {
        if (S[i] == S[i + 1]) {

        }
        else {
            break;
        }
    }
   auto suffix = S.substr(i + 1);
   auto prefix = S.substr(0, i + 1);
    S =  suffix + prefix;

    ll ans = calc(S);
    ans *= K - 1;

    ans += calc(suffix);
    ans += calc(prefix);

    cout << ans  << endl;
    
    return 0;
}

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

using namespace std;
int  main(void) {
	//B
	int N;
	int T;
	int *c = new int[100];
	int *t = new int[100];

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

	int minCost = 1001;
	for (int j = 0; j < N; j++) {
		if (c[j] < minCost && t[j] <= T) {
			minCost = c[j];
		}
	}
	if (minCost == 1001) {
		cout << "TLE";
	}
	else {
		cout << minCost;
	}

	return 0;
}

Measured memory_bytes: 256
import math
a,b,C = [int(i) for i in input().split()]

S = (1 / 2) * a * b * math.sin(C/180 * math.pi)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C/180*math.pi))
L = a + b + c
h = 2 * S / a

print(S)
print(L)
print(h)



Measured memory_bytes: 5716
def main():

    import sys
    import heapq

    N, Q = map(int, sys.stdin.readline().split())
    events = []

    for i in range(N):
        s, t, x = map(int, sys.stdin.readline().split())
        events.append((s - x, 1, x))  # 通行止め追加
        events.append((t - x, -1, x))  # 通行止め削除

    for i in range(Q):
        d = int(input())
        events.append((d, 2, 0))

    events.sort()
    events.append([float('inf'), 'guard', None])

    i = 0
    closing = set()
    hq = []  # 最小値を高速に入手するため
    while d >= events[i][0]:
        time, event, x = events[i]
        if event == 1:
            closing.add(x)
            heapq.heappush(hq, x)

        elif event == -1:
            closing.remove(x)

        else:
            while hq and (hq[0] not in closing):
                heapq.heappop(hq)

            if hq:
                print(hq[0])
            else:
                print(-1)

        i += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 89744
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, K;
char buf[333];
int dp[333][333][333];

void MAIN() {
    scanf("%s", buf);
    scanf("%d", &K);

    string S = buf;
    string T = buf;
    reverse(T.begin(), T.end());
    N = S.size();

    REP (i, N) REP (j, N) {
	if (S[i] == T[j]) {
	    REP (k, K+1) dp[i+1][j+1][k] = dp[i][j][k] + 1;
	} else {
	    REP (k, K+1) dp[i+1][j+1][k] = max(dp[i][j+1][k], dp[i+1][j][k]);
	    REP (k, K) amax(dp[i+1][j+1][k+1], dp[i][j][k] + 1);
	}
    }

    int ans = 0;
    REP (i, N+1) {
	REP (k, K+1) {
	    int j = N-i;

	    {
		int guess = dp[i][j][k] * 2;
		amax(ans, guess);
	    }

	    if (j) {
		j--;
		int guess = dp[i][j][k] * 2 + 1;
		amax(ans, guess);
	    }
	}
    }
    printf("%d\n", ans);
}


int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 130816
def solve():
    N = int(input())
    a = [int(i) for i in input().split()]
    Q = int(input())
    sort_a = sorted(a)
    judge = 0
    for i in range(N):
        if a[i] != sort_a[i]:
            judge += 1
    if judge == 0:
        print(0)
    else:
        for i in range(Q):
            x, y = map(int, input().split())
            tmp = a[x - 1]
            a[x - 1] = a[y - 1]
            a[y - 1] = tmp
            if a[x - 1] == sort_a[x - 1] and a[y - 1] != sort_a[x - 1]:
                judge -= 1
            if a[x - 1] != sort_a[x - 1] and a[y - 1] == sort_a[x - 1]:
                judge += 1
            if a[y - 1] == sort_a[y - 1] and a[x - 1] != sort_a[y - 1]:
                judge -= 1
            if a[y - 1] != sort_a[y - 1] and a[x - 1] == sort_a[y - 1]:
                judge += 1
            if judge == 0:
                print(i + 1)
                break
        else:
            print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 40080
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	lint N, K;
	cin >> N >> K;

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

	vector<vector<int>> dbl(N, vector<int>(60));
	for (int i = 0; i < N; i++) {
		dbl[i][0] = A[i];
	}

	for (int j = 0; j < 59; j++) {
		for (int i = 0; i < N; i++) {

			dbl[i][j + 1] = dbl[dbl[i][j]][j];
		}
	}
	DMP(dbl);

	int now = 0;
	for (int i = 0; i < 60; i++) {
		if (K & (1LL << i)) {
			now = dbl[now][i];
		}
	}

	cout << now + 1 << "\n";


	return 0;
}

Measured memory_bytes: 58640
from operator import itemgetter

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(i) for i in input().split()) for _ in range(m)]

a.sort()
bc.sort(key=itemgetter(1), reverse=True)
idx = 0
b, c = bc[idx]
for i in range(n):
    if a[i] >= c:
        break
    a[i] = c
    b -= 1

    if b == 0:
        idx += 1
        if idx >= m:
            break
        b, c = bc[idx]

print(sum(a))


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

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}


int main()
{
    textIO();
    fastIO();

    long long n, m, k, ans = 0;
    cin >> n >> m >> k;
    vector<long long> f(n), s(m);

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

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

    long long i = 0, j = 0, cnt = 0;

    while(k-f[i] >= 0 && i<n){
        k-=f[i];
        i++;
        cnt++;
    }

    i--;

    ans = max(cnt, ans);

    while(j<m){
        while(k-s[j] >= 0 && j<m){
            k-=s[j];
            j++;
            cnt++;
        }
        ans = max(ans, cnt);

        if(i>=0){
            k+=f[i];
            i--;
            cnt--;
        }
        else{
            break;
        }
    }

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

Measured memory_bytes: 6364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
const ll Maxn = 200005;
const ll Mod = 998244353;
ll N;
struct Robot{
	ll X;
	ll D;
}a[Maxn];
ll Touch_Far_Robot[Maxn];
ll Touch_Far_Robot_Tree[4*Maxn];
ll dp[Maxn];
bool Have_Test_Poi[Maxn];
bool cmp(Robot a,Robot b)
{
	return a.X<b.X;
}
void UpData_Tree(ll poi,ll Left,ll Right,ll Poi,ll Value)
{
	if(Left >Poi || Right <Poi)	return;
	if(Left == Right &&Left == Poi) 
	{
		Touch_Far_Robot_Tree[poi]= Value;
		return;
	}
	ll Mid = Left + (Right - Left)/2;
	UpData_Tree(poi*2,Left,Mid,Poi,Value);
	UpData_Tree(poi*2+1,Mid+1,Right,Poi,Value);
	Touch_Far_Robot_Tree[poi] = max(Touch_Far_Robot_Tree[poi*2],Touch_Far_Robot_Tree[poi*2+1]);
}
ll Search(ll x)
{
	ll Left = 1;
	ll Right = N;
	ll ans;
	while(Left<=Right)
	{
		ll Mid = Left + (Right - Left)/2;
		if(!Have_Test_Poi[Mid])	//表示当前还没有测试到
		{
			Left = Mid + 1;
			continue;
		} 
		if(a[Mid].X <x)//表示可以 
		{
			ans = Mid;
			Left = Mid +1;
		}
		else
		{
			Right = Mid -1;
		}
	}
	return ans;
}
ll Search_Touch_Tree(ll poi,ll Left ,ll Right,ll L,ll R)
{
	ll ans = -1;
	if(Left > R ||Right < L)	return 0;
	if(L <=Left &&Right <=R)	return Touch_Far_Robot_Tree[poi];
	ll Mid = Left + (Right - Left)/2;
	ans = max(ans,Search_Touch_Tree(poi*2,Left,Mid,L,R));
	ans = max(ans,Search_Touch_Tree(poi*2+1,Mid+1,Right,L,R));
	return ans;
}
int main()
{
	scanf("%lld",&N);
	for(int i=1;i<=N;i++) scanf("%lld %lld",&a[i].X,&a[i].D);
	sort(a+1,a+N+1,cmp);
	Touch_Far_Robot[N] = N; //预处理一开始最先碰到自已
	UpData_Tree(1,1,N,N,N); 
	Have_Test_Poi[N] = true;
	for(int i = N-1;i>=1;i--)
	{
		Have_Test_Poi[i] = true;
		ll Dist = a[i].X + a[i].D;
		ll x = Search(Dist);
		Touch_Far_Robot[i] = max(x,Search_Touch_Tree(1,1,N,i,x));
		UpData_Tree(1,1,N,i,Touch_Far_Robot[i]);
	}
	dp[N] = 2;
	for(int i=N+1;i<Maxn;i++)	dp[i]= 1;	//因为空的也算一种 
	for(int i=N-1;i>=1;i--)
	{
		dp[i] = dp[i+1] + dp[Touch_Far_Robot[i]+1];
		dp[i]%=Mod;
	}
	cout<<dp[1];
	return 0;	
} 

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
int main(){
  int m,f,r;
  while(1){
    cin >> m >> f >> r;
    if(m==-1 && f==-1 && r==-1){
      break;
    } else if(m==-1 || f==-1 || m+f<30){
      cout << "F" << endl;
    } else if(m+f>=80){
      cout << "A" << endl;
    } else if(m+f>=65 && m+f<80){
      cout << "B" << endl;
    } else if(m+f>=50 && m+f<65){
      cout << "C" << endl;
    } else if(m+f>=30 && m+f<50 && r>=50){
      cout << "C" << endl;
    } else {
      cout << "D" << endl;
    }
  }
}


Measured memory_bytes: 3040
N, M, K = map(int,input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

UFT = UnionFind(N)
ans = [0 for _ in range(N)]

for _ in range(M):
    A, B = map(int,input().split())
    ans[A-1] -= 1
    ans[B-1] -= 1
    UFT.union(A-1, B-1)

for _ in range(K):
    C, D = map(int,input().split())
    if UFT.same(C-1, D-1):
        ans[C-1] -= 1
        ans[D-1] -= 1

ans = [UFT.size(i) + ans[i] - 1 for i in range(N)]

print(*ans)

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n;cin >> n;
    vl h(n);
    rep(i,n)cin>>h[i];
    vl dp(100010,L_INF);
    dp[0]=0;
    rep(i,n){
        chmin(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        chmin(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }
    out(dp[n-1]);
}


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

int main(){
  int n; cin>>n;
  long a[87]={};
  a[0]=2;
  a[1]=1;
  for(int i=2;i<=n;++i){
    a[i]=a[i-1]+a[i-2];
  }
  cout<<a[n]<<endl;
}


Measured memory_bytes: 384
#include <iostream>

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

	int money = 0;
	if(a >= 13) money = b;
	else if(a >= 6) money = b / 2;
	else money = 0;

	std::cout << money << std::endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int A = cin.nextInt();
        int B = cin.nextInt();

        if (A < 6)
        {
            Console.WriteLine(0);
        }
        else if (A < 13)
        {
            Console.WriteLine(B / 2);
        }
        else
        {
            Console.WriteLine(B);
        }
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }

    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=998244353;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(){
    long A, B;
    cin>>A>>B;

    if(B==1){
        cout<<0<<endl;
    }else if(B<=A){
        cout<<1<<endl;
    }else{
        cout<<ceil((B-A)*1.0/(A-1)) + 1<<endl;
    }

    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    answer();

    return 0;
}


Measured memory_bytes: 3748
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let r = match n {
        3 | 5 | 7 => "YES",
        _ => "NO",
    };

    writeln!(o, "{}", r).unwrap();
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
char s[N]={0},t[N]={0};
int main()
{
	scanf("%s",s);
	for(int i=0;s[i];i++)
	{
		if(s[i]=='?')
			t[i]='D';
		else
			t[i]=s[i];
	}
	printf("%s",t);
	return 0;
}

Measured memory_bytes: 4212
/**
 *   author: r1933
**/
#include "bits/stdc++.h"

using namespace std;

#define all(x) x.begin(), x.end()
using i64 = long long;

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  bool yes = false;
  for (int i = 0; i < s.length() - 1; ++i) {
    if (s.substr(i, 2) == "AC") {
      yes = true;
      break;
    }
  }
  cout << (yes ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 256
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime


N,M = imn()
S = input()
T = input()

L = lcm(N,M)
g = gcd(N,M)

is_good = True
for i in range(L):
    s_index = i*N//g
    t_index = i*M//g
    if s_index >= N or t_index >= M: break
    if S[s_index] != T[t_index]:
        is_good = False
        break

print(L if is_good else -1)

Measured memory_bytes: 5552
fn main() {
    let n = read::<usize>();
    let mut v = read_vec::<i64>();
    v.insert(0, 0);
    v.push(0);
    let mut diffs = vec![];
    let mut diffs2 = vec![];
    for i in 0..n + 1 {
        diffs.push((v[i] - v[i + 1]).abs());
        if i != n {
            diffs2.push((v[i] - v[i + 2]).abs());
        }
    }
    let mut all = diffs.iter().sum::<i64>();
    for i in 0..n {
        println!("{}", all - diffs[i] - diffs[i + 1] + diffs2[i]);
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 9340
s = str(input())
t = str(input())
dict_s = {letter:s.count(letter) for letter in set(s)}
dict_t = {letter:t.count(letter) for letter in set(t)}
list_s = list(dict_s.values())
list_t = list(dict_t.values())
list_s.sort()
list_t.sort()
for letter in set(s):
  if s.count(letter) == 1:
    s = s.replace(letter, "@")
for letter in set(t):
  if t.count(letter) == 1:
    t = t.replace(letter, "@")
ans_s = []
ans_t = []
for letter in dict_s.keys():
  ans_s.append(([i for i, x in enumerate(s) if x == letter]))
for letter in dict_t.keys():
  ans_t.append(([i for i, x in enumerate(t) if x == letter]))
ans_s.sort()
ans_t.sort()
if ans_s == ans_t:
  print("Yes")
else:
  print("No")

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

using ll = long long;

constexpr double eps = 1e-8;
constexpr double gratio = (std::sqrt(5)+1)/2.0;

template <typename F>
double golden_section_search(F f, double lb, double ub, int cnt) {
    double x1 = (ub-lb)/(gratio+1) + lb,
           x2 = (ub-lb)*gratio/(gratio+1) + lb;
    double v1 = f(x1), v2 = f(x2);
    for(int i=0; i<cnt; ++i) {
        if(v1 < v2) {
            ub = x2;
            x2 = x1;
            v2 = v1;
            x1 = (ub-lb)/(gratio+1) + lb;
            v1 = f(x1);
        } else {
            lb = x1;
            x1 = x2;
            v1 = v2;
            x2 = (ub-lb)*gratio/(gratio+1) + lb;
            v2 = f(x2);
        }
    }
    return (lb+ub)/2;
}

int main() {
    int N;
    while(cin >> N, N) {
        double pw;
        cin >> pw;
        vector<double> vw(N), pf(N), vf(N), th(N);
        double res = 0;
        for(int i=0; i<N; ++i) {
            cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
            res += max(0.0, th[i] / vf[i] * pf[i]);
        }
        auto f = [&](double W) {
            double cost = W * pw;
            for(int i=0; i<N; ++i) {
                cost += max(0.0, (th[i] - vw[i] * W) / vf[i] * pf[i]);
            }
            return cost;
        };
        cout << fixed << setprecision(10) << f(golden_section_search(f, 0, 1e9, 300)) << endl;
    }
}


Measured memory_bytes: 6060
#include <iostream>
using namespace std;
int ary[60],res[40];
int main(){
	int N;
	for(int i=1;i<=51;i++){
		cin>>ary[i];
		if(cin.eof()){
			N=i-1;
			break;
		}
	}
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				for(int l=0;l<10;l++){
					res[i+j+k+l]++;
				}
			}
		}
	}
	for(int i=1;i<=N;i++){
		if(ary[i]>=0&&ary[i]<=36)cout<<res[ary[i]]<<endl;
		else cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 2988
import java.util.Scanner;

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

		String s = String.valueOf(S);
		String[] sarray = s.split("");
		String ans = "1";
		for (int i = 0; i < K; i++) {
			if (!sarray[i].equals("1")) {
				ans = (sarray[i]);
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    while(1){
        ll n; cin >> n;
        if(!n) break;
        vl a(n); rep(i,n) cin >> a[i];
        ll s = 0;
        ll ans = -linf;
        rep(i,n){
            s = max(s + a[i], a[i]);
            chmax(ans, s);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3140
# 500 yen
A = int(input())
# 100 yen
B = int(input())
# 50 yen
C = int(input())
# target
X = int(input())

cnt = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    int a[5]={0,0,0,0,0};
    int b[3]={0,0,0};
    for(int i=0;i<3;i++){
        cin >> n >> m;
        a[n]++;
        a[m]++;
    }
    if(a[1]<3 &&a[2]<3 &&a[3]<3 &&a[4]<3){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256