akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int sum=0;
	int ma=0;
	rep(i,n){
		int l;
		cin>>l;
		chmax(ma,l);
		sum+=l;
	}
	sum-=ma;
	if(ma<sum) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

a,b = get_nums_l()

x = str(a) * b
y = str(b) * a

if x < y:
    print(x)
else:
    print(y)

Measured memory_bytes: 38384
import math


def main():
    N, x = [int(a) for a in input().split()]
    ai = sorted([int(a) for a in input().split()])

    bi = []
    t = 0
    for a in ai:
        t += a
        bi.append(t)

    def solve():
        cc = 0
        for i in range(N):
            if bi[i] < x:
                cc += 1
                continue
            if bi[i] == x:
                return cc + 1
            if bi[i] > x:
                return cc
        return cc - 1

    cc = solve()
    print(cc)


if __name__ == '__main__':
    main()


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

int Partition(int *,int,int);
void Print(int *,int,int);

int main(){
  int i,q,N;
  int *A;
  scanf("%d",&N);

  A=(int*)malloc(N*sizeof(int));
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  q=Partition(A,0,N);
  Print(A,N,q);
  return 0;
}

int Partition(int *A,int p,int r){

  int x,i,j,t;

  x=A[r-1];
  i=p-1;
  for(j=p;j<r-1;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r-1];
  A[r-1]=t;
  return i+1;
}

void Print(int *A,int N,int r){
  int i;

  for(i=0;i<N;i++){
    if(i==r){
      printf("[%d] ",A[i]);
    }
      else if(i==N-1){
	printf("%d\n",A[i]);
      }
      else{
	printf("%d ",A[i]);
      }
  }
}
      



Measured memory_bytes: 2104
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;

ll n, p, i, j, ans, l;

int main()
{
  scanf("%lld%lld",&n,&p);
  if(n==1)printf("%lld\n",p);
  else if(p==1)printf("1\n");
  else {
    ans=1;
    j=0;while(p%2==0){p/=2;j++;} if(j/n>0) ans*=pow(2,j/n);
    for(i=3, l=sqrt(p)+1;i<l;i+=4){
      j=0;while(p%i==0){p/=i;j++;} if(j/n>0) ans*=pow(i,j/n);
      j=0;while(p%(i+2)==0){p/=(i+2);j++;} if(j/n>0) ans*=pow((i+2),j/n);
    }
    printf("%lld\n",ans);
  }
  return 0;
}

Measured memory_bytes: 128
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n = ni()
cnt = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for i in range(n):
    s = ns()
    cnt[s] += 1

print("AC x", cnt["AC"])
print("WA x", cnt["WA"])
print("TLE x", cnt["TLE"])
print("RE x", cnt["RE"])

Measured memory_bytes: 9220
using System;
using System.Text;

class Program
{
    static void Main()
    {
        int taro = 0, hanako = 0;
        int n = int.Parse(Console.ReadLine());
        for(int i =0;i<n;i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            int x = string.Compare(s[0], s[1]);
            if (x == 0)
            {
                taro += 1;
                hanako += 1;
            }
            else if (x > 0)
                taro += 3;
            else if (x < 0)
                hanako += 3;
        }
        Console.WriteLine("{0} {1}",taro,hanako);
    }
}

Measured memory_bytes: 10004
#include <iostream>
 
using namespace std;
 
const int MAXN = 110;
const int MOD = 1000000007;
const int64_t INFINITE = 1e12;
const int MAXW = 100010;
const int MAXP = 100010;
int64_t DP[MAXN][MAXP];
int N;
int64_t Weight[MAXN];
int64_t Price[MAXN];
int64_t W;
 
int main(){
 
    cin >> N >> W;
    int64_t sum = 0;
    for (int i = 1; i <= N; i++) {
        cin >> Weight[i] >> Price[i];
        sum += Price[i];
    }
 
    for (int i = 0; i <= N; i++) {
        for (int j = 1; j <= sum; j++) {
            DP[i][j] = INFINITE;
        }
    }
 
    for (int price = 1; price <= sum; price++) {
        if (price == Price[1]) DP[1][price] = Weight[1];
    }
    int64_t ans = -INFINITE;
    DP[1][0] = 0;
    if (N == 1) {
        if (Weight[1] <= W) {
            ans = Price[1];
        } else {
            ans = 0;
        }
    }
 
    for (int id = 2; id <= N; id++) {
        for (int64_t price = 1; price <= sum; price++ ) {
            if (price + Price[id] > sum) {
                DP[id][price] = DP[id - 1][price];
            }
            DP[id][price] = min(DP[id - 1][price], DP[id - 1][price - Price[id]] + Weight[id]);
            if (DP[id][price] <= W) {
                ans = max(ans, price);
            }
        }
    }
 
    cout << ans;
 
    return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define FOR(x,y) for(int i=x; i<y; ++i)
#define FORR(x,y) for(int i=y-1; i>=x; i--)

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> arr(n);
    FOR(0,n){
        cin >> arr[i];
    }
    sort(arr.begin(),arr.end());
    cout << arr[n-1] - arr[0] << endl;
  return 0;
}

Measured memory_bytes: 3644
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = scan.nextInt();
        long ans = 0L;
        int h = a[0];
        for (int i = 1; i < n; i++) {
            ans += Math.max(0, h - a[i]);
            h = Math.max(h, a[i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 60296
// ALDS1_2_A バブルソート

#include <iostream>

using namespace std;

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

  int flag = 1;
  int xCount = 0;
  while(flag){
    flag = 0;
    for (int j = N - 1; j >= 1; j--){
      if (A[j] < A[j - 1]){
        int tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
        xCount++;
        flag = 1;
      }
    }
  }

  for (int i = 0; i < N; i++){
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << xCount << endl;

  delete[] A;
  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


const int node_max = 100050;

vector<vector<P>> root(node_max);
vector<bool> visited(node_max, false);
vector<ll> len(node_max, MOD);

bool bfs(int v){
    queue<int> q;
    q.push(v);
    len[v] = 0;
    visited[v] = true;

    while(!q.empty()){
        int now = q.front(); q.pop();
        for(auto next: root[now]){
            if (visited[next.first] != true){
                len[next.first] = len[now] + next.second;
                visited[next.first] = true;
                q.push(next.first);
            } else {
                if (len[next.first] != len[now] + next.second){
                    return false;
                }
            }
        }
    }
    return true;
}

int main()
{
    int n, m;
    cin >> n >> m;
    rep(i, m){
        int l,r,d;
        cin >> l >> r >> d;
        l--; r--;
        root[l].push_back({r, d});
        root[r].push_back({l, -d});
    }

    bool ans = true;
    rep(i, n){
        if (visited[i] == false){
            if(!bfs(i)) {ans = false; break;}
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

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

using namespace std;
using ll = int64_t;

constexpr int INF = (1 << 30);
constexpr ll INFL = (1LL << 62);
constexpr ll MOD = 1000000007;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};

int main() {
    cout << std::fixed << std::setprecision(10);
    int n;
    cin >> n;
    vector<int> l(2 * n);
    rep(i, 2 * n) { cin >> l[i]; }
    sort(all(l));
    ll ans = 0;
    for (int i = 0; i < 2 * n; i += 2) {
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}


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

class Node {
 public:
  int location;
  int p, l, r;
  Node() {}
};

class Point {
 public:
  int id, x, y;
  Point() {}
  Point(int id, int x, int y) : id(id), x(x), y(y) {}
  bool operator<(const Point &p) const { return id < p.id; }

  void print() { printf("%d\n", id); }
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];

Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

int makeKDTree(int l, int r, int depth) {
  if (!(l < r)) return NIL;
  int mid = (l + r) / 2;
  int t = np++;
  if (depth % 2 == 0) {
    sort(P + l, P + r, lessX);
  } else {
    sort(P + l, P + r, lessY);
  }
  T[t].location = mid;
  T[t].l = makeKDTree(l, mid, depth + 1);
  T[t].r = makeKDTree(mid + 1, r, depth + 1);

  return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth,
          vector<Point> &ans) {
  int x = P[T[v].location].x;
  int y = P[T[v].location].y;

  if (sx <= x && x <= tx && sy <= y && y <= ty) {
    ans.push_back(P[T[v].location]);
  }

  if (depth % 2 == 0) {
    if (T[v].l != NIL) {
      if (sx <= x) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
    }
    if (T[v].r != NIL) {
      if (x <= tx) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
    }
  } else {
    if (T[v].l != NIL) {
      if (sy <= y) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
    }
    if (T[v].r != NIL) {
      if (y <= ty) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
    }
  }
}

int main() {
  int x, y;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &x, &y);
    P[i] = Point(i, x, y);
    T[i].l = T[i].r = T[i].p = NIL;
  }

  np = 0;
  int root = makeKDTree(0, N, 0);

  int q;
  scanf("%d", &q);
  int sx, tx, sy, ty;
  vector<Point> ans;
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
    ans.clear();
    find(root, sx, tx, sy, ty, 0, ans);
    sort(ans.begin(), ans.end());
    for (int j = 0; j < ans.size(); j++) {
      ans[j].print();
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 15948
#include<stdio.h>
#include<string.h>

int compare(char *, char *, int);

int main(){
    int length, i;
    char A[200001], B[200001];
    scanf("%s %s", A, B);

    //配列の長さを取得
    length = strlen(A);

    if(compare(A,B,length)) printf("Yes\n");
    else printf("No\n");

    return 0;
}

//判定関数 引数は文字列2つと文字列の長さ
int compare(char *A, char *B, int length){
    //未利用のアルファベットを１とする配列（alphabet[0]をaとして扱う）
    int alphabet[26];
    for(int i=0; i<26; i++) alphabet[i]=1;

    for(int i=0; i<length; i++){
        //A[i]のアルファベットが未使用の場合、処理を行う
        if(alphabet[A[i] - 'a']){
            for(int j=i+1; j<length;j++){
                /*
                判定部分
                A[i]と同じ文字を持つA[j]が存在した場合
                Aの対になるBの文字同士も同じ文字でなくてはならない
                */
                if(A[i] == A[j]){
                    if(B[i] != B[j]) return 0;
                }
                //処理は非対称なのでBから見たA配列の文字の判定も必要
                if(B[i] == B[j]){
                    if(A[i] != A[j]) return 0;
                }
            }
            alphabet[A[i] - 'a'] = 0;
        }
        else;
    }
    return 1;
}


Measured memory_bytes: 512
N, P = [int(a) for a in input().split()]
# N, P = [10, 2972439611840]
prod = P
ans = 1
if N == 1:
    ans = P
elif N > 40:
    ans = 1
else:
    for i in range(2, P):
        if i > 2 and i % 2 == 0:
            continue
        if prod < i ** N:
            break
        count = 0
        while prod % i == 0:
            prod /= i
            count += 1
            if count % N == 0:
                ans *= i
print(str(ans))

Measured memory_bytes: 3064
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

A = require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline, 2);
A = A[1].split(' ').map(Number);

cnt = sort(A);
console.log(A.join(' '));
console.log(cnt);

function sort(A) {
  var cnt, flag, j, tmp;
  cnt = 0;
  flag = 1;
  while (flag) {
    flag = 0;
    for (j = A.length - 1; j > 0; j--) {
      if (A[j] < A[j-1]) {
        tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
        flag = 1;
        cnt++;
      }
    }
  }
  return cnt;
}

Measured memory_bytes: 15768
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LLINF 1<<63-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define MOD 1000000007
void swap(int* x,int* y){
  int tmp=*x;*x=*y;*y=tmp;
}

int main(){
  int A,B,ans=0;
  scanf("%d%d",&A,&B);
  if(A>B)ans=A*2-1;
  else if(A==B)ans=A*2;
  else ans=B*2-1;

  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
N, K = map(int, input().split())
D = list(map(int, input().split()))


def is_kirai(n, D):
    if n == 0:
        if 0 in D:
            return True
    while n:
        if n % 10 in D:
            return True
        else:
            n = n // 10

    return False


n = N
while True:
    if not is_kirai(n, D):
        print(n)
        quit()
    else:
        n += 1


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define x first
#define y second


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

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;
const int MO=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<endl;}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
void solve(){
  int a,b,c,d;
  string s;
  cin>>s;
  a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
  if(a+b+c+d==7)cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
  else if(a-b+c-d==7)cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
  else if(a-b-c+d==7)cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
  else if(a+b-c-d==7)cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
  else if(a-b+c+d==7)cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
  else if(a+b-c+d==7)cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
  else if(a+b+c-d==7)cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
  else cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}

Measured memory_bytes: 256
n=int(input())
#a,b,n=map(int,input().split())
l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import bisect

ans=0
l.sort()

for i in range(n):
    a=l[i]
    for j in range(i+1,n):
        b=l[j]
        ind=bisect.bisect_left(l,a+b)
        ans+=max(0,ind-(j+1))

print(ans)


Measured memory_bytes: 3188
from fractions import gcd
N=int(input())
A=list(map(int, input().split()))
LtR=[0]*N
LtR[0]=A[0]
RtL=[0]*N
RtL[-1]=A[-1]
for i in range(N-1):
  LtR[i+1]=gcd(A[i+1],LtR[i])
  RtL[-(i+2)]=gcd(A[-(i+2)], RtL[-(i+1)])
  
  
ans=max(LtR[-2], RtL[1])
for i in range(1,N-1):
  ans=max(ans, gcd(LtR[i-1], RtL[i+1]))
  
#print(LtR, RtL)
print(ans)

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

int main(){
    int n, t;
    cin >> n >> t;
    int maxi = 0, mini = INT_MAX, cnt = 1, ans = 1;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        if(a < mini){
            mini = a;
        }else if(maxi < abs(a - mini)){
            cnt = 1;
            maxi = abs(a - mini);
        }else if(maxi == abs(a - mini)){
            cnt++;
            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

red = Counter(s)
blue = Counter(t)

point = 0
for r in red:
  point = max(point, red[r] - blue[r])
  
if point<0:
  point=0

print(point)

Measured memory_bytes: 3316
import java.util.*;public class Main{public static void main(String[] a){Scanner s=new Scanner(System.in);for(;;){int h=s.nextInt()+1;int w=s.nextInt()+1;if(h*w==1)break;int[][]l=new int[h][w];int[][]t=new int[h][w];int m=0;for(int i=1;i<h;i++){char[]c=("*"+s.next()).toCharArray();for(int j=1;j<w;j++){if(c[j]!='*')l[i][j]=l[i][j-1]+1;t[i][j]=l[i][j];for(int k=0;k<i;k++)t[k][j]=Math.min(t[k][j],l[i][j]);for(int k=0;k<i;k++)m=Math.max(m,t[k][j]*(i-k+1));}}System.out.println(m);}}}

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

int main(void){
  std::string s, t;
  std::cin >> s >> t;
  int count = 0;
  for(int i=0; i<3; i++){
    if(s[i] == t[i]) count++;
  }
  std::cout << count << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def check(s):
    i = 0
    j = len(s)-1
    while i <= j:
        if s[i] != s[j]:
            return False
        i+=1
        j-=1
    return True
    

S = input()
mid = (len(S)-1)//2

if check(S[:mid]) and S[:mid] == S[mid+1:]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt < m:
        if lis[i][1] + cnt < m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
else:
    print(m*lis[0][0])

Measured memory_bytes: 27672
#include <stdio.h>
#include <string.h>

int main(){
  char s[500001];
  scanf("%s", s);
  int len = strlen(s);
  long long int u[len];
  long long int d[len];
  int sect = 0;
  int up = 0;
  int down = 0;
  for(int i = 0; i < len; i++){
    if((s[i] == '<') && (down == 0)){
      up++;
    }else if(s[i] == '>'){
      down++;
    }else{
      u[sect] = up;
      d[sect] = down;
      sect++;
      up = 1;
      down = 0;
    }
  }
  u[sect] = up;
  d[sect] = down;
  sect++;
  long long int sumu, sumd, minud;
  long long int ans = 0;
  for(int i = 0; i < sect; i++){
    sumu = (0 + u[i]) * (u[i] + 1) / 2;
    sumd = (0 + d[i]) * (d[i] + 1) / 2;
    minud = u[i];
    if(d[i] < minud){
      minud = d[i];
    }
    //printf("%d %d %d %d\n", i, sumu, sumd, minud);
    ans += sumu + sumd - minud;
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 6016
#include<stdio.h>

int main(void){
int A, B;
scanf("%d %d", &A, &B);
char s[A+B];
for(int i =0; i < A+B; i++) {
  scanf("%s", &s[i]);
}

int count = 0;
for (int i = 0; i < A+B; i++) {
if (s[i] == '-') count++;
}

if ((count == 1) && (s[A] == '-') ) {
printf("Yes");
} else {
printf("No");
}

return 0;
}


Measured memory_bytes: 128
sub getInput{
    chomp(my $line = <STDIN>);
    my @keys = ("A", "B", "C");
    my @vals = split(/ /, $line);
    my %data = map{$keys[$_] => $vals[$_]}(0..$#keys);

    return \%data;
}

sub ans{
    my %arg = %{$_[0]};

    if ($arg{"A"} + $arg{"B"} >= $arg{"C"}){
        print "Yes\n";
    }else{
        print "No\n";
    }
}

&ans(&getInput);




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

vector<int> vec[200000];

int main() {

    int n,m,a,b;

    cin >> n >> m;

    for(int i=0;i<m;i++){
        scanf(" %d %d",&a,&b);
        vec[a-1].push_back(b-1);
    }

    int s = vec[0].size();

    for(int i=0;i<s;i++){
        a = vec[0][i];
        int ss = vec[a].size();
        for(int k=0;k<ss;k++){
            if(vec[a][k] == n-1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <queue>
#include <vector>

#define rep(i,min,max) for(int i=min;i<max;i++)
#define rrep(i,min,max) for(int i=max;i>=min;i--)

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  if(a < 6)
    cout << "0" << endl;
  else if(a < 13)
    cout << b / 2 << endl;
  else
    cout << b << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define abs(x) ((x)<0 ? -(x) : (x))
#define max(x, y) ((x)<(y) ? (y) : (x))
#define min(x, y) ((x)>(y) ? (y) : (x))

int main(){
  long n, m;  scanf("%ld %ld", &n, &m);

  if(abs(n-m) > 1){
    printf("0\n");
    return 0;
  }
  long mod = 1e9 + 7;
  long table[100005] = {0};
  table[1] = 1;
  for(long i=2; i<=max(n, m); i++)
    table[i] = (table[i-1] * i) % mod;

  long ans = (table[m] * table[n]) % mod;
  if(n == m)  ans = (ans * 2) % mod;

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

  return 0;
}


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int sum(int x) {
    int ans=0;
    while(x) ans+=x%10,x/=10;
    return ans;
}

int main() {
    int n,ans=inf;read(n);
    for(int i=1;i<n;i++) ans=min(ans,sum(i)+sum(n-i));
    write(ans);
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main
{
    public static void main(String[] args) throws IOException
    {
	BufferedReader br = 
	    new BufferedReader(new InputStreamReader(System.in));
	String str = br.readLine();
	int seconds = Integer.parseInt(str);
	if(seconds == 0)
	    {
		System.out.println("0:0:0");
	    }else{
	    int sec = seconds % 60;
	    int min =(seconds/60) % 60;
	    int hour =seconds / 3600;
	    
	    System.out.println(hour + ":" + min + ":" + sec);
        }
    }
}

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


int main()
{  int a,b;
    while(true){
    cin>>a>>b;
    if(a==0&&b==0)break;
    for(int i=0;i<a;++i){
        for(int k=0;k<b;++k){
            cout<<"#";
        }
    cout<<endl;
   }cout<<endl;
   }
   return 0;
}




Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
class program
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();
      	int len = S.Length;
      	int Bstart1 = 0;	
      	int Bstart2 = 0;	
      	int Wstart1 = 0;	
      	int Wstart2 = 0;	
      	int evTotal = 0;	
      	int odTotal = 0;	
      
      	for( int i = 0 ; i < len ; i++ )
        {
            if( i % 2 == 0)
            {
                if( S.Substring(i,1) == "1" )
                {
                    Bstart1++;
                }
                else
                {
                    Wstart1++;
                }
            }
            else
            {
                if( S.Substring(i,1) == "0" )
                {
                    Bstart2++;
                }
                else
                {
                    Wstart2++;
                }
            }
        }

        if( Bstart1 + Bstart2 > Wstart1 + Wstart2)
        {
            Console.WriteLine(Wstart1 + Wstart2);
        }
        else
        {
            Console.WriteLine(Bstart1 + Bstart2);
        }
      
    }
}


Measured memory_bytes: 15164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rint register int
inline ll read(){ll r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
ll A, B, C, D, E, F, K; int main(){A = read(), B = read(), C = read(), K = read(); cout << (K&1?B-A:A-B) << endl; return 0;}

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

int N;
ll a[100010][3];
ll dp[100010][3];
int main() {
    int N;
    cin >> N; 
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) {
                    continue;
                }
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }
    ll res = 0;
    for (int j = 0; j < 3; j++) {
        res = max(res, dp[N][j]);
    }
    cout << res << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n;
    cin>>n;
    vi a(n);
    unsigned char colors=0;
    int cnt=0;
    REP(i,n){
        cin>>a[i];
        if(a[i]<3200)colors|=bit(a[i]/400);
        else ++cnt;
    }
    int cs=0;
    REP(i,8){
        if(colors&bit(i))++cs;
    }
    cout<<(cs?cs:1)<<" "<<cs+cnt<<endl;


    return 0;
}


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

using namespace std;

int f(int n) { return n % 2 ? 3 * n + 1 : n / 2; }

int solve(int s) {
  std::unordered_set<int> as{};
  as.insert(s);
  int a = f(s);
  int m = 2;
  while (true) {
    if (as.find(a) != as.end()) {
      return m;
    }
    as.insert(a);
    m++;
    a = f(a);
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int s;
  std::cin >> s;
  std::cout << solve(s) << std::endl;
  return 0;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)
from bisect import bisect_right,bisect_left

def main():
    X = int(input())
    for i in range(1000):
        for j in range(1000):
            p = pow(i,5)
            q = pow(j,5)
            if p + q == X:
                print(i,-j)
                return
            elif p - q == X:
                print(i,j)
                return
            elif q - p == X:
                print(j,i)
                return
                
if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  int a[N];
  for(int i=0;i<N;i++) cin >> a[i];
  int cnt[N+1];
  for(int i=0;i<N;i++) cnt[a[i]] = i;
  // for(int i=1;i<=N;i++) cout << cnt[i] << endl;
  int inc = 1, maxinc = 1;
  for(int i=1;i<N;i++){
    if(cnt[i] < cnt[i+1]){
      inc++;
    }else{
      maxinc = max(inc, maxinc);
      inc = 1;
    }
  }
  maxinc = max(inc, maxinc);
  cout << N - maxinc << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main() {
    string a;
    cin>>a;
    int i,p=0;
    for(i=0;i<a.size();i++){

      if(a[a.size()-1] == '2' || a[a.size()-1]=='4' || a[a.size()-1]=='5' || a[a.size()-1]=='7' || a[a.size()-1]=='9'){
     p=1;
     break;
      }


     else if(a[a.size()-1]=='0' || a[a.size()-1]=='1' || a[a.size()-1]=='6' || a[a.size()-1]=='8'){
      p=2;
      break;
     }

    else  if(a[a.size()-1]=='3'){
      p=3;
      break;
    }




    }
    if(p==1) cout<<"hon"<<endl;
  else  if(p==2) cout<<"pon"<<endl;
  else  if(p==3) cout<<"bon"<<endl;
}




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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    int b;
    cin >> b;
    int c;
    cin >> c;
    if (a + b >= c) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
#include <assert.h>
#include <immintrin.h>
#include <emmintrin.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#ifdef ONLINE_JUDGE
#define assert(...) /* nothing */
#endif
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
const int mn=1e6+4;
int a[mn];

int n,k;
int f(int x) {
  int den=k-1;
  return (x+den-1)/den;
}
int main()
{
  cin>>n>>k;
  for (int i=0;i<n;i++) {
    int x; cin>>x;
  }
  int ans=f(n-1);
  printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	// your code goes here
	int x[4], i;
	scanf("%d %d %d",&x[1],&x[2],&x[3]);
	for(i=1;i<3;i++){
		if(x[i]>x[i+1]){
			x[0] = x[i];
			x[i] = x[i+1];
			x[i+1] = x[0];
		}
	}
	if(x[1] > x[2] ){
			x[0] = x[1];
			x[1] = x[2];
			x[2] = x[0];
		
	}
	
	printf("%d %d %d\n",x[1],x[2],x[3]);
	return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
  	cin >> a.at(i);
  }
  
  int sum = 0;
  int m = 0;
  for(int i = 0; i < n; i++){
  	sum += a.at(i);
    m = max(m, a.at(i));
  }
  if(sum - m > m){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int N;
	cin >> N;

	int num = N % 2;
	int val = N / 2;
	val += num;
	cout << val << endl;

	return  0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
const int H = 1e4 + 100;
const int N = 1e3 + 100;
int dp[H];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h , n;
cin>>h>>n;
pi arr[n];
for(int i = 0 ; i < H ; i++)dp[i] = INT_MAX;
for(int i = 0 ; i < n ;i++){
		cin>>arr[i].f>>arr[i].s;
}
dp[0] = 0;
for(int i = 0 ; i < n ; i++){
  for(int j = 0 ; j <= h ; j++){
     dp[min(j + arr[i].f , h)] = min(dp[min(j + arr[i].f , h)] , dp[j] + arr[i].s); 
  }
}
cout<<dp[h];
}



Measured memory_bytes: 384
import java.util.Scanner;
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc=new Scanner(System.in);
    		int n=sc.nextInt(),k=sc.nextInt();
    		System.out.println(k*(int)Math.pow(k-1, n-1));
    		sc.close();
    	}
    }

Measured memory_bytes: 21844
/*This is the solution from Ling2Feng1,
  no matter AC or not.
  OJ:
  ProblemID:
  Date:
*/
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

const int INF=1e9+7;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,-1,0,1};

int n,m;
int cnt;
long long ans;
int a[100005],fa[100005],rk[100005];
priority_queue<int,vector<int>,greater<int> > pq[100005],pq1;

int GetF(int x){
	while(x!=fa[x]) x=fa[x];
	return x;
}

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		fa[i]=i;rk[i]=1;
	}
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		int fu=GetF(u);
		int fv=GetF(v);
		if(rk[fu]>rk[fv]){
			fa[fv]=fu;
		}else if(rk[fu]<rk[fv]){
			fa[fu]=fv;
		}else{
			fa[fu]=fv;
			rk[fv]++;
		}
	}
	for(int i=0;i<n;i++){
		pq[GetF(i)].push(a[i]);
	}
	for(int i=0;i<n;i++){
		int j=GetF(i);
		if(!pq[j].size()) continue;
		cnt++;
		ans+=pq[j].top();pq[j].pop();
		while(pq[j].size()){
			pq1.push(pq[j].top());pq[j].pop();
		}
	}
	if(cnt==1){
		puts("0");
		return 0;
	}
	for(int i=0;i<cnt-2;i++){
		if(!pq1.size()){
			puts("Impossible");
			return 0;
		}
		ans+=pq1.top();
		pq1.pop();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7680
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = IR(n)

B = sorted(A)
a = B.pop()
b = B.pop()
for x in A:
    if x == a:
        print(b)
    else:
        print(a)


Measured memory_bytes: 70488
import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            int ans = rec(n,0,(int)Math.sqrt(n));
            System.out.println(ans);
        }
    }

    int rec(int num, int cnt, int x){
        if(num==0) return 1;
        if(cnt>=4) return 0;

        int res = 0;
        for(int i=x; i>=1; i--){
            if(num-i*i>=0) {
                res += rec(num-i*i,cnt+1,i);
            }
        }

        return res;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 19976
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n, m;
    cin >> n >> m;
    
    cout << (n>1?nCr(n, 2):0) + (m>1?nCr(m, 2):0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
ll INF = 1e15;

int main(){
    ll n, W;
    cin >> n >> W;
    vll v(n), w(n);
    REP(i, n) cin >> v[i] >> w[i];

    //dp[i][j]:i番目までで価値をjにできるときの重さの最小値
    vvll dp(n + 1, vll(10010, INF));
    REP(i, n + 1) dp[i][0] = 0;
    REP(i, n){
        REP(j, 10010){
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            //i番目を採用
            if(j - v[i] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
        }
    }
    ll ans = 0;
    REP(j, 10010){
        //cout << dp[n][j] << endl;
        if(dp[n][j] <= W) ans = j;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

ll factrial[MAX_N], inverse[MAX_N];  //階乗と逆元を保持

ll mod_power(ll x, ll n) {  //繰り返し二乗法
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

void init(ll n) {
    factrial[0] = 1;
    inverse[0] = 1;
    for (ll i = 1; i <= n; i++) {
        factrial[i] = (factrial[i - 1] * i) % MOD;  //階乗を求める
        inverse[i] = mod_power(factrial[i], MOD - 2) % MOD;  //オイラーの定理で逆元を求める
    }
}

ll nCk(ll n, ll k) {
    if(n < 0 || k < 0 || n < k) return 0;
    return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}

ll n, k;

int main() {
    cin >> n >> k;
    init(n);
    for(ll i=1;i<=k;i++){
        cout <<  nCk(n-k+1, i)*nCk(k-1,i-1) % MOD << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
const int INF = 1<<28;

int main() {
	int n, q;
	while(cin >> n >> q, n|q) {
		int days[100] = {};
		for(int i=0; i<n; i++) {
			int num;
			cin >> num;
			for(int j=0; j<num; j++) {
				int temp;
				cin >> temp;
				days[temp]++;
			}
		}
		int  ans = 0;
		for(int i=0; i<100; i++)
			if(days[i] >= q && days[i] > days[ans])
				ans = i;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n;
		n = sc.nextInt();

		List<Integer> l = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			l.add(sc.nextInt());
		}

		int ans = 0;

		for (int x = 0; x < n; x++) {
			for (int y = x + 1; y < n; y++) {
				for (int z = y + 1; z < n; z++) {
					int a = l.get(x);
					int b = l.get(y);
					int c = l.get(z);

					if (a != b && b != c && c != a && a + b > c && b + c > a && c + a > b) {
						ans++;
					}
				}
			}
		}

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 37036
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstdio>
using namespace std;


int main(){
  string S;
  cin >> S;
  string m;
  m = S.substr(5,2);
  int m_int = stoi(m);
  if(m_int<=4){
    cout << "Heisei";
  }
  else{
    cout << "TBD";
  }
  cout << endl;
}


Measured memory_bytes: 256
c = []
for i in range(3):
    c.append(list(map(int,input().split())))
if c[0][0]-c[0][1] == c[1][0]-c[1][1] and \
   c[0][0]-c[0][1] == c[2][0]-c[2][1] and \
   c[0][0]-c[0][2] == c[1][0]-c[1][2] and \
   c[0][0]-c[0][2] == c[2][0]-c[2][2] and \
   c[0][0]-c[1][0] == c[0][1]-c[1][1] and \
   c[0][0]-c[1][0] == c[0][2]-c[1][2] and \
   c[0][0]-c[2][0] == c[0][1]-c[2][1] and \
   c[0][0]-c[2][0] == c[0][2]-c[2][2]:
    print ("Yes")
else:
    print ("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

    /*
    ||||||||||||||||||||||||||||||||||||||||||||||||
       |      |||         |      ||||    ||||  |   |
      | |     |   |      | |     |   |  |      |   |
     |   |    |    |    |   |    |   |  |      |   |
    |||||||   |    |   |||||||   |||     |||   |||||
    |     |   |   |    |     |   | |        |  |   |
    |     |   |||      |     |   |  ||  ||||   |   |
    ||||||||||||||||||||||||||||||||||||||||||||||||

    */
    using namespace std;
    //#include "testlib.h"
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define int long long
    #define ll long long
    #define M 1000000007
    #define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
    #define GCD(m,n) __gcd(m,n)
    #define LCM(m,n) m*(n/GCD(m,n))
    #define mii  map<ll ,ll >
    #define msi  map<string,ll >
    #define mis  map<ll int, string>
    #define rep(a,b)    for(ll i=a;i<b;i++)
    #define rep0(n)    for(ll i=0;i<n;i++)
    #define repi(i,a,b) for(ll i=a;i<b;i++)
    #define pb push_back
    #define vi vector<ll>
    #define mp make_pair
    #define vs vector<string>
    #define ppb pop_back
    #define endl '\n'
    #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define r0 return 0;
    #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
    #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
    #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #define input freopen("input.txt", "r", stdin);
    #define Set(a, s) 4(a, s, sizeof (a))
    #define FOR repi
    #define pii pair<int,int>
    #define REVERSE(v) reverse(ALL(v))
    #define display(x) trav(a,x) cout<<a<<" ";cout<<endl
    #define debug cerr<<"bhau"<<endl
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        std::cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    ll max(ll a, ll b) { return (a > b)? a : b;}
    int min(int a, int b) { return (a < b)? a : b;}
    void amax(int &a,int b){a=max(a,b)%M; }
    void amin(int &a,int b){ a=min(a,b)%M;}
    void inc(int &a,int b){a=(a+b)%M;}
    void dec(int &a,int b){a=(a-b+M)%M;}


    
     int solve()
     {  
        string s,t;cin>>s>>t;
        int ans=0;
        rep0(s.size()) if(s[i]==t[i]) ans++;
        cout<<ans;

        r0   
     }
    signed main()
    {   
        asdf
        
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}

Measured memory_bytes: 256