akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    double a = sc.nextInt();
    double b = sc.nextInt();
    double h = sc.nextInt();
    double m = sc.nextInt();
    
    double mAngle = 360 * (m / 60);
    double hAngle = (360 * (h / 12)) + (30 * (m / 60));
    double allAngle = 0;
    if (mAngle <= hAngle) {
      allAngle = hAngle - mAngle;
    } else {
      allAngle = mAngle - hAngle;
    }
    double cosine = Math.cos(Math.toRadians(allAngle));
    
    double area2 = (a * a) + (b * b) - (2 * a * b * cosine);
    double area = Math.sqrt(area2);
    
    System.out.println(area);
    
  }
}

Measured memory_bytes: 35984
#AtCoder
N, M = map(int, input().split())

s = set()
g = set()

for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        s.add(b)
    if b == N:
        g.add(a)

if s & g:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
    


Measured memory_bytes: 18936
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#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 pdd = pair<double,double>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;
const ll inf = (1LL<<58);

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
    int N; cin >> N;
    vector<ll> A(N);
    REP(i,N){
        cin >> A[i];
    }
    if(N % 2){
        vector<vector<ll> > tameshi(1,vector<ll>(N,0));
        vector<vector<vector<ll> > > dp(3,vector<vector<ll> >(2, vector<ll>(N+1,-inf)));  //3: 余裕がどれくらいあるか  2: 選んだか選ばなかったか  N+1: N個目
        dp[0][1][0] = 0;
        REP(i,N){
            REP(j,3){
                if(j == 0){
                    dp[j][0][i+1] = dp[j][1][i] + A[i];
                    dp[j][1][i+1] = dp[j][0][i];
                }
                else{
                    dp[j][0][i+1] = dp[j][1][i] + A[i];
                    dp[j][1][i+1] = max(dp[j][0][i], dp[j-1][1][i]);
                }
            }
        }

        ll ans = max({dp[0][0][N-2], dp[1][0][N-1], dp[2][0][N]});
        cout << ans << endl;
        return 0;
    }
    else{
        vector<vector<vector<ll> > > dp(2,vector<vector<ll> >(2, vector<ll>(N+1,-inf)));

        dp[0][1][0] = 0;
        REP(i,N){
            REP(j,2){
                if(j == 0){
                    dp[j][0][i+1] = dp[j][1][i] + A[i];
                    dp[j][1][i+1] = dp[j][0][i];
                }
                else{
                    dp[j][0][i+1] = dp[j][1][i] + A[i];
                    dp[j][1][i+1] = max(dp[j][0][i], dp[j-1][1][i]);
                }
            }
        }

        ll ans = max(dp[0][0][N-1], dp[1][0][N]);
        cout << ans << endl;
        return 0;
    }
        
}



Measured memory_bytes: 20480
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.next.toInt
    val vs = (1 to n).map(x => sc.next.toInt)
    val cs = (1 to n).map(x => sc.next.toInt)
    val d: Seq[Int] = vs zip cs map { case (v, c) => v - c }
    println(d.filter(_ >= 0).sum)

  }
}

Measured memory_bytes: 25756
#include<stdio.h>

int main(){
    int n,count=0,tmp,j;
    scanf("%d",&n);
    int h[n];
    for(int i=0;i<n;i++){
        scanf("%d ",&h[i]);
    }
    for(int i=0;i<n-1;i++){
        if(count>n-i)break;
        tmp=0;
        j=0;
        while(h[i+j]>=h[i+j+1]){
            tmp++;
            j++;
            if(i+j+1>=n)break;
        }
        if(tmp>count)count=tmp;
    }
    printf("%d",count);
    return 0;
}

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


#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;

const unsigned M = 1000000007;

unsigned mulm(unsigned a, unsigned b) {
	return ((ULL)a*b) % M;
}

void solve() {
	unsigned n, k; cin >> n >> k;
	unsigned dp[100001] = {};
	unsigned dp2[100001];
	dp[0] = 1;
	for (unsigned i = 0; i < n; i++) {
		dp2[0] = dp[0];
		for (int i = 1; i <= k; i++) {
			dp2[i] = (dp2[i - 1] + dp[i]) % M;
		}
		int a; cin >> a;
		for (int i = 0; i <= a; i++) {
			dp[i] = dp2[i];
		}
		for (int i = a + 1; i <= k; i++) {
			dp[i] = (dp2[i] + M - dp2[i - a - 1]) % M;
		}
	}
	cout << dp[k] << endl;
}

int main() {

	solve();

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   int cnt, div_num=0;
   for(cnt=a;cnt<=b;cnt++)
    if(c%cnt==0) div_num++;
   cout<<div_num;
   cout<<"\n";
    return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;



int main(){
	int N,K;
	cin >> N >> K;
	vector<P> a(N);
	for(int i = 0; i < N; i++) {
		ll t,d;cin>>t>>d;
		a[i] = mp(d,t);
	}
	sort(RALL(a));
	priority_queue<ll,vector<ll>,greater<ll>> que1;
	vector<bool> used(N + 1,false);//使ってるか
	ll sum = 0;
	ll kind = 0;
	ll res = 0;
	for(int i = 0; i < N; i++) {
		if (i < K){
			if (!used[a[i].sc]){
				sum += a[i].fs;
				kind ++;
				used[a[i].sc] = true;
			}
			else{
				sum += a[i].fs;
				que1.push(a[i].fs);
			}
			res = max(res,sum + kind * kind);
		}
		else{
			if (que1.empty())break;
			if (!used[a[i].sc]){
				sum += (a[i].fs - que1.top());
				kind++;
				used[a[i].sc] = true;
				que1.pop();
				res = max(res,sum + kind * kind);
			} 
		}
	}
	cout << res << endl;
	return 0;
}


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

int main(){
 char S[3];cin>>S;
  int a=0,b=0,c=0;
  for(int i=0;i<3;i++){
  if(S[i]=='a')a++;
    else if(S[i]=='b')b++;
    else if(S[i]=='c')c++;
  }
  if(a==1&&b==1&&c==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {


    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        long sum = 0;
        for (int i = 0; i < n - k; i++) {
            sum += a[i];
        }
        out.println(sum);
    }

}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer      tokenizer;

    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////




ll N;
ll i, j, k;


int main(){
    scanf("%lld", &N);
    i = N / 2 + N % 2;
    printf("%.12lf", (double)i/N);
    return 0;
}

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

typedef long long ll;

const int MAX = 50 + 5;

int N, M, Q, score = 0;
int a[MAX];
int b[MAX];
int c[MAX];
int d[MAX];
int arr[MAX];


void sub(int i, int prev) {
    if (i > N) {
        int sum = 0;
        for (int i = 0; i < Q; i++) {
            if (arr[b[i]] - arr[a[i]] == c[i]) {
                sum += d[i];
            }
        }
        score = max(score, sum);
        return;
    }
    for (int j = prev; j <= M; j++) {
        arr[i] = j;
        sub(i + 1, j);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    sub(1, 1);
    cout << score;
}


Measured memory_bytes: 3664
def main():
    n=int(input())
    ans=0
    bit=[0]*60
    seki=10**9+7
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(60):
            if a[i]%2==1:
                bit[j]+=1
            a[i]=a[i]>>1
    for i in range(60):
        ans+=(bit[i]*(n-bit[i]))*(2**i)
    print(ans%seki)
main()

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

class UnionFind {
    vector<int> par;
    int cnt;
public:
    UnionFind(int size_) : par(size_, -1), cnt(size_) { }
    void unite(int x, int y){
        if ((x = find(x)) != (y = find(y))) {
            if (par[y] < par[x]) swap(x, y);
            par[x] += par[y]; par[y] = x; cnt--;
        }
    }
    bool same(int x, int y){ return find(x) == find(y); }
    int find(int x){ return par[x] < 0 ? x : par[x] = find(par[x]); }
    int size(int x){ return -par[find(x)]; }
    int size(){ return cnt; }
};

int N, W, H;
map<int, vector<int>> Xs, Ys;

int main(){
    cin >> N >> W >> H;
    for(int i=0; i<N; i++){
        int x, y; cin >> x >> y;
        if(Xs.find(x) == Xs.end()) Xs[x] = vector<int>();
        if(Ys.find(y) == Ys.end()) Ys[y] = vector<int>();
        Xs[x].push_back(i);
        Ys[y].push_back(i);
    }
    
    UnionFind uf = UnionFind(N);
    auto l = {Xs, Ys};
    for(auto X: l){
        for(auto u: X){
            for(int i=0; i<u.second.size()-1; i++){
                uf.unite(u.second[i], u.second[i+1]);
            }
        }
    }
    
    map<int, int> sizes;
    for(int i=0; i<N; i++){
        sizes[uf.find(i)] = uf.size(i);
    }
    
    int ans = 0;
    for(auto v: sizes){
        ans += v.second-1;
    }
    
    if(uf.size() != 1){
       ans += 2*uf.size() - 1;
        if(Xs.count(1) || Xs.count(W) || Ys.count(1) || Ys.count(H))
            ans--;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 21192
n = int(input())
x = list(map(int, input().split()))

x.sort()
x.reverse()

A = []
B = []
for i in range(len(x)):
  if i%2==0:
    m = max(x)
    A.append(m)
    x.remove(m)
  else:
    m = max(x)
    B.append(m)
    x.remove(m)

C = sum(A) - sum(B)
print(C)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define isEven(t) t%2==0
signed main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n)cin>>a[i];
  int b[n];
  rep(i,n){
    b[i]=(a[i]-(i+1));
  }
  sort(b,b+n);
  int res=0;
  rep(i,n)res+=abs(b[i]-b[n/2]);
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>

int main(void)
{
	int i,j,k,l;
	int a[10];

	for(i = 0;i < 10;i++)
	{
		scanf("%d",&a[i]);
	}

	for(i = 0;i <3;i++)
	{
		k = a[0];
		for(j = 0;j < 10;j++)
		{
			if(a[j] > k)
			{
				k = a[j];
				l = j;
			}
		}
		printf("%d\n",k);
		a[l] = -1;
	}

	return 0;
}

Measured memory_bytes: 600
#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#define p64 PRId64

#include <algorithm>
#include <cinttypes>
#include <cstdio>

using namespace std;
using ll = int64_t;

const int INF = 1000000007;

ll firstOne;
ll firstTwo;

ll secondOne;
ll secondTwo;

void FindArea(ll i, ll j)
{
    ll iHalf = i / 2;
    ll jHalf = j / 2;

    firstOne = iHalf * j;
    firstTwo = (i - iHalf) * j;
    secondOne = i * jHalf;
    secondTwo = i * (j - jHalf);
}

int main()
{
    ll H, W;
    if (scanf("%" p64 "%" p64, &H, &W) < 2) return 0;

    ll ans = (ll)INF;

    // 縦に分割する
    // 一番上の縦幅を決める
    for (int i = 1; i < H; i++)
    {
        ll top = (ll)i * W;

        FindArea(H - (ll)i, W);
        
        ll firstMin = min(top, min(firstOne, firstTwo));
        ll firstMax = max(top, max(firstOne, firstTwo));
        ans = min(ans, firstMax - firstMin);

        ll secondMin = min(top, min(secondOne, secondTwo));
        ll secondMax = max(top, max(secondOne, secondTwo));
        ans = min(ans, secondMax - secondMin);
    }

    // 横に分割する
    // 一番左の横幅を決める
    for (int i = 1; i < W; i++)
    {
        ll left = H * (ll)i;

        FindArea(H, W - (ll)i);

        ll firstMin = min(left, min(firstOne, firstTwo));
        ll firstMax = max(left, max(firstOne, firstTwo));
        ans = min(ans, firstMax - firstMin);

        ll secondMin = min(left, min(secondOne, secondTwo));
        ll secondMax = max(left, max(secondOne, secondTwo));
        ans = min(ans, secondMax - secondMin);
    }

    printf("%" p64 "\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll n, r; cin >> n >> r;

    if(n >= 10){
        cout << r << endl;
    }
    else{
        cout << r + 100 * (10 - n) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <typeinfo>
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

int main(){
  string s;
  cin >> s;
  string s1 = "2019/04/30";
  if(s>s1){
    cout << "TBD" << endl;
  }else{
    cout << "Heisei" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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 <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll A, B;
  cin >> A >> B;
  ll AB = A * B;
  ll AmB = A - B;
  ll ApB = A + B;

  ll ans = max(ApB, max(AB, AmB));
  COUT(ans);
  return 0;
}

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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))


void quick_sort (int array[],int sub_array1[],int sub_array2[], int left, int right);
void swap_int (int *x,  int *y);
int partition (int array[],int sub_array1[],int sub_array2[], int left, int right);



void swap_int (int *x,  int *y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
 
int partition (int array[],int sub_array1[],int sub_array2[], int left, int right) {
    int i, j, pivot;
    i = left;
    j = right + 1;
    pivot = left;   // 先頭要素をpivotとする
 
    do {
        do { i++; } while (array[i] < array[pivot]);
        do { j--; } while (array[pivot] < array[j]);
        // pivotより小さいものを左へ、大きいものを右へ
        if (i < j) {
            swap_int(&array[i], &array[j]);
            swap_int(&sub_array1[i], &sub_array1[j]);
            swap_int(&sub_array2[i], &sub_array2[j]);
        }
    } while (i < j);
 
    swap_int(&array[pivot], &array[j]);   //pivotを更新
    swap_int(&sub_array1[pivot], &sub_array1[j]);   //pivotを更新
    swap_int(&sub_array2[pivot], &sub_array2[j]);   //pivotを更新
    return j;
}
 

void quick_sort (int array[],int sub_array1[],int sub_array2[], int left, int right) {
    int pivot;
    if (left < right) {
        pivot = partition(array,sub_array1,sub_array2, left, right);
        // pivotを境に再帰的にクイックソート
        quick_sort(array,sub_array1,sub_array2, left, pivot-1);
        quick_sort(array,sub_array1,sub_array2, pivot+1, right);
    }
}


SINT32 main() {
    SINT32 n,m;
    scanf("%d%d",&n,&m);
    int *year = malloc(sizeof(int)*100001);
    int *city = malloc(sizeof(int)*100001);
    int *num = malloc(sizeof(int)*100001);
    int *haya2 = malloc(sizeof(int)*100001);

    int *haya = malloc(sizeof(int)*100001);

    for (SINT32 i = 0; i < 100001; i++) {
        city[i] = 0;
        year[i] = 0;
        num[i] = 0;
        haya[i] = 0;
        haya2[i] = 0;
    }


    for (SINT32 i = 0; i < m; i++) {
        scanf("%d%d", &city[i],&year[i]);
        num[i] = i;
    }

    quick_sort(year,city,num, 0, m-1);

    for (SINT32 i = 0; i < m; i++) {
        haya[city[i]] = haya[city[i]] + 1;
        haya2[i] = haya[city[i]];
    }
/*
    for (SINT32 i = 0; i < m; i++) {
        printf("%d ",num[i]);
    }
    printf("\n");
    */

    quick_sort(num,city,haya2, 0, m-1);
/*
    for (SINT32 i = 0; i < m; i++) {
        printf("%d ",num[i]);
    }
    printf("\n");
    */


    for (SINT32 i = 0; i < m; i++) {
        printf("%06d%06d\n",city[i],haya2[i]);
    } 

    
	return 0;
}

Measured memory_bytes: 3328
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
using namespace std;
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
int main() {
	string s;
	cin >> s;
	int a=0, b=0, c=0;
	TFOR(i, s.size()) {
		if (s[i] == 'a')++a;
		if (s[i] == 'b')++b;
		if (s[i] == 'c')++c;
	}
	cout << (max(abs(a - b), max(abs(b - c), abs(c - a))) <= 1 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 512
//b 点
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,m,ans=0,x,y;
	cin>>n>>m;
	for (long long i=1;i<=n;++i) {
		cin>>x>>y;
		if (x*x+y*y<=m*m){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	ll k,n;
	cin>>n>>k>>s;k--;
	s[k]=s[k]-'A'+'a';
	cout<<s;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n,k,q;
ll a[2005];
ll b[2005];
ll in[2005];
bool cmp(ll i,ll j)
{
	return a[i]>a[j];
}
bool check(ll l,ll r)
{
	for(int i=1;i<=n;i++)
	{
		if(a[i]<=r&&a[i]>=l)
			b[i]=1;
		else if(a[i]<l)
			b[i]=0;
		else
			b[i]=2;
	}
//	for(int i=1;i<=n;i++)
//		cout<<b[i]<<" ";
	//cout<<endl;
	ll op=0;
	ll i=1,j=1;
	while(i<=n&&j<=n)
	{
		while(i<=n&&b[i]==0)i++;
		j=i;
		ll cnt=0;
		while(j<=n&&(b[j]==1||b[j]==2))
		{
			if(b[j]==1)
				cnt++;
			j++;
		}
	//	cout<<i<<" "<<j<<endl;
		ll x=j-i;
		if(x>=k)
		{
			op+=min(x-k+1,cnt);
		}
	//	cout<<cnt<<" "<<op<<endl;
		i=j;
	}
	return (op>=q);
}
ll solve(ll i)
{
	ll x=a[i];
	ll l=0,r=x+1;
	ll mid=(l+r)>>1;
	if(!check(0,x))return INF;
	if(check(x,x))return 0;
	while(r-l>1)
	{
		if(check(mid,x))
			l=mid;
		else
			r=mid;
		mid=(l+r)>>1;
	}
	if(mid<x&&check(mid+1,x))mid++;
	if(!check(mid,x))mid--;
	return (x-mid);
}
int main()
{
	SPEED;
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++)
		cin>>a[i],in[i]=i;
	sort(in+1,in+n+1,cmp);
	ll ans=INF;
	for(int i=1;i<=n;i++)
	{
		ans=min(ans,solve(in[i]));
	}
	cout<<ans<<endl;
	//cout<<check(1,8)<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// int ans=0;
// void dfs(vector<int>&visited,int cur,vector<int>graph[],int& counter)
// {
//     visited[cur]=true;
//     counter++;
//     if(counter>ans)
//     ans=counter;
//     for(int i=0;i<graph[cur].size();i++)
//     {
//         if(!visited[graph[cur][i]])
//         {
//             dfs(visited,graph[cur][i],graph,counter);

//         }
//     }
//     visited[cur]=false;
//     counter--;

// }
ll nodes,edges,src,dest;
ll dp[100005];
ll indegree[100005];
queue<ll>q;
vector<ll>graph[100005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>nodes>>edges;

    for(int i=0;i<edges;i++)
    {
        cin>>src>>dest;
        indegree[dest]++;
        graph[src].push_back(dest);
    }
    for(int i=1;i<=nodes;i++)
    {
        if(indegree[i]==0)
        q.push(i);
    }
    ll ans=0;
    while(!q.empty())
    {
        ll t=q.front();
        q.pop();

        for(int i=0;i<graph[t].size();i++)
        {
            indegree[graph[t][i]]--;
            dp[graph[t][i]]=max(dp[graph[t][i]],dp[t]+1);
            ans=max(ans,dp[graph[t][i]]);
            if(indegree[graph[t][i]]==0)
            {
                q.push(graph[t][i]);
            }
        }

    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 7296
n = int(input())
d = []
for i in range(n):
  d.append(input().split())
ans = 'No'
for i in range(n - 2):
  if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
    ans ='Yes'
    break

print(ans)


Measured memory_bytes: 62196
#include <stdio.h>
#include<math.h>
#include <stdlib.h>

int main(){

  int i,j;
  int a,b,c,d;

  scanf("%d %d %d %d",&a,&b,&c,&d);
  if(abs((a-c))<=d){
    printf("Yes");
  }
  else{
    if(abs(a-b)<=d && abs(b-c)<=d){
      printf("Yes");
    }
    else{
      printf("No");
    }
    }

  return 0;
}


Measured memory_bytes: 128
#include <cstdio>

#define MAX 20000

int split2(long int num)
{
	int count=0;
	while(num%2==0){
		num = num/2;
		count++;
	}
	return count;
}

int main()
{
	int N, count = 0;
	long int A[MAX];
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%ld", &A[i]);
		count += split2(A[i]);
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int mae = scanner.nextInt();
        int ato = scanner.nextInt();
        int goukei = scanner.nextInt();
        int tuuka = 0;
        int zeikomi = 0;
        while (mae != 0 && ato != 0 && goukei != 0) {
            for (int syou = 1; syou < goukei; syou++) {
                for (int hinn = 1; hinn < goukei; hinn++) {
                    if ((syou * (100 + mae) / 100) + (hinn * (100 + mae) / 100) == goukei) {

                        tuuka = (syou * (100 + ato) / 100 + hinn * (100 + ato) / 100);
                        if (tuuka > zeikomi) {
                            zeikomi = tuuka;
                        }

                    }

                }
            }
            System.out.println(zeikomi);
            mae = scanner.nextInt();
            ato = scanner.nextInt();
            goukei = scanner.nextInt();
            zeikomi=0;
        }

    }
}



Measured memory_bytes: 29144
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] >= k) {
                break;
            }

            int s = (i == 0 ? 1 : 0);
            int sum = a[i];
            boolean isNeed = false;
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }

                sum += a[j];
                if (sum >= k) {
                    while (sum - a[s] >= k) {
                        sum -= a[s++];
                        if (s == i) {
                            s++;
                        }
                    }

                    if (sum - a[i] < k) {
                        isNeed = true;
                        break;
                    }
                }
            }

            if (!isNeed) {
                ans++;
            }
        }

        System.out.println(ans);
    }

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


Measured memory_bytes: 30228
/////////////////////////////////////////////////
/////             Give me AC!!!!            /////
/////////////////////////////////////////////////
//↑これじゃ気合いが足りない！
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////             お願いしますACをくださいそうじゃないと僕泣きますお願いしますACをくださいJudge様....            /////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const int MOD = 1000000007;
const int MAX = 100000;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
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;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
ld rad(ld a) {return a * 180 / PI;}
const int dx[4] = {1, 0, -1, 0};//2次元グリッド上のx軸方向
const int dy[4] = {0, 1, 0, -1};//2次元グリッド上のy軸方向

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

map<ll,ll> factorize_list;

void prime_factorize(ll N) {
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        factorize_list[a] = ex;
    }

    // 最後に残った数について
    if (N != 1) factorize_list[N] = 1;
    return ;
}

//dpTable
vector<ll> dp(100,MAX);

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

long long fac[MAX], finv[MAX], inv[MAX];

char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}
char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}

const ll INF = 10000000000;
struct edge{ll to, cost;};

int main(){
    ll N;
    cin >> N;
    prime_factorize(N);
    ll ans = 0;
    for (auto p : factorize_list) {
        for (int i = 1; i < 100; i++) {
            if (i * (i + 1) / 2 > p.second) {
                ans += i - 1;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int N, M, Q;
ll res=0;
vector<int> a, b, c, d;
vector<int> A;

void rec(int prev, int n){
    if(n == N){
        ll total=0;
        for(int i=0; i<Q; i++){
            if(A[b[i]]-A[a[i]] == c[i]) total+=d[i];
        }
        res=max(res, total);
        return;
    }
    for(int i=prev; i<=M; i++){
        A[n]=i;
        rec(i, n+1);
    }
    return;
}

int main(){
    cin >> N >> M >> Q;
    A.resize(N);
    a.resize(Q), b.resize(Q), c.resize(Q), d.resize(Q);
    for(int i=0; i<Q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }
    rec(1, 0);
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3648
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
MOD = 10 ** 9 + 7

def prime_factorize(n): # Nの素因数分解
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def combination(n, x, mod=10**9+7):
    # nCx 組み合わせ ex) combination(5, 2) = 10
    factorial = [1] * (n+1)
    t = 1
    for i in range(1, n+1):
        t = (t * i) % mod
        factorial[i] = t
    tmp = factorial[n]
    tmp = (tmp * pow(factorial[x], mod-2, mod)) % mod
    tmp = (tmp * pow(factorial[n-x], mod-2, mod)) % mod
    return tmp

A = prime_factorize(M)
counter = Counter(A)
answer = 1
for c in counter.values():
    answer *= combination((N-1+c), c)
    answer %= MOD

print(answer)
# 19

Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    constexpr int N = 2e5;
    int n;cin >> n;
    int a[N+10];

    int first = 0;
    int second = 0;

    REP(i,n) {
        cin >> a[i];
        if (first <= a[i]) {
            swap(first,second);
            first = a[i];
        } else if (second < a[i]) {
            second = a[i];
        }
    }

    REP(i,n) {
        if (a[i] == first) {
            cout << second << endl;
        } else {
            cout << first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    ans = [[0] * 3 for _ in range(3)]
    for b in B:
        for i, a in enumerate(A):
            g = my_index(a, b)
            if g != 'no':
                ans[i][g] = 1
    for r in range(3):
        if 1 == ans[0][r] == ans[1][r] == ans[2][r]:
            print('Yes')
            exit()
    for r in range(3):
        if 1 == ans[r][0] == ans[r][1] == ans[r][2]:
            print('Yes')
            exit()
    if 1 == ans[0][0] == ans[1][1] == ans[2][2]:
        print('Yes')
        exit()
    if 1 == ans[0][2] == ans[1][1] == ans[2][0]:
        print('Yes')
        exit()
    print('No')

def my_index(l, x):
    return l.index(x) if x in l else 'no'

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll n, k;

int main() {
    cin >> n >> k;
    vector<int> pvec(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> pvec[i]; pvec[i]--;
    }
    vector<ll> cvec(n, 0);
    for(int i = 0; i < n; ++i) cin >> cvec[i];
    vector<bool> check(n, false);
    vector< vector<ll> > tree;
    for(int i = 0; i < n; ++i) {
        if(!check[i]) {
            check[i] = true;
            vector<ll> subtree;
            subtree.emplace_back(cvec[i]);
            int now = pvec[i];
            while(now != i) {
                subtree.emplace_back(cvec[now]);
                check[now] = true;
                now = pvec[now];
            }
            tree.emplace_back(subtree);
        }
    }
    // 各サイクルを構築
    /*for(auto x:tree) {
        for(auto y:x) {
            cout << y << " ";
        }
        cout << endl;
    }*/

    ll ans = -1e18;
    for(auto x : tree) {
        int xlen = x.size();
        int xxlen = 2*xlen;
        vector<ll> xx(xxlen, 0);
        for(int i = 0; i < xlen; ++i) {
            xx[i] = x[i], xx[i+xlen] = x[i];
        }
        vector<ll> xsum(xxlen+1, 0);
        for(int i = 0; i < xxlen; ++i) {
            xsum[i+1] += (xsum[i]+xx[i]);
        }

        // 1週目はxlen-1回でいける
        // 1周しない最大
        ll sum = -1e18;
        ll xmax = xsum[xlen]-xsum[0];
        int limit = min(k, (ll)xlen);
        for(int i = 0; i < xlen; ++i) {
            for(int j = 1; j <= limit; ++j) {
                int sl = i+1, sr = i+1+j;
                chmax(sum, xsum[sr]-xsum[sl]);
            }
        }

        // 何周かした後
        ll kcnt = k/xlen;
        // kcnt = 0なら1周できない, kcnt > 0なら1周はできる
        for(int i = 0; i < xlen; ++i) {
            ll rest = k-kcnt*xlen;
            ll xxx = kcnt*xmax;
            int limit = min(rest, (ll)xlen);
            for(int j = 1; j <= limit; ++j) {
                int sl = i, sr = i+j;
                chmax(sum, xxx+xsum[sr]-xsum[sl]);
                // cout << "now " << xxx+xsum[sr]-xsum[sl] << endl;
            }
        }
        if(kcnt > 0) {
            for(int i = 0; i < xlen; ++i) {
                ll xxx = (kcnt-1)*xmax;
                for(int j = 1; j <= xlen; ++j) {
                    int sl = i, sr = i+j;
                    chmax(sum, xxx+xsum[sr]-xsum[sl]);
                }
            }
        }
        chmax(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int d;
    cin>>d;
    vector<int>c(26),t(d),nod(26);
    rep(j,26)cin>>c[j];
    vector<vector<int>>s(d,vector<int>(26));
    rep(i,d)rep(j,26)cin>>s[i][j];
    //rep(i,d)cin>>t[i];
    int pt=0,mx,tx;
    rep(i,d){
        mx=-1000000;
        rep(j,26){
            tx=max(s[i][j],nod[j]*c[j]*-1);
            if(tx>mx){
                mx=tx;
                t[i]=j+1;
            }
        }
        
        rep(j,26){
            if(t[i]-1==j){
                pt+=s[i][j];
                nod[j]=0;
            }
            else{
                nod[j]++;
                pt-=c[j]*nod[j];
            }
        }
        //cout<<pt<<endl;
        
    }
    rep(i,d)cout<<t[i]<<endl;
	return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

vector<int> edge[200000];
ll cnt[200000];
ll ans[200000];

void dfs(int pos, int bef, ll sum) {
  sum += cnt[pos];
  ans[pos] = sum;

  rep(i, edge[pos].size()) {
    int next = edge[pos][i];
    if (next == bef) continue;
    dfs(next, pos, sum);
  }
}

int main() {
  int N, Q;
  cin >> N >> Q;
  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].eb(b);
    edge[b].eb(a);
  }
  rep(i, Q) {
    int p, x;
    cin >> p >> x;
    p--;
    cnt[p] += x;
  }
  dfs(0, -1, 0);

  rep(i, N) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}


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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int r,g,b;
    cin>>r>>g>>b;
    int num = r * 100 + g * 10 + b;
    if (num % 4 == 0) {
        cout << "YES" << endl;
    } else cout << "NO" << endl;
    
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
import numpy as np
n, k=map(int,input().split())

a = list(map(int,input().split()))

 
s = list()
ord = np.full(n+1, -1)
c=1
l=0

v=1
while ord[v]==-1:
    ord[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-ord[v]
l=ord[v]

if k<l:
    print(s[k])  
else:
    k-=l
    k%=c
    print(s[l+k])


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

const int N = 1e5;

vector<int> arr[26];
vector<int> cnt(26,0);

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	string s,t;
	cin >> s;
	cin >> t;

	for(int i = 0;i < s.size();i++){
		arr[s[i]-'a'].push_back(i);
	}

	int rep = 0;
	int last = -1;
	bool not_possible = false;

	for(int i = 0;i < t.size();i++){
		if(arr[t[i]-'a'].size() == 0){
			not_possible = true;
			break;
		}

		int n_pos = upper_bound(arr[t[i]-'a'].begin(),arr[t[i]-'a'].end(),last) - arr[t[i]-'a'].begin();

		if(n_pos == arr[t[i]-'a'].size()){
			rep++;
			n_pos = 0;
		}

		last = arr[t[i]-'a'][n_pos];


	}

	if(not_possible) cout << -1 << endl;

	else{
		long long ans = (long long)((long long)rep*(long long)s.size() + (long long)last + 1LL);
		cout << ans << endl;
	}



}

Measured memory_bytes: 1216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int a[N];

int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++) cin>>a[i];
        int cnt=0;
        for(int i=1;i<=n;i++){
            if(a[i]==i){
                cnt++;
                swap(a[i],a[i+1]);
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


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

#define pb push_back
#define mp make_pair

using namespace std;

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

int main() {
  int d[26] = {0};

  string s;
  cin >> s;

  bool ok = true;
  for (char c : s) {
    if (d[c-'a'] != 0) {
      ok = false;
      break;
    } else {
      d[c-'a']++;
    }
  }

  if (ok) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
// ??????????????¢?????????????????????
        // boolean ret = a < b || b < c;
        boolean ret = a < b && b < c;
        System.out.println(ret ? "Yes" : "No");
    }
}

Measured memory_bytes: 17172
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}

const int mod = 1e9+7;
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int T;
ll N, A, B, C, D;
map<ll, ll> dp;
ll dfs(ll x)
{
	if (dp.find(x)!=dp.end()) return dp[x];
	ll &ans = dp[x];
	if (1.0*D*x<1e18) ans = D*x; else ans = 1e18;
	ans = min(ans, A+(x%2)*D+dfs(x/2));
	ans = min(ans, A+(2-x%2)*D+dfs(x/2+1));
	ans = min(ans, B+(x%3)*D+dfs(x/3));
	ans = min(ans, B+(3-x%3)*D+dfs(x/3+1));
	ans = min(ans, C+(x%5)*D+dfs(x/5));
	ans = min(ans, C+(5-x%5)*D+dfs(x/5+1));
	return ans;
}
int main()
{
	cin>>T;
	while (T--)
	{
		cin>>N>>A>>B>>C>>D;
		dp.clear();
		dp[0] = 0;
		cout<<dfs(N)<<endl;
	}
	return 0;
}

Measured memory_bytes: 4632
n = int(input()) 
a = list(map(int,input().split()))

q = n // 3 
r = n % 3

dic = {}
for i in range(n):
    if a[i] not in dic:
        dic[a[i]] = 1
    else:
        dic[a[i]] += 1

res = "No"

if len(dic) == 1:
    if a[0] == 0:
        res = "Yes"
elif len(dic) == 2:
    x,y = tuple(dic.keys())
    if (x == 0 or y == 0) and r == 0:
        if x == 0:
            x = y
        if dic[x] == 2 * q and dic[0] == q:
            res = "Yes"
elif len(dic) == 3:
    x,y,z = tuple(dic.keys())
    if x ^ y == z:
        count1 = 0
        count2 = 0
        for i in (x,y,z):
            if dic[i] == q:
                count1 += 1
            elif dic[i] == q + 1:
                count2 += 1
        if count1 == 3 - r and count2 == r:
            res = "Yes"
print(res)


Measured memory_bytes: 14116
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

int main()
{
	int n, m;

	cin >> n >> m;
	vector<int> a(n, 0);


	for (int i = 0; i < m + m; i++) {
		int x;
		cin >> x;
		a[x - 1]++;
	}
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}

	

	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  int N,K;
  cin>>N>>K;
  
  vector<double> P(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  
  vector<double> exp(N);
  for(int i=0;i<N;i++){
    exp[i]=(P[i]+1)/2;
  }
  
  vector<double> sum(N);
  sum[0]=exp[0];
  for(int i=1;i<N;i++){
    sum[i]+=(exp[i]+sum[i-1]);
  }
  
  
  double ans=sum[K-1];
  
  for(int i=0;i<=N-K;i++){
    ans=max(ans,sum[K+i]-sum[i]);
  }
  
  cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 8052
/*
* @Author: _dp95
* @Date:   2019-02-10 15:01:58
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 2*1000*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

ll dp[ MAX ], ar[ MAX ] ;

int main( ){
  timesaver ;
  int n ;
  cin >> n ;
  for( int i = 0 ; i < n ; i++ ){
    cin >> ar[ i ] ;
  }
  dp[ 0 ] = 0 ;
  dp[ 1 ] = abs( ar[ 1 ] - ar[ 0 ] );
  for( int i = 2 ; i < n ; i++ ){
      dp[ i ] = min( dp[ i - 1 ] + abs( ar[ i - 1 ] - ar[ i ] ), dp[ i - 2 ] + abs( ar[ i ] - ar[ i - 2 ] ) ) ;
  }
  cout << dp[ n - 1 ] << nl ;
}

Measured memory_bytes: 5120