akhauriyash/Code-Regression huggingface dataset:
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n):
    x = 0
    for j in range(m):
        x += a[i][j] * b[j]
    if x + c > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
import sys


TEST_INPUT = [
    """
    100
    1
    """,
    """
    25
    2
    """,
    """
    314159
    2
    """,
    """
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    3
    """
]
ANSWER = [
    "19",
    "14",
    "937",
    "117879300"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(n, k):
    res = 0
    le = len(n) - 1

    # smaller order
    if k == 1 and le >= 1:
        res += 9 * le
    if k == 2 and le >= 2:
        res += 9 * 9 * le * (le - 1) // 2
    if k == 3 and le >= 3:
        res += 9 * 9 * 9 * le * (le - 1) * (le - 2) // 6

    # bxxxxx
    if k == 1:
        res += int(n[0]) - 1
    if k == 2:
        res += (int(n[0]) - 1) * (9 * le)
    if k == 3:
        res += (int(n[0]) - 1) * (9 * 9 * le * (le - 1) // 2)

    # axxxxx
    if k == 1:
        res += 1
    if k == 2:
        # first nonzero
        for i in range(1, le + 1):
            if int(n[i]) > 0:
                res += int(n[i])
                res += 9 * (le - i)
                break
    if k == 3:
        j = 0
        # first nonzero
        for i in range(1, le + 1):
            if int(n[i]) > 0:
                res += (int(n[i]) - 1) * 9 * (le - i)
                res += 9 * 9 * ((le - i) * (le - i - 1) // 2)
                j = i
                break
        # second nonzero
        for i in range(j + 1, le + 1):
            if int(n[i]) > 0:
                res += int(n[i])
                res += 9 * (le - i)
                break
    return res


def input_and_solve(ih):
    n = ih.input()
    k = int(ih.input())
    res = solve(n, k)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    print(res)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        # print(res, ans)
        assert str(res) == str(ans)


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3192
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n;
//<<-----Implement Functions Here---->>//
const ll N2=1e7+8;
ll p[N2];
void sieve(){
    for(ll i = 2; i*i <= N2; i++){
        if(p[i] == 0){
            for(ll j = 2*i; j < N2; j += i){
           		if(p[j]==0) p[j]=i;
            }
        }
    }
    for(ll i=1;i<N2-1;i++)if(p[i]==0)p[i]=i; 
}
vll getFactorization(ll x) 
{ 
    vll ret; 
    while(x!=1){ret.pb(p[x]);x = x/p[x];} 
    return ret; 
} 

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n;ll ans = 0;
		for(ll i=1;i<=n;i++)
		{
			map<ll,ll>map1;ll temp = 1;
			vll v = getFactorization(i);
			for(auto it:v)map1[it]++;
			for(auto it:map1)temp *= (it.s+1);
			ans += i*temp;
		}
		cout<<ans<<endl;
}	

int main(){
    fastio;randomINIT;
    sieve();
    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 88796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;
 
int main()
{
	int N,sum =0,mx = 0;
	vector<int> s;
	cin >> N;
	s.resize(N);
 
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		sum += s[i];
	}
 
	sort(s.begin(),s.end());
	if (sum % 10 != 0) {
		mx = sum;
	}
	else {
		for (int i = 0; i < N; i++) {
			if ((sum - s[i]) % 10 != 0) {
				mx = sum - s[i];
				break;
			}
		}
	}
	cout << mx << endl;
return	0;
}

Measured memory_bytes: 256
from itertools import accumulate
import math
import bisect
n,q = map(int, input().split())
a = list(map(int, input().split()))

a_ac = [0] + list(accumulate(a))
taka_ac = [0] + list(accumulate(reversed(a[::-2]))) 
aoki_ac = [0] + list(accumulate(reversed(a[-2::-2]))) 
x = []
y = [10000000000]
z = [taka_ac[-1]]
for i in range(q):
  x.append(int(input()))
if n > 2:
  for i in range((n-1)//2):
    y.append((a[-i-2]+a[-i-3-i])//2)
    z.append(taka_ac[-i-3]+a_ac[-1]-a_ac[-i-3])
y.reverse()
z.reverse()
if n > 2:
  for i in x:
    print(z[bisect.bisect_left(y,i)])
else:
  for i in x:
    print(a[1])

Measured memory_bytes: 26944
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();

		int i,j;
		long cnt;
		double ans = 0.0;
		for(i = 1; i <= n; i++) {
			cnt = 0;
			double temp = i;
			while(temp < k) {
				cnt++;
				temp *= 2;
			}
			ans += (1 / (Math.pow(2, cnt) * n));
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[1010][1010];
ll dis[1010][1010];
bool f[1010][1010];
int main(){
	ll h,w,sy,sx,gy,gx;
	cin>>h>>w>>sy>>sx>>gy>>gx;
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
		cin>>s[i][j];
		dis[i][j]=1e9;
	}
	dis[sy][sx]=0;
	deque<pair<ll,ll>>deq;
	deq.push_front({sy,sx});
	ll dy[4]={0,1,0,-1},dx[4]={1,0,-1,0};
	while(!deq.empty()){
		pair<ll,ll>p=deq.front();
		deq.pop_front();
		ll y=p.first,x=p.second,cos=dis[y][x];
		if(f[y][x])continue;
		f[y][x]=1;
		for(int i=0;i<4;i++){
			if(!(1<=y+dy[i]&&y+dy[i]<=h&&1<=x+dx[i]&&x+dx[i]<=w))continue;
			if(s[y+dy[i]][x+dx[i]]=='.'){
				if(cos<dis[y+dy[i]][x+dx[i]]){
					deq.push_front({y+dy[i],x+dx[i]});
					dis[y+dy[i]][x+dx[i]]=cos;
				}
			}
		}
		for(int i=y-2;i<=y+2;i++)for(int j=x-2;j<=x+2;j++){
			if(!(1<=i&&i<=h&&1<=j&&j<=w)||(i==y&&j==x))continue;
			if(s[i][j]=='.'&&cos+1<dis[i][j]){
				deq.push_back({i,j});
				dis[i][j]=cos+1;
			}
		}
	}
	if(dis[gy][gx]==1e9)cout<<-1<<endl;
	else cout<<dis[gy][gx]<<endl;
	return 0;
}


Measured memory_bytes: 13596
N,M,C=map(int,input().split())
b=list(map(int,input().split()))
a=list(range(N))
for i in range(N):
    a[i]=list(map(int,input().split()))
ab=list(range(N))
count=0

for i in range(N):
    ab[i]=0
    for j in range(M):
        ab[i]+=a[i][j]*b[j]
    if ab[i]+C>0:
        count+=1

print(count)


Measured memory_bytes: 3064
#include<stdio.h>
#define N 36

typedef struct{
  char kind;
  int num;
}Card;

void bubblesort(Card * ,int);
void selectionsort(Card *,int);
//void swap(Card *,Card *);
int isStable(Card *,Card *,int n);

int main(){
  int n;
  int i;
  Card card1[N],card2[N];
  int flag=0;
  
  scanf("%d",&n);//枚数の入力
  for(i=0;i<n;i++){
    scanf(" %c%d",&card1[i].kind,&card1[i].num);
    card2[i]=card1[i];
  }
  
  
  bubblesort(card1,n);
  for(i=0;i<n-1;i++){
    printf("%c%d ",card1[i].kind,card1[i].num);
  }
  printf("%c%d\n",card1[n-1].kind,card1[n-1].num);
  printf("Stable\n");
  
  selectionsort(card2,n);
  for(i=0;i<n-1;i++){
    printf("%c%d ",card2[i].kind,card2[i].num);
  }
  printf("%c%d\n",card2[n-1].kind,card2[n-1].num);
  for(i=0;i<n;i++){
    flag=flag+isStable(card1,card2,n);
  }
  if(flag==0)printf("Not stable\n");
  else printf("Stable\n");
  return 0;
}

void bubblesort(Card A[],int n){
  int i,j;
  Card temp;
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j].num<A[j-1].num){
	//swap(&A[j],&A[j-1]);
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
      }
    }
  }
  
}

void selectionsort(Card A[],int n){
  int i,j,minj;
  Card temp;
  for(i=0;i<=n-1;i++){
    minj=i;
    for(j=i;j<=n-1;j++){
      if(A[j].num<A[minj].num)
	minj=j;
      }
    
   
   
      temp=A[i];
      A[i]=A[minj];
      A[minj]=temp;
    }
  
}
 
/*void swap(Card *a,Card *b){
  Card temp;
  temp=*a;
  *a=*b;
  *b=temp;
  }*/

int isStable(Card *a,Card *b,int n){
  int i;

  for(i=0;i<n;i++){
    if(a[i].kind!=b[i].kind) 
    return 0;
  }
  return 1;
}



Measured memory_bytes: 2760
#include<iostream>
#include<string>
using namespace std;
 
int main(){
   long long N,M,ans;
   cin >> N;
   cin >> M;
   if(N == 1){
     if(M == 1){ans = 1;}
     if(M == 2){ans = 0;}
     if(M >= 3){ans = M-2;}
   }
   if(N == 2){
     ans = 0;
   }
   if(N >= 3){
     if(M == 1){ans = N-2;}
     if(M == 2){ans = 0;}
     if(M >= 3){ans = (N-2)*(M-2);}    
   }
   cout<<ans<<endl;
   return 0;
}

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

int main() {
  	int n;
	cin >> n;
  	vector<int> vec(n);
  	for (int i = 0; i < n; ++i) {
      cin >> vec[i];
    }
  	int ans = 0;
  	for (int i = 1; i < n - 1; ++i) {
      vector<int> s = {vec[i-1],vec[i], vec[i+1]};
      sort(s.begin(), s.end());
      if (vec[i] == s[1]) ans++;
    }
  cout << ans << endl;
  
  
  	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll solve(string s, string t) {
    int s_len = SIZE(s);
    map<char, vector<ll>> ch2loc;
    REP(i, s_len) {
        auto ch = s[i];
        ch2loc[ch].pb(i);
    }

    ll ans = 0;
    ll prev = -1;
    bool ok = true;
    for(auto ch: t) {
        if (SIZE(ch2loc[ch]) == 0) {
            ok = false;
            break;
        } else {
            auto it = lower_bound(ALL(ch2loc[ch]), prev + 1);
            if (it == ch2loc[ch].end()) {
                ans += (s_len - prev) + ch2loc[ch][0];
                prev = ch2loc[ch][0];
            } else {
                ans += *it - prev;
                prev = *it;
            }
        }
        // cout << "prev = " << prev << ", ans = " << ans << endl;
    }
    if (ok) {
        return ans;
    } else {
        return -1;
    }
}

int main(void)
{
    cin.sync_with_stdio(false);
    string s;
    cin >> s;
    string t;
    cin >> t;

    cout << solve(s, t) << endl;

    // assert(solve("a", "aaa") == 3);

    return 0;
}


Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int, int > Pi;
const int INF = 1 << 30;
 
int N, M;
string S;
int dp[1000003];
int rec(int idx)
{
  if(~dp[idx]) return(dp[idx]);
  int ret = 0;
  if(S[idx] == 'O' && S[idx + 1] == 'I') ret = rec(idx + 2) + 1;
  return(dp[idx] = ret);
}
 
int main()
{
  while(cin >> N, N) {
    memset(dp, -1, sizeof(dp));
    cin >> M;
    cin >> S;
    int ret = 0;
    for(int i = 0; i < M - 2; i++) {
      if(S[i] == 'I') ret += rec(i + 1) >= N;
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 6288
n = int(input())
a = list(map(int, input().split()))
print(2*n-1)
if max(a) >= abs(min(a)):
  base = a.index(max(a)) + 1
  for i in range(1,n+1):
    print(base,i)
  for i in range(1,n):
    print(i,i+1)
else:
  base = a.index(min(a)) + 1
  for i in range(1,n+1):
    print(base,i)
  for i in range(n,1,-1):
    print(i,i-1)
    

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

int main() {
  int H, N;
  cin >> H >> N;
  int sum = 0;
  int a = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    sum += a;
  }
  if (sum < H) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int  long long 
#define loop(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007
#define INF 1000000000000
#define pb push_back
#define lim 1000001
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,ans=0,red=0,white=0,r=0,w=0,i;
    
    cin>>n;
    char s[n+1];
    cin>>s;

    loop(i,0,n)
    {
    	if(s[i]=='W')
    		white++;
    	else
    		red++;
    }

    ans=white;

    loop(i,0,n)
    {
        ans=min(ans,max(w,red-r));
        if(s[i]=='W') w++;
        else
        	r++;
    }
    cout<<ans<<endl;
    

    return 0;}

Measured memory_bytes: 3844
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  int W,a,b;
  cin >> W >> a >> b;
  if(b>a+W)
    cout << b-(a+W) << endl;
  else if((a+W)==b)
    cout << 0 << endl;
  else if(b<a+W && b+W>a+W)
    cout << 0 << endl;
  else if(a==b && a+W==b+W)
    cout << 0 << endl;
  else if(b<a && b+W>a)
    cout << 0 << endl;
  else if(a==b+W)
    cout << 0 << endl;
  else if(b+W<a)
    cout << a-(b+W) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  ll a[200005];
  ll b[200005];
  ll ans = 0;
  FOR(i, 1, n + 1) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  FOR(i, 1, m + 1) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  int j = m;
  REP(i, n + 1) {
    for (; j >= 0; j--) {
      if (a[i] + b[j] <= k) {
        ans = max(ans, (ll)(i + j));
        break;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 6736
n = int(raw_input())
a = [int(x) for x in raw_input().split()]

c = {}

for v in a:
    if v not in c:
        c[v] = 0
    c[v] += 1

d = {i: 1 if i == 0 else 2 for i in xrange(1 - n % 2, n, 2)}

MOD = 10**9 + 7

if c == d:
    print pow(2, n // 2, MOD)
else:
    print 0


Measured memory_bytes: 13336
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int X,A,B;
  cin>>X>>A>>B;
  cout<<(X-A)%B;
  }


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

buf = [[0] for i in range(n)] 

for i in range(m):
    buf[ab[i][0] - 1].append(h[ab[i][1] - 1])
    buf[ab[i][1] - 1].append(h[ab[i][0] - 1])

cnt = 0
for i in range(n):
    if h[i] > max(buf[i]):
        cnt += 1

print(cnt)

Measured memory_bytes: 44144
#if 0
date +%Y.%m.%d

称形如 111...111 的数为 MAGIC ，特别的， 0 也是 MAGIC 。
上升数一定可以表示成恰好 9 个 MAGIC 的和。
那么 N 表示成 K 个上升数的和就等价于 9K 个 MAGIC 的和。
即 N = sum(9K) { (10^x - 1) / 9 } 。
化简得 9N + 9K = sum(9K) { 10^x } 。
那么从小到大枚举 K ，每次 K 的增加会使左边加 9 。
考虑右边的数的数位和，假设没有进位显然是 9K ，算上进位，右边的取值是形如 9K - 9X 的数。
那么找到第一个 K 满足左边的数位和不大于 9K 即可。
#endif
#include <cstdio>
#include <cstring>
#define debug(...) fprintf(stderr, __VA_ARGS__)

const int maxn = 1000005;
char s[maxn];
int a[maxn];

int main() {
	scanf("%s", s);
	int n = strlen(s), k = 0, sum = 0;
	for(int i = 0; i < n; i ++) {
		a[i] = (s[n - i - 1] - '0') * 9;
		sum += a[i];
	}
	for(int i = 0; i < n or a[i]; i ++) {
		sum -= a[i] / 10 * 9;
		a[i + 1] += a[i] / 10;
		a[i] %= 10;
		// debug("%d", a[i]);
	}
	// debug(" -> %d\n", sum);
	while(sum > 9 * k) {
		a[0] += 9;
		sum += 9;
		for(int i = 0; a[i] > 9; i ++) {
			sum -= 9;
			a[i + 1] ++;
			a[i] -= 10;
		}
		k ++;
	}
	printf("%d\n", k);
}

Measured memory_bytes: 4608
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
cnt=0
for i in range(N):
    A=list(map(int,input().split()))
    res=C
    for j in range(M):
        res+=A[j]*B[j]
    if res>0:cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int N,C,K;
int T[100100];
int main(){
	cin >> N >> C >> K;
	for(int i=0;i<N;i++)cin >> T[i];
	sort(T,T+N);
	int s = 0,t = 0;
	int ans = 0;
	while(s<N){
		while(t<N&&T[t]<=T[s]+K){
			t++;
		}
		ans++;
		s = min(s+C,t);
	}
	cout << ans << endl;
	return 0;
}


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

class Edge
{
	public:
	int to,cost;
	Edge(int t,int c)
	{
		to=t;
		cost=c;
	}
};

vector<Edge> g[100]; //辺を張る
vector<Edge> rg[100]; //逆辺を張る
vector<int> vs; //帰りがけ順の並び
vector<int> tres;//トポロジカルソートの結果
double p[100];
bool used[100];

//2つの関数でトポロジカルソート
void visit(int k)
{
	if(!used[k])
	{
		used[k]=true;
		for(int j=0;j<g[k].size();j++)
			visit(g[k][j].to);
		tres.push_back(k);
	}
}

void tsort(int n)
{
	for(int i=0;i<n;i++)
		visit(i);
	reverse(tres.begin(),tres.end());
}

//DFSで起きなければならない人から起こせる人を列挙する
void dfs1(int now)
{
	used[now]=true;
	for(int i=0;i<g[now].size();i++)
	{
		Edge e=g[now][i];
		if(!used[e.to])
			dfs1(g[now][i].to);
	}
	return;
}

//ループをdpで調べる
void dfs2(int now)
{
	used[now]=true;
	for(int i=0;i<g[now].size();i++)
	{
		if(!used[g[now][i].to])
			dfs2(g[now][i].to);
	}
	vs.push_back(now);
}

void rdfs2(int now,int k)
{
	used[now]=true;
	tres[now]=k;
	for(int i=0;i<rg[now].size();i++)
	{
		if(!used[rg[now][i].to])
			rdfs2(rg[now][i].to,k);
	}
}

//短縮後の要素数を返す
int scc(int n)
{
	fill(used,used+100,false);
	vs.clear();
	for(int i=0;i<n;i++)
	{
		if(!used[i])
			dfs2(i);
	}
	fill(used,used+100,false);
	int k=0;
	for(int i=vs.size()-1;i>-1;i--)
	{
		if(!used[vs[i]])
			rdfs2(vs[i],k++);
	}
	return k;
}
int main()
{
	while(1)
	{
		int n;
		double ans=1.0;
		cin>>n;
		if(n==0)
			break;
		for(int i=0;i<100;i++)
		{
			rg[i].clear();
			g[i].clear();
		}
		tres.clear();
		fill(used,used+100,false);
		for(int i=0;i<n;i++)
		{
			cin>>p[i];
			int m;
			cin>>m;
			for(int j=0;j<m;j++)
			{
				int a;
				cin>>a;
				a--;
				g[i].push_back(Edge(a,1));
				rg[a].push_back(Edge(i,1));
			}
		}
		tsort(n);
		/*
		for(int i=0;i<n;i++)
			cerr<<tres[i]<<" ";
		cerr<<endl;*/
		scc(n);//トポロジカルソートして強連結成分分解
		/* 
		for(int i=0;i<n;i++)
			cerr<<tres[i]<<" ";
		cerr<<endl;*/
		fill(used,used+100,false);
		//トポロジカルソート昇順で調べる
		//これにはO(N^2)かける
		for(int cnt=0;cnt<n;cnt++)
		{
			vector<int> tmp;
			for(int j=0;j<n;j++)
			{
				if(tres[j]==cnt && !used[j])
					tmp.push_back(j);
			}
			if(tmp.size()==0)
				continue;
			//tmpに同じ強連結成分が入っている
			double kari=1.0;
			for(int j=0;j<tmp.size();j++)
				kari*=p[tmp[j]];
			ans*=(1.0-kari);
			dfs1(tmp[0]);
		}
		cout<<fixed<<setprecision(12)<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3400
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,i,a[1001],b[1001],s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(i=n-1;i>1;i--){
		if(a[i]==b[i]&&a[i-1]==b[i-1]&&a[i-2]==b[i-2]){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

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

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> t;
    rep(i, M){
        int p, y;
        cin >> p >> y;
        t.emplace_back(p, y, i);
    }
    sort(t.begin(), t.end());

    vector<int> fr(M);
    vector<int> ba(M);
    for(int i = 0; i < M; ){
        int prefecture = get<0>(t[i]);
        int j = 0;
        while(prefecture == get<0>(t[i]) && i < M){
            int index = get<2>(t[i]);
            fr[index] = prefecture;
            ba[index] = j+1;
            j++;
            i++;
        }
    }
    rep(i, M){
        printf("%06d", fr[i]);
        printf("%06d\n", ba[i]);
    }
    return 0;
}

Measured memory_bytes: 5368
#include <stdio.h>     
int main()  
{   int m,n,flag;  
    scanf("%d",&n);  
    while(n--) 
	{   flag=1;  
        int a,b=0,c=0;  
        for(m=1;m<=10;m++) 
		{   scanf("%d",&a);  
            if(flag)
			{   if(a>b)  
                    b=a;  
                else if(a>c)  
                    c=a;  
                else  
                    flag=0;  
            }  
        }  
        if(flag==0)
            printf("NO\n");
        else
            printf("YES\n");
    }  
    return 0;  
}  


Measured memory_bytes: 1972
s = input()

A=[["R","U","D"],["L","U","D"]]

ans = 0
t = 0
for i in range(len(s)):
    if s[i] in A[t]:
        ans += 1
    t = (t+1) % 2

if ans == len(s):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
k, n, *A = map(int, open(0).read().split())

dist = A[0] + (k - A[-1])
maxdist = dist
start = 0

for i in range(n - 1):
    if maxdist < A[i + 1] - A[i]:
        start = i + 1
        maxdist = A[i + 1] - A[i]

if start == 0:
    print(A[-1] - A[0])
else:
    print(A[-1] - A[start] + dist + (A[start - 1] - A[0]))

Measured memory_bytes: 25124
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register
#define LL long long
#define fre(a) freopen(a".in","r",stdin);//freopen(a".out","w",stdout);
using namespace std;
const int MAXN=300000;
int n,m;
int X[MAXN],Y[MAXN],fa[MAXN];
double ans,ALL;
struct ed
{
   int from,to;
   double len;
}edge[MAXN];
bool comp(ed x,ed y){ return x.len>y.len; }
int find(int x)
{
   if(x!=fa[x])
      fa[x]=find(fa[x]);
   return fa[x];
}
void Union(int x,int y)
{
   x=find(x);
   y=find(y);
   fa[x]=y;
}
void work()
{
   int cnt=0;
   for(int i=1;i<=m;i++)
      {
	 int A=edge[i].from,B=edge[i].to;
	 if(find(A)!=find(B))
	    {
	       Union(A,B);
	       ans+=edge[i].len;
	       cnt++;
	    }
	 if(cnt>=n-1)break;
      }
}
int main()
{
   //fre("1");
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
      {
	 scanf("%d%d",&X[i],&Y[i]);
	 fa[i]=i;
      }
   for(int i=1,a,b;i<=m;i++)
      {
	 scanf("%d%d",&a,&b);
	 edge[i].from=a;
	 edge[i].to=b;
	 edge[i].len=sqrt((X[a]-X[b])*(X[a]-X[b])+(Y[a]-Y[b])*(Y[a]-Y[b]));
	 ALL+=edge[i].len;
      }
   sort(edge+1,edge+1+m,comp);
   work();
   ans=ALL-ans;
   printf("%.3lf\n",ans);
   return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    }
    else if(n == 2){
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	std::ios::sync_with_stdio(false);
	int n, a[200005];
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a,a+n);
	int flag = 0;
	for(int i=0; i<n-1; i++){
		if(a[i]==a[i+1]){
			flag = 1;
			break;
		}
	}
	if(flag) cout << "NO"<<endl;
	else cout << "YES" <<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int x,y;
  cin>>x>>y;
  if(abs(x)==abs(y)){
    cout<<1<<endl;
    return 0;
  }else{
    if(x==0&&y!=0){
      if(y>0)cout<<abs(y)<<endl;
      else cout<<abs(y)+1<<endl;
    }else if(x!=0&&y==0){
      if(x>0)cout<<x+1<<endl;
      else cout<<abs(x)<<endl;
    }else if(x<y){
      if((x>0&&y>0)||(x<0&&y<0)){
        cout<<abs(y-x)<<endl;
      }else{
        cout<<abs(x*(-1)-y)+1<<endl;
      }
    }else{
      if((x>0&&y>0)||(x<0&&y<0)){
        cout<<abs(x-y)+2<<endl;
      }else{
        cout<<abs(x-y*(-1))+1<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int num,pmax,psum,temp,st1,st2,i;
    while (1) {
        scanf("%d",&num);
        if (num==0) break;
        psum=0;
        for (i=0; i<num; i++) {
            scanf("%d %d %d",&temp,&st1,&st2);
            st1+=st2;
            if (st1>psum) {
                pmax=temp;
                psum=st1;
            }
        }
        printf("%d %d\n",pmax,psum);
    }
    return 0;
}

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

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define eb emplace_back
#define vec vector

typedef long long ll;

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

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

template<class T> T gcd(T m, T n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}

template<class T> T lcm(T m, T n) {
  return m * n / gcd(m, n);
}

const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;

using namespace std;

/* Input variables. */
int n, m;
vec<vec<int>> s;
vec<int> p;

/* Solve! */
void solve() {
  int ans = 0;
  rep(i, 1 << n) {
    bool ok = true;
    rep(j, m) {
      int c = 0;
      for (auto k : s[j]) {
        if ((i >> k) & 1) {
          c++;
        }
      }
      if (c % 2 != p[j])
        ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl;
}

int main() {
  /* Input handling. */
  cin >> n >> m;
  s = vec<vec<int>>(m);
  p = vec<int>(m);
  rep(i, m) {
    int k; cin >> k;
    s[i] = vec<int>(k);
    rep(j, k) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, m) cin >> p[i];

  solve();
  return 0;
}

Measured memory_bytes: 256
def m(L,R):
 global c;c+=len(L)+len(R)
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


Measured memory_bytes: 61868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double x = sc.nextDouble();
		double r;
		if(x>a*a*b/2) {
			r = Math.atan((2*b/a)-(2*x/(a*a*a)));
		}else {
			r = Math.atan((a*b*b)/(2*x));
		}
		System.out.println(String.format("%.10f", r*180/Math.PI));
	}

}


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

int main() {
  int n,sum;
  int d[3010];
  cin >> n;
  for(int i=0 ;i<n ;i++){
    cin >> d[i];
  }
  for(int i=0 ;i<n ;i++){
    sum += d[i]-1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}

const int N=3005;
int G[N][N];
LL dp[N][N][5];
void main() {
    int r,c,m;
    R(r,c,m);
    REP(i,m) {
        int a,b,c;
        R(a,b,c);
        --a; --b;
        G[a][b]=c;
    }
    REP(i,r) REP(j,c) {
        REP(k,4) chmax(dp[i+1][j+1][0],dp[i][j+1][k]);
        REP(k,4) chmax(dp[i+1][j+1][k],dp[i+1][j][k]);
        if ( G[i][j]>0 ) {
            for ( int k=2; k>=0; k-- ) {
                chmax(dp[i+1][j+1][k+1],dp[i+1][j+1][k]+G[i][j]);
            }
        }
    }
    LL ans=0;
    REP(k,4) chmax(ans,dp[r][c][k]);
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 391168
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)

A, B, C, D = map(int, input().split())

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)

print((B-A+1) -(b_num - a_num))


        

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
ll m[100005];
ll fpow(ll a,ll b)
{
    if(a==0) return 0;
    if(b==0) return 1;
    if(b==1) return a;
    ll t=fpow(a,b/2)%MOD1,ans=t*t%MOD1;
    if(b%2) ans=ans*a%MOD1;
    return ans;
}
int main()
{

    ll n,k,ans=0;
    cin>>n>>k;
    for(int i=k;i>=1;i--)
    {
        m[i]=fpow(k/i,n);
        for(int j=2*i;j<=k;j+=i)
        {
            m[i]=(m[i]-m[j]+MOD1)%MOD1;
        }
        ans=(ans+i*m[i])%MOD1;
    }
    cout<<ans;
}



Measured memory_bytes: 4396
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

void solve();

int a, b, c;

int main() {
  cin >> a >> b >> c;

  solve();

  return 0;
}

void solve() {

  for(int i=1; i<=(a*b); ++i) {
    if((a*i)%b==c) {
      cout << "YES" << endl;
      return;
    }
  }

  cout << "NO" << endl; 
}


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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int dp[105][4][2];

int main()
{
    string s; cin >> s;
    int K; cin >> K;
    int n = s.size();
    dp[0][0][0] = 1;
    rep(i,n) rep(j,4) rep(k,2) {
        int nd = s[i] - '0';
        rep(d,10){
            if(d != 0){
                if(j+1>K) continue;
                if(k == 0){
                    if(d < nd)  dp[i+1][j+1][1] += dp[i][j][k];
                    if(d == nd) dp[i+1][j+1][k] += dp[i][j][k];
                }else{
                    dp[i+1][j+1][k] += dp[i][j][k];
                }
            }else{
                if(k == 0){
                    if(d > nd) continue;
                    if(d < nd)  dp[i+1][j][1] += dp[i][j][k];
                    if(d == nd) dp[i+1][j][k] += dp[i][j][k];
                }else{
                    dp[i+1][j][k] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[n][K][0] + dp[n][K][1] << endl;
}

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

const int INF = 1e9;
const ll LINF = 1e18;


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

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

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  string ans;
  
  for(int i = 0 ; i < s.size() ; i++){
  	if(s.at(i)=='0'){
      ans += '0';
    }else if(s.at(i)=='1'){
      ans += '1';
    }else if(s.at(i)=='B'&ans.size()!=0){
      ans.pop_back();
    }
  		//cout << i << " : " <<  ans << endl; 
  }
	
  cout << ans << endl;
}


Measured memory_bytes: 3600
import heapq
import math
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = [-A[_] for _ in range(N)]
heapq.heapify(A)
for i in range(M):
    B = math.ceil(heapq.heappop(A)/2)
    heapq.heappush(A,B)
print(-sum(A))



Measured memory_bytes: 14532
#include <stdio.h>

int main(void){
	int x,i,j,r,c,A[200][200]={0};
	scanf("%d %d",&r,&c);
	for(j=0;j<r;j++){
		for(i=0;i<c;i++){
			scanf("%d",&x);
			A[i][j]+=x;
		}
	}
	for(j=0;j<r;j++){
		for(i=0;i<c;i++){
			A[c][j]+=A[i][j];
		}
	}
	for(i=0;i<=c;i++){
		for(j=0;j<r;j++){
			A[i][r]+=A[i][j];
		}
	}
	for(j=0;j<=r;j++){
		for(i=0;i<=c;i++){
			printf("%d", A[i][j]);
			if(i!=c) printf(" ");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a>> b;
  if(a>=13)
    cout << b << endl;
  else if(a>=6)
    cout << b/2 << endl;
  else
    cout << 0 << endl;
  return 0;
}


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

int main(void){
	int n; cin >> n; int x[n], y[n], xy[2]={0,0};
	for(int i=0; i<n; i++) {
		cin >> x[i] >> y[i];
		xy[(x[i]+y[i])%2]=1;
	}
	if (xy[0] && xy[1]) {cout << -1 << endl; return 0;}
	vector<int> v;
	if (xy[0]) v.push_back(1);
	for(int i=1<<30; i>0; i>>=1) {
		v.push_back(i);
	}
	cout << v.size() << endl;
	for(int i=0; i<v.size(); i++) {
		cout << v[i] << " ";
	} cout << endl;
	for(int i=0; i<n; i++) {
		int xx=0, yy=0;
		for(int j=0; j<v.size(); j++){
			if (abs(x[i]) > abs(y[i])) {
				if (x[i] > 0) {x[i]-=v[j]; cout << "R";}
				else {x[i]+=v[j]; cout << "L";}
			} else {
				if (y[i] > 0) {y[i]-=v[j]; cout << "U";}
				else {y[i]+=v[j]; cout << "D";}
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,K;
  cin >> N >> K;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N-K; i++) {
    if (A[i] < A[i+K]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5148
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue> 
using namespace std;
int n,k;
const int N=5001;
int x[N],tmp[N];
bool f[N][N];
bool check(int d)
{
    if(x[d]>=k) return true; 
    int i,j,cnt=0;
    memset(tmp,0,sizeof(tmp));
    memset(f,false,sizeof(f));
    for(i=1;i<=n;i++)
        if(i!=d)
            tmp[++cnt]=x[i];
    f[1][0]=true;
    if(tmp[1]<=k)   f[1][tmp[1]]=true;
    for(i=2;i<=n-1;i++)
        for(j=0;j<=k;j++)
            if(j-tmp[i]>=0)
                f[i][j]=f[i-1][j-tmp[i]];
            else
                f[i][j]=f[i-1][j];
    for(i=k-x[d];i<k;i++)
        if(f[n-1][i])
            return true;
    return false;
}
int main()
{
    int i,j,l,r;
    cin>>n>>k;
    for(i=1;i<=n;i++)
        scanf("%d",&x[i]);
    sort(x+1,x+n+1);
    l=1,r=n;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(!check(mid)) l=mid+1;
        else    r=mid-1;
    } 
    cout<<r;
   /* cout<<check(1);
    //cout<<f[5][16]<<' '<<f[5][19];
    for(i=1;i<=n;i++)
        for(j=0;j<=k;j++)
            if(f[i][j])
                cout<<i<<' '<<j<<endl;*/
    return 0;
}


Measured memory_bytes: 24704
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring> 
#include<vector>

using namespace std;

const int N=300;

int a,b,c;

int main()
{
	scanf("%d %d %d",&a,&b,&c);
	printf("%d\n",min(a*b,c));
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define pb(z) push_back(z)
#define ff first
#define ss second
#define pi(a,b) make_pair(a,b)
#define pii pair<ll,ll>
#define T int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define input(v,n) vector<int>v;for(int i=0;i<n;i++){int x;cin>>x;v.push_back(x);}
#define debugg(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;


const int inf    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 2e5+5;
//vector<int>v;
//for(int i=0; i<n; i++)
//{
//    int x;
//    cin>>x;
//    v.push_back(x);
//}
inline ll ok(ll n)
{
    return (n*(n+1))/2;
}

int main()
{


    int n,n2;
    cin>>n;
    input(v,n);
    int res=0;
    int maxx=-1;
    rep(i,0,n-1)
    {
        if(v[i]<=v[i+1]);
     
        else
        {
            res+=v[i]-v[i+1];
            

        }
        // cout<<res<<endl;

    }
    res+=v[n-1];
    cout<<res<<endl;




}


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

int main (void) {
    int N;
    cin >> N;
    int A[N] = {0};
    int result[N] = {0};

    for (int i = 1; i < N; ++i) {
        cin >> A[i];
        result[A[i]]++;
    }

    for (int i = 1; i < N; ++i) {
        cout << result[i] << endl;
    }
    cout << "0" << endl;
}

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

using namespace std;

const int Nmax = 55;

typedef long long ll;
ll sum, need, total, j, a[Nmax];
int n, i;

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

    cin >> n;
    for(i=1; i<=n; ++i) cin >> a[i], sum += a[i];

    for(j = sum - n*(n-1); j<=sum; ++j)
    {
        total = 0;
        for(i=1; i<=n; ++i)
        {
            need = a[i] + j - (n-1);
            if(need < 0) continue;
            if(need % (n+1) == 0) need /= (n+1);
                else need = need / (n+1) + 1;
            total += need;
        }

        if(total <= j) break;
    }

    cout << j << '\n';

    return 0;
}


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


int main(){
  int A, B ;
  string S ;
  cin >> S ;
  for(int i=0;i<S.size();i++){
    S.at(i) = 'x' ;
  }  
  cout << S << endl ;
  return 0 ;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.range;
import std.array;
import std.string;
import std.conv;

void main(){
	auto n = readln.chomp.to!long;
	writeln(get_lucas(n));
}

long get_lucas(long n, long pre = 2, long after = 1){
	if(n == 1){
		return after;
	}else if(n == 0){
		return 2;
	}else{
		return get_lucas(n-1, after, pre+after);
	}
}

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

const int B1=123456789;
const int B2=999999937;
const int P=1000000007;

void gen_hash(const vector<string> &m,int H,int W,int R,int C,vector<vector<long long> >&hash){
	vector<vector<long long> > hash1(H);
	hash.resize(H);

	for(int h=0;h<H;h++){
		hash1[h].resize(W);
		hash[h].resize(W);

		long long c=0;
		long long Brev=1;
		for(int w=0;w<W;w++){
			c=(c*B1+m[h][w])%P;
			if(w<C)Brev=Brev*B1%P;else c=((c-m[h][w-C]*Brev)%P+P)%P;
			hash1[h][w]=c;
		}
	}
	for(int w=0;w<W;w++){
		long long c=0;
		long long Brev=1;
			for(int h=0;h<H;h++){
			c=(c*B2+hash1[h][w])%P;
			if(h<R)Brev=Brev*B2%P;else c=((c-hash1[h-R][w]*Brev)%P+P)%P;
			hash[h][w]=c;
		}
	}
}

int main(){
	int H,W,R,C;
	cin>>H>>W;
	vector<string>field(H);
	for(int i=0;i<H;i++)cin>>field[i];
	cin>>R>>C;
	vector<string>pattern(R);
	for(int i=0;i<H;i++)cin>>pattern[i];
	vector<vector<long long> >hash_field,hash_pattern;
	gen_hash(field,H,W,R,C,hash_field);
	gen_hash(pattern,R,C,R,C,hash_pattern);
	for(int h=R-1;h<H;h++)for(int w=C-1;w<W;w++){
		if(hash_field[h][w]==hash_pattern[R-1][C-1])printf("%d %d\n",h-R+1,w-C+1);
	}
}

Measured memory_bytes: 26612
//インクルード
#include <cstdlib>
#include <iostream>
#include <string>

//メイン関数
int main() {
	//初期値
	int x = 0;

	int answer;

	//入力の取得
	std::string temp;
	std::getline(std::cin, temp);
	int N = std::stoi(temp);

	std::string S;
	std::getline(std::cin, S);

	for(int i=0; i<N; ++i) {
		switch(S.c_str()[i]) {
		case 'I':
			++x;
			if(x > answer) {
				answer = x;
			}
			break;
		case 'D':
			--x;
			break;
		}
	}


	//答えの出力
	std::cout << answer << std::endl;

	//正常終了
	return EXIT_SUCCESS;
}


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

int main() {
	long long a, b, c, d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	long long answer = a * c;
	answer = max(answer, b * d);
	answer = max(answer, a * d);
	answer = max(answer, b * c);
	printf("%lld", answer);
}


Measured memory_bytes: 3792
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int n,m,map[55][55]={};
	char ch;
	scanf("%d%d",&n,&m);
	for (register int i=1;i<=n;++i) {
		for (register int j=1;j<=m;++j) {
			cin>>ch;
			if (ch=='#') {
				map[i][j]=1;
			}
		}
	}
	for (register int i=1;i<=n;++i) {
		for (register int j=1;j<=m;++j) {
			if (map[i][j]) {
				printf("#");
			}
			else {
				printf("%d",map[i-1][j-1]+map[i-1][j]+map[i-1][j+1]+map[i][j-1]+map[i][j+1]+map[i+1][j-1]+map[i+1][j]+map[i+1][j+1]);
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int A=sc.nextInt();
		int B=sc.nextInt();

		int ans=0;

		if(B%A==0) ans=A+B;
		else ans=B-A;

		System.out.println(ans);

		sc.close();

	}

}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;


//-------------------------------------------------------------------
#define P 1000000007
#define N_MAX 3000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
//-------------------------------------------------------------------
ll sigcomb(ll a, ll b){
  return pp((pp((a+2), comb(a+b+2, a+2)) - b - 1 + P)%P, inv[b+1]);
}
int main(int argc, char const *argv[]) {
  ll r1, c1, r2, c2;std::cin >> r1 >> c1 >> r2 >> c2;
  init();
  ll ans = 0;
  for(int i=1;i<=r2+1;i++) ans = (ans + comb(c2+i, i))%P;
  for(int i=1;i<=r1;i++) ans = (ans - comb(c2+i, i)+P+P)%P;
  for(int i=1;i<=c1;i++) ans = (ans - comb(r2+i, i)+P+P)%P;
  for(int i=1;i<=r1;i++) ans = (ans + comb(c1-1+i, i))%P;
  //std::cout << "editorial answer: " << ans << '\n';
  ans = (sigcomb(r2, c2)
    - sigcomb(r2, c1-1)
    - sigcomb(c2, r1-1)
    + sigcomb(c1-1, r1-1) + 2 * P)%P;
  std::cout << ans << '\n';
  //std::cout << "output: " << ans << '\n';
  return 0;
}


Measured memory_bytes: 71160
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
int pow5[14];
set<int>S;
int ans[60];
int n;
int solve(int a,int b,int c){
	if(a==n)return 1;
	if(S.count(b))return 0;
	S.insert(b);
	for(int i=0;i<13;i++){
		if(b%pow5[i+1]/pow5[i]&&c%(i+1)==0){
			ans[n-1-a]=i+1;
			if(solve(a+1,b-pow5[i],c-(i+1)))return 1;
		}
	}
	return 0;
}
int main(){
	pow5[0]=1;
	for(int i=1;i<14;i++)pow5[i]=pow5[i-1]*5;
	int a;
	while(scanf("%d",&a),a){
		n=a;
		int st=0;
		int sum=0;
		for(int i=0;i<a;i++){
			int p;scanf("%d",&p);
			sum+=p;
			p--;
			st+=pow5[p];
		}
		S.clear();
		int res=solve(0,st,sum);
		if(res){
			for(int i=0;i<a;i++){
				if(i)printf(" ");
				printf("%d",ans[i]);
			}
			printf("\n");
		}else printf("No\n");
	}
}

Measured memory_bytes: 1292