akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>

using namespace std;

struct Memo
{

  int count;

  Memo()
  {
    count = 0;
  }

};

Memo memo[31][4];

int ProgressNumberOfYears(int step_num, int step_kind)
{

  int kind_count = 0;

  if(step_num == 0) return 1;
  else if(memo[step_num][step_kind].count) return memo[step_num][step_kind].count;

  if(step_num - 3 >= 0)  kind_count = kind_count + ProgressNumberOfYears(step_num - 3,3);
  if(step_num - 2 >= 0)  kind_count = kind_count + ProgressNumberOfYears(step_num - 2,2);
  if(step_num - 1 >= 0)  kind_count = kind_count + ProgressNumberOfYears(step_num - 1,1);

  memo[step_num][step_kind].count = kind_count;

  return kind_count;

}

int main()
{

  int step_num;

  while(cin >> step_num && step_num != 0) cout << ProgressNumberOfYears(step_num,0)/10/365 + 1<< endl;

  return 0;

}

Measured memory_bytes: 1160
from collections  import defaultdict
import bisect

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
N=int(input())
M=sorted(make_divisors(N))
p=bisect.bisect(M, N**0.5)
#print(p,M)
ans1=M[p]+(N//M[p])-2
ans2=9999999999999999999
ans3=9999999999999999999
if p>0:
    ans2=M[p-1]+(N//M[p-1])-2
if p<len(M)-1:
    ans3=M[p+1]+(N//M[p+1])-2
print(min(ans1,ans2,ans3))


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


int dp[10010];


int main(){
  int n,i,W,j,w;
  cin >> n >> W;
  vector<int> v(n),weight(n);
  for(i=0;i<n;++i){
    cin >> v[i] >> weight[i];
  }
  for(i=0;i<10010;++i){
    dp[i]=0;
  }
  for(i=0;i<n;++i){
    for(j=0;j+weight[i]<=W;++j){
      dp[j+weight[i]]=max(dp[j+weight[i]],dp[j]+v[i]);
    }
  }
  cout << dp[W] << endl;
}



Measured memory_bytes: 3152
#include<iostream>
#include<algorithm>
using namespace std;
signed main(){

   // cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);

    int n;
    cin>>n;
    int p[1001][1001];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>p[i][j];
        }
       sort(p[i],p[i]+3);
    }
    int ans=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(p[i][0]==p[j][0]&&p[i][1]==p[j][1]&&p[i][2]==p[j][2]){
                ans++;
                break;
            }
        }

    }

    cout<<ans<<"\n";
    return (0);
}


Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int flag = 0, n;
    cin >> n;
    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            if(i * j == n)
                flag = 1;
        }
    }
    if(flag == 1)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
import collections

n=int(input())
a=list(map(int,input().split()))
a=collections.Counter(a)
a=sorted(a.items(),reverse=True)
#print(a)

tm=0

for i in range(n):
    if a[i][1]>=4 and tm==0:
        print(a[i][0]*a[i][0])
        exit()
    elif a[i][1]>=2:
        if tm==0:
            tm=a[i][0]
        else:
            print(tm*a[i][0])
            exit()

print("0")
    

Measured memory_bytes: 21412
#include<stdio.h>
#define H 500000
int h;

void maxHeapify(int *A,int i){
  int temp;
  int l,r,largest;
  l = 2*i;
  r = 2*i+1;

  if(l<=h && A[l] > A[i]) largest = l;
  else largest = i;
  if(r<=h && A[r]>A[largest]) largest = r;
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(A,largest);
  } 
}

void buildMaxHeap(int *A){
  int i;

  for(i=h/2;i>=1;i--) maxHeapify(A,i);
}

int main(){
  int heap[H+1];
  int i;

  scanf("%d",&h);
  for(i=1;i<=h;i++) scanf("%d",&heap[i]);
  buildMaxHeap(heap);

  for(i=1;i<=h;i++) printf(" %d",heap[i]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

char s[20][20];
int check[20][20];
int h,w;

int bfs(int sy, int sx, int gy, int gx){
  for(int i=0;i<20;i++){
    for(int j=0;j<20;j++){
      check[i][j]=-1;
    }
  }
  check[sy][sx]=0;
  queue<int> memo;
  memo.push(sy);memo.push(sx);
  while(!memo.empty()){
    int y=memo.front();memo.pop();
    int x=memo.front();memo.pop();
    int dy[4]={0,1,0,-1},dx[4]={1,0,-1,0};
    for(int i=0;i<4;i++){
      int ny=y+dy[i],nx=x+dx[i];
      if(ny<0 || ny>=h || nx<0 || nx>=w ||s[ny][nx]=='#') continue;
      if(check[ny][nx]!=-1) continue;
      check[ny][nx]=check[y][x]+1;
      memo.push(ny);memo.push(nx);
    }
  }
  return check[gy][gx];
}

int main() {
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cin>>s[i][j];
  }
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#') continue;
      for(int p=0;p<h;p++){
        for(int q=0;q<w;q++){
          if((s[p][q]=='#')|| (i==p && j==q)) continue;
          ans=max(ans,bfs(i,j,p,q));
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;
const ll INF = 1e12;


int main(){
        ll N, A;
        cin >> N >> A;
        cout << N*N-A;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f   first
#define s   second
#define pb          push_back
#define mod         1000000007
#define hell        998244353
#define inf         1000000000000000000LL
using namespace std;
ll n,k,m;
//ll dp[15][1005];
double dp[3005][3005];
ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2){res=(res*x)%mod;}
        x=(x*x)%mod;
        y/=2;
    }
    return res;
}
ll invmod(ll x)
{ return power(x,mod-2);}
void solve()
{   ll W,X,D,Y,A,B,C;
    cin>>n;
    vector<double> v(n+1),pt(n),ph(n);
    for(int i=1;i<=n;i++) cin>>v[i];
        //dp[i][j] i coin tosses and j heads;
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
            {if(j)dp[i][j]+=(dp[i-1][j-1]*v[i]);
                dp[i][j]+=dp[i-1][j]*(1-v[i]);}
    }
    double ans=0;
    for(int i=(n/2)+1;i<=n;i++)
        ans+=dp[n][i];
    cout<<setprecision(18)<<ans;

}

int main()
{
    ll t=1;
    //cin>>t;
    
    while(t--)
        solve();

}

Measured memory_bytes: 69120
from sys import stdin

n500 = int(stdin.readline().rstrip())
n100 = int(stdin.readline().rstrip())
n50 = int(stdin.readline().rstrip())
yen = int(stdin.readline().rstrip())

x = 0

for a in range(n500+1):
    for b in range(n100+1):
        for c in range(n50+1):
            if yen == a*500+ b*100+ c*50: 
                x += 1

print(x)

Measured memory_bytes: 3060
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
char s[100007];
int get[128];
int main()
{
    get['b'] = 0 , get['p'] = 1 , get['d'] = 2 , get['q'] = 3;
    scanf("%s",s+1); // 从 s[1] 开始的
    for(int l = strlen(s+1), i = 1; i <= (l>>1) + 1; ++i)
    {
        if(get[s[i]]^((get[s[l-i+1]]+2)%4)) return printf("No\n"),0;
    } // 这个 +2 %4 刚好让 b 转到 d 上， d 转到 b 上， p 转到 q 上， q 转到 p 上 
    return printf("Yes\n"),0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
typedef long long int ll;
#define pb         push_back
#define mp         make_pair
#define F          first
#define S          second
#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define pll        pair<ll,ll>
#define pii        pair<int,int>
#define all(v)     v.begin(),v.end()
#define M          1000000007
#define M2         1000000009

using namespace std;
bool isPrime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;

    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0|| n%(i+2)==0)
            return false;

    return true;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b,a%b);

}

bool sortbydesc(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    if(a.S < b.S)
        return true;
    else
        return false;
}


int main()
{
 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll n,k;
 cin>>n>>k;
 ll a;
 vector<ll> v;
 v.pb(a);
 fl(i,0,n)
 {
    cin>>a;
    v.pb(a);
 }
 ll dp[k+1][2];
 dp[0][0]=1;
 dp[0][1]=0;
 fl(i,1,k+1)
 {
    dp[i][0]=1;
    dp[i][1]=0;
    fl(j,1,n+1)
    {
        if(i-v[j]>=0 && dp[i-v[j]][1]==0)
            dp[i][0]=0;
        if(i-v[j]>=0 && dp[i-v[j]][0]==1)
            dp[i][1]=1;
    }
 }
 if(dp[k][0]==0)
    cout << "First";
 else
    cout << "Second";
}






Measured memory_bytes: 1792
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from bisect import bisect_left
from itertools import accumulate
 
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
A_r = list(reversed(A))
B = [0] + list(accumulate(A_r))
 
def func(x):
    count = 0
    for Ai in A:
        idx = bisect_left(A,x-Ai)
        count += N-idx
    if count >= M:
        return True
    else:
        return False
 
MIN = 0
MAX = 2*10**5+1
while MAX-MIN > 1:
    MID = (MIN+MAX)//2
    if func(MID):
        MIN = MID
    else:
        MAX = MID
 
ans = 0
count = 0
 
for Ai in A_r:
    idx = bisect_left(A,MIN-Ai)
    ans += Ai*(N-idx) + B[N-idx]
    count += N-idx
print(ans-(count-M)*MIN)

Measured memory_bytes: 20676
#include <iostream>

using namespace std;

int main()
{
    int b[3];

    for (int i = 0; i < 3; ++i)
        cin >> b[i];

    if ((b[0] == 1 && b[1] == 1 && b[2] == 0) ||
        (b[0] == 0 && b[1] == 0 && b[2] == 1))
        cout << "Open\n";
    else
        cout << "Close\n";


    return 0;
}

Measured memory_bytes: 1116
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	str := []rune(s)
	if str[2] == str[3] && str[4] == str[5] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

int main()
{
    int n, m;
    std::cin >> n >> m;

    std::priority_queue<int, std::vector<int>, std::greater<int>> q;
    for (int i = 0; i < n; i++) {
        int temp;
        std::cin >> temp;
        q.push(temp);
    }

    std::vector<std::pair<int, int>> convert(m);
    for (int i = 0; i < m; i++) {
        std::cin >> convert[i].first >> convert[i].second;
    }

    std::sort(convert.begin(), convert.end(), std::greater<std::pair<int, int>>());

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < convert[i].first && q.top() < convert[i].second; j++) {
            q.pop();
            q.push(convert[i].second);
        }
    }

    long long ans = 0;
    while (q.size()) {
        ans += q.top();
        q.pop();
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int mx = -INF, mn = INF;
  int mx_ind, mn_ind;
  rep(i, N) {
    cin >> a[i];
    if (chmax(mx, a[i]))
      mx_ind = i;
    if (chmin(mn, a[i]))
      mn_ind = i;
  }

  cout << (2 * N - 1) << endl;
  if (mx + mn >= 0) {
    rep(i, N) {
      if (i != mx_ind)
        cout << (mx_ind + 1) << ' ' << (i + 1) << endl;
    }
    cout << (mx_ind + 1) << ' ' << (mx_ind + 1) << endl;
    rep(i, N - 1) {
      cout << (i + 1) << ' ' << (i + 2) << endl;
    }
  } else {
    rep(i, N) {
      if (i != mn_ind)
        cout << (mn_ind + 1) << ' ' << (i + 1) << endl;
    }
    cout << (mn_ind + 1) << ' ' << (mn_ind + 1) << endl;
    repr(i, N - 1, 1) {
      cout << (i + 1) << ' ' << i << endl;
    }
  }
}

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

int main(){
    int n;
    cin>>n;

    bool hantei=false;
    int r;

    for(int i=0; i<3; i++){
        r=n%10;
        if(r==7){
            hantei=true;
        }
        n/=10;
    }

    if(hantei==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
   int a, b;
  char s;
  scanf("%d\n",&a);
  scanf("%c",&s);
  scanf("%d",&b);
  if(s=='+')
   printf("%d\n",a+b);
  else
   printf("%d\n",a-b);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  int n,m;
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    b[i]=a[i]-(i+1)
b.sort()
min_b=b[n//2]
ans=0
for i in range(n):
    ans+=abs(a[i]-(min_b+(i+1)))
print(ans)

Measured memory_bytes: 26132
import sys
import math
from collections import deque
input = sys.stdin.readline
#S,L,R = map(int, input().split())

N = int(input())

A = [0]
B = []

Answer = 0

j = 1;
while j*j<=N:
    A.append(j)
    if N//j != j:
        B.append(N//j)
    j+=1

B.reverse()
A =  A + B

Answer = 0
for i in range(1,len(A)):
    num = ((N//A[i])*(N//A[i]+1)//2)
    num *= ((A[i]*(A[i]+1)//2)-(A[i-1]*(A[i-1]+1)//2))
    Answer += num

print(Answer)


Measured memory_bytes: 9716
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

int main(){
  set<string> keys;

  int n,m;
  cin >> n;

  rep(i,n){
    char s[12];
    scanf("%s", s);
    string key(s);
    keys.insert(key);
  }

  cin >> m;

  bool door=false;
  rep(i,m){
    char s[12];
    scanf("%s", s);
    string key(s);
    if( keys.find(key) != keys.end() ){ //find
      if(!door)
	cout << "Opened by " << key << endl;
      else
	cout << "Closed by " << key << endl;
      door = !door;

    }else {
      cout << "Unknown " << key << endl;

    }
  }

}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int h, w; cin >> h >> w;
    vector<string> s(h); cin >> s;
    int cnt = 0;
    each(t, s)each(c, t)if (c == '#')++cnt;
    cout << (cnt == h + w - 1 ? "Possible" : "Impossible") << "\n";
}

Measured memory_bytes: 256
K,S=map(int,input().split())
 
z = list(range(K+1))
ans = []
 
for i in z:
  s_z = S - i
  if s_z < 0:
    pass
  elif K < s_z:
    if (K + 1) > (s_z - K):
      ans.append(K + 1 - (s_z - K))
  else:
    ans.append(s_z + 1)

print(sum(ans))

Measured memory_bytes: 3188
from itertools import product

n = int(input())
data = [[int(i) for i in input().split()] for _ in range(n)]
for d in data:
    if d[2] > 0:
        sample = d
        break

for cx, cy in product(range(101), repeat=2):
    ch = sample[2] + abs(sample[0]-cx) + abs(sample[1]-cy)
    for x, y, h in data:
        val = h + abs(x-cx) + abs(y-cy)
        if h != max(ch - abs(x-cx) - abs(y-cy), 0):
            break
    else:
        print(cx, cy, ch)
        break


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static String mainString;
    public static String subString;
    public static int maxLength = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        mainString = sc.nextLine();
        subString = sc.nextLine();

        for (int i = 0; i <= mainString.length() - subString.length(); i++) {
            loop(i);
        }

        System.out.println(subString.length() - maxLength);
    }

    public static void loop(int start) {
        String ms = mainString.substring(start, start + subString.length());
        check(ms);
    }

    public static void check(String ms) {
        int count = 0;
        for (int i = 0; i < subString.length(); i++) {
            if (ms.charAt(i) == subString.charAt(i)) {
                count++;
            }
        }
        if (maxLength < count) {
            maxLength = count;
        }
    }
}

Measured memory_bytes: 35628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>S;

    ll n1 = stoi(S.substr(0,2));
    ll n2 = stoi(S.substr(2,2));
    
    if(n1!=0 && n1<=12 && n2!=0 && n2<=12){
        cout<<"AMBIGUOUS"<<endl;
    }else if(n1!=0 && n1<=12){
        cout<<"MMYY"<<endl;
    }else if(n2!=0 && n2<=12){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }




    return 0;
    

}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		String s = sc.next();
		
		int len = s.length();
		
		String ans = len <= k ? s : s.substring(0, k) + "...";
		System.out.println(ans);
	}
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define FOR_EX(i, a, b) for (int i = a; i < b; i++)
#define FOR_IN(i, a, b) for (int i = a; i <= b; i++)

#define ALL(a) a.begin(), a.end()

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(10);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int n;
    cin >> n;
    unordered_map<int, int> b;
    FOR_IN(i, 1, n) {
        cin >> b[i];
    }
    unordered_set<int> pressed;
    int times = 0;
    int cur = 1;
    while (cur != 2) {
        if (b.find(cur) == b.end() || pressed.find(cur) != pressed.end()) {
            cout << -1 << endl;
            return 0;
        }
        times++;
        pressed.insert(cur);
        cur = b[cur];
    }
    cout << times << endl;
}


Measured memory_bytes: 8484
import java.util.Arrays;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long[] a = new long[N];
		for (int i = 0; i < N; ++i) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		boolean[] vis = new boolean[K];
		vis[0] = true;
		int ok = N;
		for (int i = N - 1; i >= 0; --i) {
			for (int j = K - 1; j >= 0; --j) {
				if (!vis[j])
					continue;
				if (j + a[i] >= K)
					ok = i;
				else {
					vis[(int) (j + a[i])] = true;
				}
			}
		}
		System.out.println(ok);
	}
}

Measured memory_bytes: 31124
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))



using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;






ll max(ll a, ll b) {
	if(a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}


ll N, M;
string s[100];
ll num[50];
int main() {

	cin >> N >> M;

	rep(i, N) {
		cin >> s[i];
	}

	rep(i, N) {
		rep(j, M) {
			num[s[i][j] - 'a'] += 1;
		}
	}
	bool flag = false;
	rep(i, N / 2) {
		rep(j, M / 2) {
			rep(k, 'z' - 'a' + 1) {
				if (num[k] >= 4) {
					num[k] -= 4;
					flag = true;
					break;
				}
			}

			if (flag == false) {
				cout << "No" << endl;
				return 0;
			}

			flag = false;

		}

			

	}

	

	if (N % 2 == 1) {
		rep(i, M / 2) {

			flag = false;
			rep(k, 'z' - 'a' + 1) {
				if (num[k] >= 2) {
					num[k] -= 2;
					flag = true;
					break;
				}
			}

			if (flag == false) { cout << "No" << endl; return 0; }


		}

	}

	if (M % 2 == 1) {
		rep(i, N / 2) {

			flag = false;
			rep(k, 'z' - 'a' + 1) {
				if (num[k] >= 2) {
					num[k] -= 2;
					flag = true;
					break;
				}
			}

			if (flag == false) { cout << "No" << endl; return 0; }


		}

	}
	flag = false;
	if (M % 2 == 1 && N % 2 == 1) {
		rep(k, 'z' - 'a' + 1) {
			if (num[k] >= 1) {
				num[k] -= 1;
				flag = true;
				break;
			}

		}

		if (flag == false) { cout << "No" << endl; return 0; }

	}



	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
// Echo
#include <iostream>
using namespace std;

int main(){
    int n;
    string s;
    int a=0;
    cin >> n >> s;
    if(n%2==0){
        for(int i=0; i<n/2; i++){
            if(s[i]==s[i+n/2]){
                a+=1;
            }
        }
        if(a==n/2){
            
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
int K;
cin >> K;

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2,
1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << a[K-1] << endl;

return 0;
 }


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

int main(void){
    int W,H,x,y,r;
        cin >> W;
        cin >> H;
        cin >> x;
        cin >> y;
        cin >> r;
    if(x-r<0 || x+r>W ||y-r<0 || y+r>H){
        cout <<"No"  << endl;
    }else if(x-r>=0 && x+r<=W && y-r>=0 && x+r<=H){
        cout << "Yes" << endl;
    }
    
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;

int main( void ) {
  int N, ans = 0;
  cin >> N;

  vector<int> L(N);
  for(int i=0;i<N;i++) {
    cin >> L.at(i);
  } 

  sort( L.begin(), L.end(), greater<int>() );

  for(int i=0;i<N;i++) {
    for(int j=i+1;j<N;j++) {
      for(int k=j+1;k<N;k++) {
        if(L.at(i)<L.at(j)+L.at(k))  ans++;
      }
    }
  } 

  cout << ans << endl;

  return ( 0 );
}


Measured memory_bytes: 256
S_ = input()
S = list(S_)
flag = True

if S[0] == 'A':
    S.pop(0)
    big = []
    for i in range(1, len(S)-1):
        if S[i] == 'C':
            big.append(i)
    if len(big) == 1:
        S.pop(big[0])
        for s in S:
            if s.isupper():
                flag = False
    else:
        flag = False
else:
    flag = False

if flag:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
string a;
int ans=-1;
int main(){
	cin>>a;
	int len=a.size();
	for(int i=0;i<len;i++) if(a[i]!=a[i+1]) ans++;
	cout<<ans<<endl;
	return 0;
} 

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    cout << setprecision(15) << fixed;
    string s;
    cin >> s;
    int res = 0;
    int len = 0;
    for (int i = 0; i < 3; ++i) {
        if(s[i] == 'R') {
            len++;
            res = max(res, len);
        }
        else len = 0;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
	int x, y[100], z[100];
	double a, b, c, d = 0;
	char* s = "%.6f\n";
	cin >> x;
	for(int i = 0; i < x; i++){
		cin >> y[i];
	}
	for(int i = 0; i < x; i++){
		cin >> z[i];
	}
	for(int i = 0; i < x; i++){
		a += fabs(y[i] - z[i]);
		b += pow(y[i] - z[i], 2);
		c += fabs(pow(y[i] - z[i], 3));
		d = d < fabs(y[i] - z[i]) ? fabs(y[i] - z[i]) : d;
	}
	printf(s, a);
	printf(s, sqrt(b));
	printf(s, cbrt(c));
	printf(s, d);
	return 0;
}


Measured memory_bytes: 3432
#include<bits/stdc++.h>
 
using namespace std;
 
const int INF = 1 << 30;
 
int main()
{
  int N, A[100];
  bool cnt[8] = {};
  cin >> N;
  bool only = true;
  int st = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    only &= A[i] >= 3200;
    if(A[i] >= 3200) {
      ++st;
      continue;
    }
    cnt[A[i] / 400]++;
  }
  int ret = 0;
  for(int i = 0; i < 8; i++) ret += cnt[i];
  cout << max(1, ret) << endl;
  cout << ret + st << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll ans=1; int n;
string s_1, s_2;
vector<int> ff;

ll gv(int u, int v)
{
	if(v==0 && u==1) return 3;
	if(v==0 && u==2) return 6;
	if(v==1 && u==2) return 2;
	if(v==1 && u==1) return 2;
	if(v==2 && u==1) return 1;
	if(v==2 && u==2) return 3;
}

int main(void)
{
	cin>>n>>s_1>>s_2; 
	int i, j;
	for(i=0 ; i<n ; i++)
	{
		if(s_1[i]==s_2[i]) ff.push_back(1);
		else ff.push_back(2), i++;
	}
	ff.push_back(0);
	for(i=0 ; i<ff.size()-1 ; i++) ans=(ans*gv(ff[i],ff[i+1]))%mod;
	cout<<ans; return 0;
}


// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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

#define ll long long
#define mx 200005
int n,k;
int ar[mx];
int dp[mx];
bool visit[mx][3];
#define mod 1000000007
ll bigmod(ll n,ll p){if(p==0) return 1;if(p==1)return (n+mod)%mod;if(p%2)return (bigmod(n,p-1)*n+mod)%mod;else{ll x=bigmod(n,p/2);return (x*x+mod)%mod;}}


int main()
{
    scanf("%d%d",&n,&k);
    for(int i=k;i>=1;i--)
    {
        int bag=k/i;
        int val=bigmod(bag,n)%mod;
        int bat=0;
        for(int j=2*i;j<=k;j+=i)
        {
            bat=(bat+dp[j])%mod;
        }
        dp[i]=(val-bat+mod)%mod;
    }
    int ans=0;
    for(int i=1;i<=k;i++)
    {
        ans=(ans+(1LL*dp[i]%mod*i%mod)%mod)%mod;
    }
    printf("%d\n",ans);

    return 0;

}


Measured memory_bytes: 4120
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] ch = str.toCharArray();
        for (int i = 0; i < ch.length; i++){
            if('7' == ch[i]){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");

    }
}


Measured memory_bytes: 35632
from scipy.sparse.csgraph import dijkstra
import numpy as np 

N,X,Y = map(int,input().split())

edge = tuple([0]*N for i in range(N))

for i in range(N-1):
    edge[i][i+1] = 1
    edge[i+1][i] = 1

edge[X-1][Y-1] = 1
edge[Y-1][X-1] = 1

edge_n = np.array(edge)
ans = dijkstra(edge_n)
ans = np.array(ans,dtype="int32")
cnt = [0]*N
for i in range(N):
    for j in ans[i]:
        cnt[j] += 1

for i in range(1,N):
    print(cnt[i]//2)

Measured memory_bytes: 131264
from collections import deque

K = int(input())
if K <= 9:
    print(K)
else:
    que = deque([9,8,7,6,5,4,3,2,1])
    count = 0

    while True:
        x = que.pop()
        count += 1
        if count == K:
            break
        if x%10 != 0:
            que.appendleft(x*10+x%10-1)
        que.appendleft(x*10+x%10)
        if x%10 != 9:
            que.appendleft(x*10+x%10+1)
    
    




            

    print(x)

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

int main(){
  int N,M;
  cin >> N;
  deque<int> dd,dt;
  for(int i=0;i<N;i++){
    int D;
    cin >> D;
    dd.push_back(D);
  }
  cin >> M;
  for(int i=0;i<M;i++){
    int T;
    cin >> T;
    dt.push_back(T);
  }
  sort(dd.begin(),dd.end());
  sort(dt.begin(),dt.end());
  while(1){
    if(dd.size()<dt.size()){
      cout << "NO" << endl;
      return 0;
    }
    if(dt.size()==0){
      break;
    }
    if(dd.front()==dt.front()){
      dd.pop_front();
      dt.pop_front();
    }else{
      dd.pop_front();
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0;i<3;i++){
        if(s[i] == '1'){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def resolve():
    MOD = int(1e9+7)
    N,M = map(int,input().split())
    S= list(map(int,input().split()))
    T= list(map(int,input().split()))
    dpt = [[0]*(M+1) for i in range(N+1)]

    sm = [[0]*(M+1) for i in range(N+1)]

    for i in range(N):
        for j in range(M):
            dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0

            sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD
    ans =0
    for dptr in dpt:
        for i in dptr:
            ans += i
            ans %= MOD

    print(ans+1)            



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 104284
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int w = scn.nextInt(), h = scn.nextInt();
        int x = scn.nextInt(), y = scn.nextInt(), r = scn.nextInt();
        System.out.println(
          x - r < 0 || y - r < 0 || x + r > w || y + r > h ? "No" : "Yes"
        );
    }
}

Measured memory_bytes: 26208
from operator import itemgetter

N = int(input())
L = []
for i in range(N):
    S, P = input().split()
    L.append((S, int(P), i + 1))

L = sorted(L, key=itemgetter(1), reverse=True)
L = sorted(L, key=itemgetter(0))

for l in L:
    print(l[2])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a),i##ed=(b);i<=i##ed;i++)
#define per(i,a,b) for(int i=(a),i##ed=(b);i>=i##ed;i--)
#define LNK(i,a) for(int i=hed[a];i;i=nxt[i])
using namespace std;
typedef long long ll;
const ll mod=924844033;
const int N=200010;
int n,num[N],sz[N];
int cnt=0,hed[N],to[N+N],nxt[N+N];
ll fa[N],fb[N];
ll a[N*4],b[N*4]; int lmt,l,r[N*4];

ll ksm(ll x,ll y) { ll s=1;for(;y;y/=2,x=x*x%mod) if(y%2) s=s*x%mod;return s; }
inline void add(int x,int y) { to[++cnt]=y,nxt[cnt]=hed[x],hed[x]=cnt; }
void dfs(int u,int ff) {
	sz[u]=1;
	LNK(i,u) if(to[i]^ff)
		dfs(to[i],u),sz[u]+=sz[to[i]],--num[sz[to[i]]],--num[n-sz[to[i]]];
}
void ntt(ll *A,int opt) {
	rep(i,0,lmt-1) if(i<r[i]) swap(A[i],A[r[i]]);
	for(int mid=1;mid<lmt;mid<<=1) {
		ll Wn=ksm(opt==1? 5:554906420,(mod-1)/(mid<<1));
		for(int R=mid<<1,j=0;j<lmt;j+=R) {
			ll w=1;
			for(int k=0;k<mid;k++,w=w*Wn%mod) {
				ll x=A[j+k],y=w*A[j+mid+k]%mod;
				A[j+k]=(x+y)%mod,A[j+mid+k]=(x-y+mod)%mod;
			}
		}
	}
	if(opt==-1) {
		ll inv=ksm(lmt,mod-2); rep(i,0,lmt-1) a[i]=a[i]*inv%mod;
	}
}
int main() {
	scanf("%d",&n);
	rep(i,2,n) { int x,y;scanf("%d%d",&x,&y),add(x,y),add(y,x); }
	rep(i,1,n) num[i]=mod; dfs(1,0),num[n]=n; rep(i,1,n) num[i]%=mod;
//	rep(i,1,n) printf("%d ",num[i]); puts("");
	fa[0]=fa[1]=fb[0]=fb[1]=1;
	rep(i,2,n) fa[i]=fa[i-1]*i%mod;
	rep(i,2,n) fb[i]=(mod-mod/i)*fb[mod%i]%mod;
	rep(i,2,n) fb[i]=fb[i-1]*fb[i]%mod;
	rep(i,1,n) a[n-i]=fa[i]*num[i]%mod,b[i-1]=fb[i-1];
//	rep(i,0,n-1) printf("%lld ",a[i]); puts("");
//	rep(i,0,n-1) printf("%lld ",b[i]); puts("");
	for(lmt=1,l=0;lmt<=n+n;lmt<<=1,++l);
	rep(i,0,lmt-1) r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
	ntt(a,1),ntt(b,1);
	rep(i,0,lmt-1) a[i]=a[i]*b[i]%mod;
	ntt(a,-1);
//	rep(i,0,n+n-2) printf("%lld ",a[i]); puts("");
	rep(i,1,n) printf("%lld\n",(a[n-i]*fb[i]%mod+mod)%mod);
	return 0;
}

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

int main() {
  int R;
  cin >> R;
  
  if(R<1200){
    cout << "ABC" << endl;
  }else if(R<2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }
}



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

int main(){
  long Q,H,S,D,N;
  cin>>Q>>H>>S>>D>>N;

  long ans=0;
  if(Q*2<=H){
    H=Q*2;
  }
  if(H*2<=S){
    S=H*2;
  }
  if(S*2<=D){
    D=S*2;
  }

  long d= N/2;
  N-=d*2;
  ans+=d*D;
  long s=N/1;
  N-=s;
  ans+=s*S;
  long h=N/0.5;
  N-=h*0.5;
  ans+=h*H;
  long q=N/0.25;
  N-=q*0.25;
  ans+=q*Q;
  cout<<ans<<endl;
  return  0;

}


Measured memory_bytes: 256
a, b, k = (int(i) for i in input().split())
list_ComDiv = []
for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i == 0:
        list_ComDiv.append(i)
list_ans = sorted(list_ComDiv, reverse=True)
print(list_ans[k - 1])

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1||a==5||a==3||a==7||a==8||a==10||a==12)
    {
        if(b==1||b==5||b==3||b==7||b==8||b==10||b==12)
            cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
    }
    else if(a==4||a==9||a==6||a==11)
    {
        if(b==4||b==9||b==6||b==11)
            cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
    }
    else if(a==7||a==8||a==9)
    {
        if(b==7||b==8||b==9)
            cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
    }
    else if(a==2)
    {
        if(b==2)
            cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
// get<0>(v[i])
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(40);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 40)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 100005

void solve(){
    ll l, r, d;
    cin >> l >> r >> d;
    ll ans = 0;
    for(ll i = l ; i <= r ; i++)
        if(i%d == 0)
            ans++;
    cout << ans << nl;
}
 
int main(){
    // boost;
    // cal(3);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 3572
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
l.sort()

cnt=0
res=0

for i in range(n):
    if l[i][1] > m:
        res += l[i][0]*m
        break
    else:
        m-=l[i][1]
        res+=l[i][0]*l[i][1]

print(res)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v.at(i);
	}

	int wt = 0;
	int i = 0;
	while (wt <= N) {
		wt++;
		int n = v.at(i) - 1;
		if (n == 1) break;
		else i = n;
	}

	if (wt <= N) cout << wt << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 3780
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B, N;
	int ans = INF;
	
	cin>>A>>B>>N;
	
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= N; j++){
			if((i*B)%j) continue;
			// cout<<i<<" "<<j<<" "<<i*B/j<<" "<<abs(A - i*B/j)<<endl;
			ans = min(ans, abs(A - i*B/j));
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        int temp;
        cin >> temp;
        mp[temp]++;
    }
    int cnt = 0;
    for(auto x : mp){
        if(x.first < x.second){
            cnt += x.second - x.first;
        } else if(x.first > x.second){
            cnt += x.second;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 7912
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

struct Stick{
	Int p,q,r,b;
};

vector<Stick> sticks;
vector<Int> weight;

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

int main() {
	int n;
	while(n=in()){
		sticks.clear();
		weight.clear();
		int i;
		Stick buf;
		for(i=0;i<n;i++){
			cin>>buf.p>>buf.q>>buf.r>>buf.b;
			buf.r--;buf.b--;
			sticks.push_back(buf);
			weight.push_back(0);
		}
//for(i=0;i<n;i++)cout<<i<<" "<<sticks[i].p<<" "<<sticks[i].q<<" "<<sticks[i].r<<" "<<sticks[i].b<<endl;
		bool update=true;
		while(update){
			update=false;
			for(i=0;i<n;i++){
				if(weight[i]>0)continue;
				if(sticks[i].r==-1&&sticks[i].b==-1){
					weight[i]=(sticks[i].p+sticks[i].q)/gcd(sticks[i].p,sticks[i].q);
					update=true;
				}else if(sticks[i].r==-1&&weight[sticks[i].b]>0){
					Int r,b;
					b=weight[sticks[i].b]*sticks[i].p;
					r=b*sticks[i].q/sticks[i].p;
					weight[i]=(b+r)/gcd(r,sticks[i].p);
					update=true;
				}else if(sticks[i].b==-1&&weight[sticks[i].r]>0){
					Int r,b;
					r=weight[sticks[i].r]*sticks[i].q;
					b=r*sticks[i].p/sticks[i].q;
					weight[i]=(b+r)/gcd(b,sticks[i].q);
					update=true;
				}else if(weight[sticks[i].r]>0&&weight[sticks[i].b]>0){
					Int r,b;
					b=weight[sticks[i].b]*weight[sticks[i].r]*sticks[i].p;
					r=b*sticks[i].q/sticks[i].p;
					weight[i]=(b+r)/gcd(weight[sticks[i].b]*sticks[i].q,weight[sticks[i].r]*sticks[i].p);
					update=true;
				}
			}
		}
//for(i=0;i<n;i++)cout<<i<<" "<<weight[i]<<endl;
		Int res=0;
		for(i=0;i<n;i++){
			chmax(res,weight[i]);
		}
		cout<<res<<endl;
	}
	return 0;
}

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

signed main(){
	int n, K;
	std::cin >> n >> K;
	std::vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	std::vector<bool> ans(n - K);
	for(int i = 0; i < n - K; i++){
		if(a[i] < a[i + K]) ans[i] = true;
		else ans[i] = false;
	}
	for(auto ok : ans){
		if(ok) std::cout << "Yes" << std::endl;
		else std::cout << "No" << std::endl;
	}
}

Measured memory_bytes: 4856
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
vector<tuple<int, int, int, int>> en;
int bad[30] = {};
int already_done[1LL << 24LL];
int cnt[30] = {};
int kasane(int x1, int y1, int c1, int x2, int y2, int c2) {
	int hoge = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
	if (hoge >= (c1 + c2) * (c1 + c2)) return 0;
	return 1;
}
int solve(int now) {
	if (already_done[now] == 1) return 0;
	already_done[now] = 1;
	int ans = 0;
	for (int i = 0; i < en.size(); ++i) {
		if (cnt[i] == 0 && bad[i] == 0) {
			for (int q = i + 1; q < en.size(); ++q) {
				if (cnt[q] == 0 && bad[q] == 0) {
					if (get<3>(en[q]) == get<3>(en[i])) {
						bad[i] = 1;
						bad[q] = 1;
						for (int j = i + 1; j < en.size(); ++j) {
							int hoge = kasane(get<0>(en[i]), get<1>(en[i]), get<2>(en[i]), get<0>(en[j]), get<1>(en[j]), get<2>(en[j]));
							if (hoge == 1) {
								cnt[j]--;
							}
						}
						for (int j = q + 1; j < en.size(); ++j) {
							int hoge = kasane(get<0>(en[q]), get<1>(en[q]), get<2>(en[q]), get<0>(en[j]), get<1>(en[j]), get<2>(en[j]));
							if (hoge == 1) {
								cnt[j]--;
							}
						}
						ans = max(ans, solve(now + (1 << i)+(1 << q))+2);
						bad[i] = 0;
						bad[q] = 0;
						for (int j = i + 1; j < en.size(); ++j) {
							int hoge = kasane(get<0>(en[i]), get<1>(en[i]), get<2>(en[i]), get<0>(en[j]), get<1>(en[j]), get<2>(en[j]));
							if (hoge == 1) {
								cnt[j]++;
							}
						}
						for (int j = q + 1; j < en.size(); ++j) {
							int hoge = kasane(get<0>(en[q]), get<1>(en[q]), get<2>(en[q]), get<0>(en[j]), get<1>(en[j]), get<2>(en[j]));
							if (hoge == 1) {
								cnt[j]++;
							}
						}
					}
				}
			}
		}
	}
	return ans;
}
int main() {
	while (true) {
		en.clear();
		REP(i, 1 << 24) {
			already_done[i] = 0;
		}
		REP(q, 30) {
			cnt[q] = 0;
			bad[q] = 0;
		}
		int n;
		cin >> n;
		if (n == 0) return 0;
		REP(i, n) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			en.push_back(make_tuple(a, b, c, d));
		}
		for (int i = 0; i < n; ++i) {
			for (int q = i + 1; q < n; ++q) {
				if (kasane(get<0>(en[q]), get<1>(en[q]), get<2>(en[q]), get<0>(en[i]), get<1>(en[i]), get<2>(en[i])) == 1) {
					cnt[q]++;
				}
			}
		}
		cout << solve(0) << endl;
	}
}


Measured memory_bytes: 68588