akhauriyash/Code-Regression huggingface dataset:
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}



int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;

      n=5;

      for(i=0; i<n; i++)
      {
          cin>>a;
          if(a==0)
          {
              sum=i+1;
          }
      }
      cout<<sum<<endl;



}



Measured memory_bytes: 3620
// buy a lot of 0s
// or simply return 0 ?
// nope, it's buy one 0
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

  string s, t;
  cin >> s >> t;
  int m = s.size();
  int n = t.size();
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    if(s[i] != t[i]) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3808
# -*- coding: utf-8 -*-

n = int(input())
s = list(input())

answer_sum = [0] * n
e_sum = [0] * (n+1)
w_sum = [0] * (n+1)

for i in range(n):
    w_sum[i+1] = (s[i] == 'W') + w_sum[i]
    e_sum[i+1] = (s[i] == 'E') + e_sum[i]

for i in range(n):
    answer_sum[i] = w_sum[i] + (e_sum[n] - e_sum[i+1])

print(min(answer_sum))

Measured memory_bytes: 41124
#include <iostream>
#include <algorithm>
using namespace std;
int s;
int m;
int main(){
    int n;cin >> n;
    for(int i=0;i<n;i++){
        int l;
        cin >> l;
        m = max(l,m);
        s += l;
    }
    cout<<((2*m<s)?"Yes":"No");
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>      // sqrt
#include <cstdlib>    // exit
#include <algorithm>  // min,max
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)
#define forv(i,m,n) for (int i=(m); i>=(n); i--)
#define forall(it,p) for (auto it = p.begin(); it != p.end(); ++it)
#define R 1000000007
#define BIG 100000007
#define DBG 1
typedef pair<int,int> pii;
typedef long long ll;

#define MAXN 1024*1024*8
int mintree[MAXN];
int maxtree[MAXN];
int a[200001];

int twopowercell(int n) {
  forr(i,0,30) {
    int m = int(pow(2.0,double(i)));
    if (m>=n) return m;
  }
  return -1;
}

//* * * *

void mininit(int *a, int n) {
  int nn = twopowercell(n);
  forr(i,0,2*nn-1) mintree[i] = BIG;
  forr(i,0,n-1) mintree[nn-1+i] = a[i];
  forv(i,nn-2,0) mintree[i] =
      min(mintree[2*i+1], mintree[2*i+2]);
}

int treemincore(int x, int y, int k, int l, int r) {
  if (r<=x || y<=l) return BIG;
  if (x<=l && r<=y) return mintree[k];
  int vl = treemincore(x,y,2*k+1,l,(l+r)/2);
  int vr = treemincore(x,y,2*k+2,(l+r)/2,r);
  return min(vl,vr);
}

int treemin(int x, int y, int n) {
  int nn = twopowercell(n);
  return treemincore(x,y,0,0,nn);
}

//* * * *

void maxinit(int *a, int n) {
  int nn = twopowercell(n);
  forr(i,0,2*nn-1) maxtree[i] = -BIG;
  forr(i,0,n-1) maxtree[nn-1+i] = a[i];
  forv(i,nn-2,0) maxtree[i] =
      max(maxtree[2*i+1], maxtree[2*i+2]);
}

int treemaxcore(int x, int y, int k, int l, int r) {
  if (r<=x || y<=l) return -BIG;
  if (x<=l && r<=y) return maxtree[k];
  int vl = treemaxcore(x,y,2*k+1,l,(l+r)/2);
  int vr = treemaxcore(x,y,2*k+2,(l+r)/2,r);
  return max(vl,vr);
}

int treemax(int x, int y, int n) {
  int nn = twopowercell(n);
  return treemaxcore(x,y,0,0,nn);
}

//* * * *
bool kstrks[200001];

int main() {
  int n,k;
  cin >> n >> k;
  forr(i,0,n-1)
    cin >> a[i];
  mininit(a,n);
  maxinit(a,n);
  int st = 1;
  int kstrkscnt = 0;
  forr(i,0,n-1) kstrks[i] = false;
  forr(i,0,n-1) {
    if (a[i]<a[i+1]) {
      st++;
      if (st>=k) {
        kstrkscnt++;
        kstrks[i+1] = true;
      }
    } else st = 1;
  }
#if 0
  cout << kstrkscnt << endl;
  forr(i,0,n-1)
    cout << kstrks[i] << ' ';
  cout << endl;
#endif
  int cnt = 0;
  forr(i,0,n-k-1) {
    if (!kstrks[i+k-1] && !kstrks[i+k] &&
        a[i]<treemin(i+1,i+k,n) &&
        treemax(i+1,i+k,n)<a[i+k]) cnt += 1;
  }

  if (kstrkscnt>0) kstrkscnt--;
  cout << n-k+1-kstrkscnt-cnt << endl;
}


Measured memory_bytes: 8448
# -*- coding: utf-8 -*-
import numpy as np

x = int(input())
flg = 0

for i in range(1, x+1):
    if x % i != 0:
        continue
    else:
        for a in range(x):
            b = a - i
            if a**5 - b**5 == x:
                ans_a = a
                ans_b = b
                flg = 1
                break
            elif a > i and a**5 - b**5 > x:
                flg = -1
                break
        if flg == 1:
            break
        elif flg == -1:
            flg = 0
            continue

print(ans_a, ans_b)


Measured memory_bytes: 27136
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math


def main():
  a, b, x = map(int, input().split())
  x = x / a
  low = 0
  high = 90

  for _ in range(100):
    r = (low + high) * 0.5
    rb = math.tan(r * math.pi / 180) * a
    ra = math.tan((90 - r) * math.pi / 180) * b

    if rb < b:
      y = a * b - a * rb * 0.5
    else:
      y = ra * b * 0.5

    if y > x:
      low = r
    else:
      high = r

  print((low + high) * 0.5)


if __name__ == '__main__':
  main()


Measured memory_bytes: 38896
///supercalifragilisticexpialidocious.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
string str;
char ch[4] = {'N' , 'S' , 'E' , 'W'};
bool bo[4];
int32_t main()
{
	cin >> str;
    for(int i = 0 ; i < sz(str) ; i ++)
        for(int j = 0 ; j < 4 ; j ++)
            if(str[i] == ch[j])
                bo[j] = true;
    if((bo[0] ^ bo[1]) || (bo[2] ^ bo[3]))
        return cout << "No" << endl , 0;
    return cout << "Yes" << endl , 0;
}


Measured memory_bytes: 256
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math
import functools

n = int(input())
cnt = 0
for i in range(n):
    l,r = map(int,input().split())
    a = r-l + 1
    cnt += a
print(cnt)

Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
  
typedef long long ll;
int N, M;//街数、道路数
bool adj[1010][1010];
bool visited[1010];
int color[1010];
int counter[2];

bool dfs(int s, int c){
    if(visited[s]) return color[s]==c;
    
    visited[s]=true;
    color[s]=c;
    if(c==1) counter[c]++;
    for(int next=1; next<=N; next++){
        if(adj[s][next] && ! dfs(next, -c)){
            return false;
        }
    }
    return true;
}

int main(void){
    while(cin>>N>>M){
        if(N+M==0) break;
        for(int i=1; i<=N; i++){
            fill(adj[i]+1, adj[i]+(N+1), false);
        }
        
        for(int i=0; i<M; i++){
            int u, v;
            cin>>u>>v;
            adj[u][v]=adj[v][u]=true;
        }
        
        set<int> s;
        fill(visited+1, visited+(N+1), false);
        fill(color+1, color+(N+1), 0);
        fill(counter+0, counter+2, 0);
        
        if(dfs(1, 1)){
            if(counter[1]%2==0){
                s.insert(counter[1]/2);
            }
            if((N-counter[1])%2==0){
                s.insert((N-counter[1])/2);
            }
        }
        
        cout << s.size() << "\n";
        for(auto x: s){
            cout << x << "\n";
        }
        
        
    }
    
    return 0;
}


Measured memory_bytes: 4048
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<string>
#include<sstream>
using namespace std;
//char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int main(){
	//while(1){
		int w,a,b;cin>>w>>a>>b;
		if(abs(b-a)<=w){cout<<0<<endl;}
		else cout<<abs(b-a)-w<<endl;
		
	}//mainwhile

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

const int maxn = (int)(2e5) + 5;
char s[maxn];

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1), j = 0;
    long long ret = 0;
    for (int i = 1; i <= n; ++i) {
        if (s[i] == 'B') ++j;
        else ret += j;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
  private static Scanner sc;

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


  private void solve() {
    String S = sc.next();
    boolean flg = false;
    if (S.startsWith("A")) {
      String sub = S.substring(2, S.length() - 1);
      int cnt = 0;
      for (int i = 0; i < sub.length(); i++) {
        char c = sub.charAt(i);
        if (c == 'C') cnt++;
      }

      if (cnt == 1) {
        int ucnt = 0;
        for (int i = 0; i < S.length(); i++) {
          char c = S.charAt(i);
          if (Character.isUpperCase(c)) {
            ucnt++;
          }
        }

        if (ucnt == 2) {
          flg = true;
        }
      }
    }

    if (flg) {
      System.out.println("AC");
    } else {
      System.out.println("WA");
    }
  }
}



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

int main(){
  int n;
  int h[100001];

  cin >> n;

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

  int cost[100001];
  cost[0] = 0;
  cost[1] = abs(h[0]-h[1]);
  for(int i = 2; i <= n; i++){
    cost[i] = min(abs(h[i]-h[i-2])+cost[i-2],abs(h[i]-h[i-1])+cost[i-1]);
  }

  cout << cost[n-1] << '\n';

  return 0;
}


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

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

Measured memory_bytes: 3072
#include<stdio.h>

int main(void) {
  int n, k, x = 1;
  scanf("%d %d", &n, &k);

  for (int i = 0; i < n; i++) {
    if (x * 2 < x + k) x *= 2;
    else x += k;
  }

  printf("%d", x);

  return 0;
}


Measured memory_bytes: 128
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define pb push_back
#define Mp make_pair
#define pll pair<ll, ll>
#define F first
#define S second

ll a, b, v, w, t;

int main(){
	fast_io;
	
	cin >> a >> v >> b >> w >> t;
	cout << ((v - w) * t >= abs(a - b) ? "YES" : "NO");
	
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll n,ans=0;
int main(){
	cin>>n;
	ll now=2;
	if (n%2==1){
		puts("0");return 0;
	}
	for (;;){
		now*=5;
		ans+=n/now;
		if (now>1e18/5) break;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int N,K,Q;
vector<LL> A;

int main(void){
    GI(N);GI(K);GI(Q);
    A = vector<LL>(N);
    REP(i,N)
        GLL(A[i]);
    LL ans = LLMAX;
    REP(i,N){
        int j = 0;
        vector<LL> gettable;
        vector<LL> vi;
        // printf("A[i] = %lld\n",A[i]);
        while(j<N){
            if(A[j] < A[i]){
                if(vi.size()!=0){
                    // REP(k,SZ(vi))
                        // printf("vi[%d] = %d\n",k,vi[k]);
                    sort(ALL(vi));
                    REP(k,SZ(vi)-K+1)
                        gettable.PB(vi[k]);
                    vi = vector<LL>(0);
                }
            }else{
                vi.PB(A[j]);
            }
            j++;
        }
        sort(ALL(vi));
        REP(k,SZ(vi)-K+1)
            gettable.PB(vi[k]);

        // printf("gettable.size() = %d\n",gettable.size());
        // for(j=0;j<SZ(gettable);j++)
            // printf("%d\n",gettable[j]);
        sort(ALL(gettable));
        if(Q<=SZ(gettable))
            ans = min(ans, gettable[Q-1] - gettable[0]);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

int main()
{ 
    LL x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<P> q;
    vector<LL> C;
    for(int i=0;i<a;i++){
        LL X;
        cin>>X;
        q.push_back(P(X,0));
    }
    for(int i=0;i<b;i++){
        LL X;
        cin>>X;
        q.push_back(P(X,1));
    }
    for(int i=0;i<c;i++){
        LL X;
        cin>>X;
        C.push_back(X);
    }
    
    sort(q.begin(),q.end());
    //reverse(q.begin(),q.end());
    sort(C.begin(),C.end());
    //reverse(C.begin(),C.end());
    vector<LL> ans;
    LL cnta=0;
    LL cntb=0;
    LL cntc=0;
    while(cnta+cntb+cntc<x+y){
        P X=q.back();
        LL Y;
        if(!C.empty()){Y=C.back();}
        else{Y=-1;}
        if(X.first>=Y){
            if(X.second==0&&cnta<x){cnta++;ans.push_back(X.first);}
            else if(X.second==1&&cntb<y){cntb++;ans.push_back(X.first);}
            q.pop_back();
        }
        else{
            cntc++;
            ans.push_back(Y);
            C.pop_back();
        }
    }
    LL Ans=0;
    for(int i=0; i<ans.size();i++){Ans=Ans+ans[i];/*cout<<ans[i]<<'x'<<endl;*/}
    cout<<Ans<<endl;
    return 0;
}

Measured memory_bytes: 8556
N = int(input())
A = list(map(int, input().split()))
# print(N, A)

ans = list(set(A))
l = len(ans)
if l > 3:
    print('No')
    exit()

if l == 1:
    if ans[0] == 0:
        print('Yes')
    else:
        print('No')
    exit()

if l == 2:
    a0 = ans[0]
    a1 = ans[1]
    num_a0 = A.count(ans[0])
    num_a1 = A.count(ans[1])
    if a0 != 0 and a1 != 0:
        print('No')
        exit()
    num_0 = num_a0 if a0 == 0 else num_a1
    num_n0 = num_a1 if a0 == 0 else num_a0
    if num_0 * 2 == num_n0:
        print('Yes')
    else:
        print('No')
    exit()

a0 = ans[0]
a1 = ans[1]
a2 = ans[2]

if a0 ^ a1 != a2:
    print('No')
    exit()

num_a0 = A.count(ans[0])
num_a1 = A.count(ans[1])
num_a2 = A.count(ans[2])

if num_a0 != num_a1 or num_a0 != num_a2:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 60784
#!/usr/bin/env python3
import sys

def solve(N: int, K: int, R: int, S: int, P: int, T: str):
    scoreDict = {}
    scoreDict["r"]=P
    scoreDict["s"]=R
    scoreDict["p"]=S
    def toScore(c):
        return scoreDict[c]
    sum = 0
    record = []
    for i in range(N):
        if i-K<0 or record[i-K]!=T[i]:
            sum += toScore(T[i])
            # print(sum)
            record.append(T[i])
        else:
            record.append("*")
    # print(record)
    print(sum)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    T = next(tokens)  # type: str
    solve(N, K, R, S, P, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4248
//bismillah
//author anaksoleh
//creadit errichto
//26 Dec 2019
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll INF = 1e18L + 5;

void min_self(ll *a,ll b){
    *a = min(*a,b);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,W;
    cin >> N >> W;
    vector<int> weight(N) , val(N);
    for(int i = 0 ; i < N ; i++){
        cin >> weight[i] >> val[i];
    }
    int sum_val = 0;
    for(auto x : val){
        sum_val += x;
    }
    vector<ll> dp(sum_val+1,INF);
    dp[0] = 0;
    for(int item = 0 ; item < N ; item++){
        for(int val_already = sum_val - val[item] ; val_already >= 0 ; val_already--){
            min_self(&dp[val_already+val[item]],dp[val_already] + weight[item]);
        }
    }
    ll ans = 0;
    for(int i = 0 ; i < sum_val + 1 ; i++){
        if(dp[i] <= W){
            ans = max(ans,(ll)i);
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10));
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cin >> c.at(i).at(j);
        }
    }
    vector<vector<int>> A(H,vector<int>(W));
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> A.at(i).at(j);
        }
    }
    
    for(int i = 0; i < 10; i++) { //通過点
        for(int j = 0; j < 10; j++) { //始点
            for(int k = 0; k < 10; k++) { //終点
                c.at(j).at(k) = min(c.at(j).at(k), c.at(j).at(i) + c.at(i).at(k));
            }
        }
    }
    
    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            int a = A.at(i).at(j);
            if(a==-1) continue;
            ans += c.at(a).at(1);
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 384
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val n, q = sc.nextInt
    val ps = scala.collection.mutable.Queue.fill(n)((sc.next, sc.nextInt))

    var t = 0
    while(ps.nonEmpty) {
      val (name, time) = ps.dequeue()
      if(time <= q) {
        println(s"${name} ${t + time}")
        t += time
      } else {
        ps.enqueue((name, time - q))
        t += q
      }
    }
  }
}



Measured memory_bytes: 155620
a=[]
b=[]
for i in range(5):
    a.append(int(input()))
ans=sum(a)
for i in range(5):
    losstime =a[i]%10
    if losstime!=0:
        b.append(10-losstime)
if len(b)==0:
    print(sum(a))
else :
    print(sum(a)+sum(b)-max(b))


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Atcoder
{
    class aaaa
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);int b = int.Parse(input[1]);

            if ((a + b) % 2 == 0){
                Console.WriteLine((a+b) / 2 );
            }else{
                Console.WriteLine((a+b)/2 +1);
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 100000000

using namespace std;

int main() {
   int n;
   cin >> n;
   cout << (1+n)*n/2 << endl;
}

Measured memory_bytes: 256
s = input()
K = int(input())

n = len(s)

dp = [[[0] * 2 for _ in range(4)] for _ in range(105)]
dp[0][0][0] = 1


for i in range(n):
    for j in range(4):
        for k in range(2):
            nd = int(s[i])
            for d in range(10):
                ni = i + 1
                nj = j
                nk = k
                if d != 0: nj += 1
                if nj > K: continue
                if k == 0:
                    if d > nd: continue
                    if d < nd: nk = 1
                dp[ni][nj][nk] += dp[i][j][k]

ans = dp[n][K][0] + dp[n][K][1]
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=998244353;
const int N=3005;
int dp[N][N];
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	dp[a][b]=1;
	for(int i=a;i<=c;i++){
		for(int j=b;j<=d;j++){
			if(i==a&&j==b)
			continue;
			dp[i][j]=(1ll*dp[i-1][j]*j+1ll*dp[i][j-1]*i-(1ll*dp[i-1][j-1]*(i-1)*(j-1)%mod)+mod)%mod;
		}
	}
	printf("%d",dp[c][d]);
}


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

#define REP(i,n) for(int i = 0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long, long> pl;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c; cin >> a >> b >> c;
    if(a==b && b == c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
 
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))
typedef long long ll;
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, l;
  cin >> n >> l;
  int res = n * (l - 1) + (n * (n + 1) / 2);

  if(l > 0){
    res -= l;
  }else if((l < 0)&&((l + n) <= 0)){
    res -= l + n - 1;
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

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











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

int main() {
    int m,f,r;
    while (true) {
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1){
            break;
        }else if(m==-1 || f==-1){
            cout << 'F' << endl;
        }else if (m+f >= 80){
            cout << 'A' << endl;
        }else if(m+f >= 65){
            cout << 'B' << endl;
        }else if(m+f >= 50){
            cout << 'C' << endl;
        }else if(m+f >= 30){
            if(r >= 50){
                cout << 'C' << endl;
            }else{
                cout << 'D' << endl;
            }
        }else{
            cout << 'F' << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3084
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

S = str(input())

if "RRR" in S:
    ans = 3
elif "RR" in S:
    ans = 2
elif "R" in S:
    ans = 1
else:
    ans = 0
print(ans)


Measured memory_bytes: 10924
S = input()
odd = {'R', 'U', 'D'}
even = {'L', 'U', 'D'}
isEasy = "Yes"
for i in range(0,len(S)):
  isEven = (i + 1) % 2 == 0
  if (isEven and S[i] not in even) or not isEven and S[i] not in odd:
    isEasy = "No"
print(isEasy)

Measured memory_bytes: 3060
#include <stdio.h>
int main()
{
	int N, K, X, Y;
	scanf("%d %d %d %d", &N, &K, &X, &Y);
	if(N<=K) 
	{printf("%d\n", N*X);}
	else 
	{printf("%d\n", K*X + N*Y - K*Y);}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, P> PP;
struct edge {int to, cost;};
int a[114514], b[114514];
int imos[114514];
vector<P>Q;
signed main() {
	int n, m; cin >> n >> m;
	rep(i, m)cin >> a[i] >> b[i];
	rep(i, m) {
		Q.push_back(P(a[i], b[i]));
	}
	sort(Q.begin(), Q.end());
	Q.push_back(P(n + 1, n + 1));
	int s = Q[0].first, g = Q[0].second;
	int ans = 0;
	rep(i, Q.size()) {
		if (s <= Q[i].first&&Q[i].second <= g) {
			s = Q[i].first;
			g = Q[i].second;
		}
		else{
			if (max(s, Q[i].first) < min(g, Q[i].second)) {
				s = max(s, Q[i].first);
				g = min(g, Q[i].second);
			}
			else {
				ans++;
				s = Q[i].first;
				g = Q[i].second;
			}
		
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3956
n=int(input())
A=list(map(int,input().split()))

ans=set()
for i in range(n-1,-1,-1):
  for j in range(i+1,n+1,i+1):
    if j in ans:
      A[i]+=1
  if A[i]%2:
    ans.add(i+1)
print(len(ans))
print(*ans)


Measured memory_bytes: 15756
#include<iostream>
#include<cstdio>
using namespace std;
#define MOD 1000000007
#define MAX 305
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,m,ans,a[MAX<<1];
int cnt1,cnt2,f[MAX<<1][MAX][MAX];
int S[MAX<<1];
bool vis[MAX<<1],book[MAX<<1];
int main()
{
	n=read();
	for(int i=1;i<=n+n;++i)a[i]=read();
	for(int i=1;i<=n+n;i+=2)
		if(a[i]==-1&&a[i+1]==-1)++cnt1;
		else if(a[i]>0&&a[i+1]>0)vis[a[i]]=vis[a[i+1]]=true;
		else ++cnt2,book[(~a[i])?a[i]:a[i+1]]=true;
	for(int i=n+n;i;--i)if(!vis[i])S[++m]=i;
	f[0][0][0]=1;
	for(int i=1;i<=m;++i)
		for(int j=0;j<=cnt1+cnt2;++j)
			for(int k=0;k<=cnt2;++k)
			{
				if(!f[i-1][j][k])continue;
				if(!book[S[i]])
				{
					add(f[i][j+1][k],f[i-1][j][k]);
					if(j)add(f[i][j-1][k],f[i-1][j][k]);
					if(k)add(f[i][j][k-1],1ll*k*f[i-1][j][k]%MOD);
				}
				else
				{
					add(f[i][j][k+1],f[i-1][j][k]);
					if(j)add(f[i][j-1][k],f[i-1][j][k]);
				}
			}
	ans=f[m][0][0];for(int i=1;i<=cnt1;++i)ans=1ll*ans*i%MOD;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 166472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<int, int>;



int main() {
    int n,m,x; cin >> n >> m >> x;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    vector<int> masu(n+1,0);
    rep(i, m) masu[a[i]]++;


    int ans1 = 0;
    FOR(i, x, n+1) {
        ans1 += masu[i];
    }

    int ans2 = 0;
    for(int i=x; i >= 0; i--) {
        ans2 += masu[i];
    }

    cout << min(ans1, ans2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;
deque<int> dq;

int main()
{
	int i, j, k;
	scanf("%d", &N);
	int x;
	for (i = 1; i <= N; ++i) {
		scanf("%d", &x);
		if (i % 2 == 1) dq.push_back(x);
		else dq.push_front(x);
	}
	vector<int> vt;
	while (!dq.empty()) {
		vt.push_back(dq.front());
		dq.pop_front();
	}
	if (N % 2 == 1) reverse(vt.begin(), vt.end());
	for (i = 0; i < vt.size(); ++i) printf("%d ", vt[i]);

}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
int n,i,x,ok=1;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x % 3 != 0 && x % 5 != 0 && x % 2 == 0)
            ok=0;
    }
    if(ok==1)
        cout<<"APPROVED";
    else cout<<"DENIED";
    return 0;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll q,h,s,d;
ll n;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans=LINF;
    cin >> q>>h>>s>>d;
    chmin(ans,q*4);
    chmin(ans, h * 2);
    chmin(ans, s);
    cin >> n;
    ll anss=n*ans;
    if(n%2)
    chmin(anss,ans+d*(n/2));
    else{
        chmin(anss, d * (n / 2));
    }
    cout << anss << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vector<vector<int>> dp(n, vector<int>(3));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
		dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
		dp[i][2] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int now = 1;
  int ans = 0;
  rep(i,n) {
    if (now == a[i]) {
      now++;
      continue;
    }
    else ans++;
  }
  if (now == 1) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4044
#include<iostream>
using namespace std;
int main()
{
	int A,B,num=0;
	cin>>A>>B;
	if(A>0&&B>A) cout<<"Positive";
	if(A<0&&B>0) cout<<"Zero";
	if(B<0&&A<B) 
	{
		for(int i=A;i<=B;i++)
		{
			num++;
		}
		if(num%2==0) cout<<"Positive";
		else cout<<"Negative";
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

A,B,C,D = I()
if A+B > C+D:
    print('Left')
elif A+B == C+D:
    print('Balanced')
else:
    print('Right')

Measured memory_bytes: 10072
#include <stdio.h>
int n,i,j,a[100],b,c=0,minj;
int main () {

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



  for (i=0;i<n;i++){
    minj = i;
    for (j=i;j<n;j++){
      if( a[j] < a[minj]){
	minj = j;
      }
    }
    if(a[i]!=a[minj]){
    b=a[i];
    a[i]=a[minj];
    a[minj]=b;
    c++;
  }
  }
     

 
  for (i=0;i<n;i++){
     printf("%d",a[i]);
     if (i<n-1)
       printf(" ");
  }
  printf("\n%d\n",c);
  return 0;
}



Measured memory_bytes: 2108
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

bool compare_by_second(pair<int, ull> a, pair<int, ull> b) {
    return a.second > b.second;
}

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

    vector<ull> A(N);
    vector<pair<int, ull>> BC(M);    
    for(int i=0; i<N; i++)
        cin >> A[i];
    for(int i=0; i<M; i++) {
        ull b, c;
        cin >> b >> c;
        BC[i] = pair<int, ull>(b, c);
    }
    sort(A.begin(), A.end());
    sort(BC.begin(), BC.end(), compare_by_second);

    bool exit = false;
    int i = 0;
    for(int j=0; j<M && (!exit); j++) {
        int B = BC[j].first;
        ull C = BC[j].second;
        for(int k=0; k<B && (!exit); k++) {
            if(A[i] >= C)
                exit = true;
            else
                A[i] = C;
            i++;
        }
    }

    ull sum = 0;
    for(int i=0; i<N; i++)
        sum += A[i];
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 2560
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define forn(i, s, f) for (int i = s; i < f; i++)
#define ll long long
#define pii pair <int, int>
#define fs first
#define sc second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    forn (i, 0, n)
        cin >> a[i], a[i]--;
    vector <int> ans;
    for (int i = n - 1; i >= 0; i--) {
        for  (int j = min((int)a.size(), i); j >= 0; j--) {
            if (a[j] == j) {
                a.erase(a.begin() + j);
                ans.pb(j);
                break;
            }
        }
    }
    if (ans.size() < n)
        return cout << -1, 0;
    while (!ans.empty()) {
        cout << ans.back() + 1 << "\n";
        ans.pop_back();
    }
    return 0;
}


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

#define BUF_SIZE 1024
#define EOF -1


using namespace std;

class Stack
{
private:
	int top;
	int maxSize;
	int* stackArray;
public:
	Stack(int size);
	void Initialize(int size);
	void Push(int x);
	int Pop();
	bool IsEmpty();
	bool IsFull();
	~Stack();
};

Stack::Stack(int size)
{
	Initialize(size);
}

void Stack::Initialize(int size) {
	top = 0;
	maxSize = size;
	stackArray = new int[size];
}

void Stack::Push(int x) {
	if (IsFull()) {
		std::cout << "Stack is Full.\n";
		return;
	}
	stackArray[++top] = x;
}

int Stack::Pop() {
	if (IsEmpty()) {
		std::cout << "Stack is Empty.\n";
		return -9999999;
	}
	top--;
	return stackArray[top + 1];
}

bool Stack::IsEmpty() {
	return !(top > 0);
}

bool Stack::IsFull() {
	return !(top < maxSize);
}

Stack::~Stack()
{
	delete[] stackArray;
}

int main() {
	int a, b, N = 1000;
	char inputString[BUF_SIZE];


	Stack stack = Stack(N);

	while (scanf("%s", inputString, BUF_SIZE) != EOF) {
		if (*inputString == '+') {
			stack.Push( stack.Pop() + stack.Pop() );
		}
		else if (*inputString == '-') {
			b = stack.Pop();
			a = stack.Pop();
			stack.Push(a - b);
		}
		else if (*inputString == '*') {
			stack.Push(stack.Pop() * stack.Pop());
		}
		else {
                        int number = atoi(inputString);
			stack.Push( number );
		}
	}

	printf("%d\n", stack.Pop());

	return 0;
}



Measured memory_bytes: 3240
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
#include<map>
using namespace std;


int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int res = min(a,b);
	res += min(c,d);
	cout << res << endl;
	return 0;
}



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

void turnccw(int n, vector<char> &a){
	for(int i=0; i<2*n; i++){
		swap(a[0], a[1]);
		swap(a[1], a[2]);
		swap(a[2], a[5]);
		swap(a[5], a[8]);
		swap(a[8], a[7]);
		swap(a[7], a[6]);
		swap(a[6], a[3]);
	}
}
void moveleft(vector<vector<char> > &a){
	swap(a[4], a[1]);
	swap(a[1], a[5]);
	swap(a[5], a[3]);
	turnccw(1, a[0]);
	turnccw(3, a[2]);
	turnccw(1, a[4]);
	turnccw(1, a[1]);
	turnccw(1, a[5]);
	turnccw(1, a[3]);
}
void moveright(vector<vector<char> > &a){
	for(int i=0; i<3; i++) moveleft(a);
}
void movefront(vector<vector<char> > &a){
	swap(a[0], a[4]);
	swap(a[4], a[2]);
	swap(a[2], a[5]);
	turnccw(1, a[1]);
	turnccw(3, a[3]);
	turnccw(2, a[4]);
	turnccw(2, a[2]);
}
void moveback(vector<vector<char> > &a){
	for(int i=0; i<3; i++) movefront(a);
}

vector<vector<char> > move(int dir, vector<vector<char> > &a){
	vector<vector<char> > ret = a;
	if(dir==0) moveleft(ret);
	if(dir==1) moveright(ret);
	if(dir==2) movefront(ret);
	if(dir==3) moveback(ret);
	return ret;
}

int solve(int step, vector<vector<char> > a){
	if((a[0][6]=='*' || a[0][7]=='*' || a[0][8]=='*') && (a[2][6]=='*' || a[2][7]=='*' || a[2][8]=='*')){
		return step;
	}
	if(step == 2) return 3;
	int ret = 3;
	for(int i=0; i<4; i++){
		ret = min(ret, solve(step+1, move(i, a)));
	}
	return ret;
}

int main(){
	vector<vector<char> > a(6, vector<char>(9));
	while(1){
		cin >> a[0][0];
		if(a[0][0]=='#') break;
		
		for(int i=0; i<6; i++){
			for(int j=(i==0)?1:0; j<9; j++){
				cin >> a[i][j];
			}
		}
		cout << solve(0, a) << endl;
	}
	return 0;
}



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

unordered_map<int, int>mp;
int n, m, k;
void solve(int p, int s) {
	if (p == n) {
		mp[max(1, s - k)]++; return;
	}
	for (int i = 1; i <= m; i++)solve(p + 1, s + i);
}
int main() {
	while (scanf("%d%d%d", &n, &m, &k), n) {
		mp.clear(); solve(0, 0);
		int sum = 0;
		for (auto p : mp)sum += p.second;
		double ans = 0;
		for (auto p : mp)ans += p.first*p.second / (double)sum;
		printf("%.10lf\n", ans);
	}
}

Measured memory_bytes: 3404
tn=[map(int,input().split()) for _ in range(4)]
t,n=[list(i) for i in zip(*tn)]

l=[]
for x in range(4):
    if t[x]==1:
        l.append(6000*n[x])
    elif t[x]==2:
        l.append(4000*n[x])
    elif t[x]==3:
        l.append(3000*n[x])
    else:
        l.append(2000*n[x])
print(l[0])
print(l[1])
print(l[2])
print(l[3])


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

using namespace std;

const int N = 100005;

int n, m, k;
int p[N], sz[N];
int f(int u) {
	return u == p[u] ? u : p[u] = f(p[u]);
}
void join(int a, int b) {
	a = f(a), b = f(b);
	if(a == b) return;
	sz[a] += sz[b];
	p[b] = a;
}

vector<int> fr[N], bl[N];

int main() {
	scanf("%d %d %d", &n, &m, &k);
	
	for(int i = 1; i <= n; i++) p[i] = i, sz[i] = 1;

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

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

	for(int i = 1; i <= n; i++) {
		int ans = sz[ f(i) ] - 1;
		for(int j : fr[i]) ans--;
		for(int j : bl[i]) if(f(j) == f(i)) ans--;

		printf("%d%c", ans, " \n"[i == n]);
	}
}


Measured memory_bytes: 13176
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int a, b, c;
int main() {
    while (cin >> a >> b >> c) {
        cout << min(c, b/a) << endl;
    }
}















Measured memory_bytes: 256
A = []
while True:
    try:
        a = list(map(int, input().split(',')))
    except:
        break
    A.append(a)

Sum = 0
N = 0
for i in range(len(A)):
    Sum += A[i][0] * A[i][1]
    N += A[i][1]
N_average = N / len(A)
N_average_int = N // len(A)

if 0 <= N_average - N_average_int <0.5:
    N_average = int(N_average_int)
else:
    N_average = int(N_average_int) + 1

print(Sum)
print(N_average)


Measured memory_bytes: 5620
using System;

namespace newEx
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] l = Console.ReadLine().Split(' ');
            int p = int.Parse(l[0]);
            int q = int.Parse(l[1]);
            int r = int.Parse(l[2]);

            //string l = Console.ReadLine();
            //int r = int.Parse(l);

            Console.WriteLine(Volume(p,q,r));
        }

        static int Volume(int A, int B, int C)//修正200630
        {
            //容器２のあまり
            if (C > A - B)  //修正200630
            {
                return (C - (A - B));
            }
            else
            //if (A < B)  //修正200630
            {
                return 0;
            }                                    //修正200630
        }
    }
}


Measured memory_bytes: 27540
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    REP(i, 0, n) {
        REP(j, 0, n) {
            int remain = n - i * r - j * g;
            if(remain < 0) continue;
            if(remain % b == 0) {
                ans++;
                //cout << i << " " << j << " " << remain / b << endl;
            }
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
module Main where
import           Data.List
main :: IO ()
main = do
    [x1, y1, x2, y2] <- (map read . words) <$> getLine :: IO [Int]
    putStrLn $ (intercalate " " . map show)
        [x2 - y2 + y1, y2 + x2 - x1, x1 - y2 + y1, y1 + x2 - x1]
    return ()


Measured memory_bytes: 508
ans :: [[Int]] -> Int
ans [[n,c],d] =
  let s = sum d
      a = s `div` (n+1)
      b = s `mod` (n+1)
  in
    if b /= 0
    then (a + 1)
    else a

main = do
  l <- getContents
  let i = map (map read) $ map words $ lines l :: [[Int]]
      o = ans i
  print o
      



Measured memory_bytes: 4108
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int n;
    cin >> n;
    int a[n+1], b[n];
    for(int i = 0; i < n+1; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += min(a[i], b[i]);
        if(i == n-1){
            sum += min(max(b[i] - a[i], (int)0), a[n]);
            break;
        }
        b[i] -= min(a[i], b[i]);
        sum += min(a[i+1], b[i]);
        a[i+1] -= min(a[i+1], b[i]);
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
x = []
x = input()

y = 0

for i in range(len(x)):
    if x[0:2] != "hi":
        break
    if x[i] != 'h' and x[i] != 'i':
        y = 0
        break
    if len(x) % 2 != 0:
        break
    if x[i:i + 2] == "hi":
        y = 1
    else:
        pass

if y == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060