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

public class Main {


    public static InputReader in = new InputReader( System.in );
    public static PrintWriter out = new PrintWriter( System.out );
    public static void main( String[] atgs ) {

        new Main().solve();
        out.close();
        System.exit(0);
    }


    private void solve() {
        int s = in.nextInt();
        int w = in.nextInt();
        if(s<=w)
            System.out.print("unsafe");
        else
            System.out.print("safe");
    }

    //Solution ends
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

        public String next() {
            while ( tokenizer == null || !tokenizer.hasMoreTokens( ) ) {
                try {
                    tokenizer = new StringTokenizer( reader.readLine( ) );
                } catch ( IOException e ) {
                    throw new RuntimeException( e );
                }
            }
            return tokenizer.nextToken( );
        }

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

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

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

        public String nextLine() throws IOException {
            return reader.readLine( );
        }
    }


}

Measured memory_bytes: 32824
n=gets.chomp.to_i
ary=Array.new(n)
k=0
for i in 0..n-1
	ary[i]=gets.chomp.to_i
	root=Math.sqrt(ary[i]).to_i
	j=3
			if ary[i]==2 || ary[i]==3 || ary[i]==5 || ary[i]==7
				k += 1
#				print(k,"?´???°1\n")
			elsif ary[i]<2 || ary[i]%2==0
#				puts "?´???°??§?????????1"
			else
				while j <= root
#					print(j,"j??????\n")
					if ary[i]%j==0
						break # puts "?´???°??§?????????2"
					elsif j+2>root &&  ary[i]%j!=0
						k += 1
						break  #print("j=",j," k=",k," ?´???°2\n")
					end
					j+=2
				end
			end
end
puts k

Measured memory_bytes: 8624
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define debug(n) cout<<"# "<<#n<<": "<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const double EPS=1e-10;

// (a b)(x) (c)
// (d e)(y) (f)
int main()
{
	for(double a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;){
		double x=(c*e-b*f)/(a*e-b*d);
		double y=(a*f-c*d)/(a*e-b*d);
		printf("%.3f %.3f\n",x+EPS,y+EPS);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  int n,m,t;
  int sx,sy;
  cin>>n>>m>>t>>sx>>sy;
  string s1,s2;
  cin>>s1>>s2;
  bool flag = 0;
  int x = sx,y = sy;
  for(int i=0;i<t;i++){
    if(s1[i]=='L') {
      y--;
      if (y <= 0) {
        flag = 1;
        break;
      }
    }
    if(s2[i]=='R'&&y+1<=m)y++;
  }
  if(!flag){
    x = sx,y=sy;
    for(int i=0;i<t;i++){
      if(s1[i]=='R') {
        y++;
        //bug2(y,m)
        if (y > m) {
          flag = 1;
          break;
        }
      }
      if(s2[i]=='L'&&y-1>0)y--;
    }
  }
  if(!flag){
    x = sx,y=sy;
    for(int i=0;i<t;i++){
      if(s1[i]=='U') {
        x--;
        if (x <=0) {
          flag = 1;
          break;
        }
      }
      if(s2[i]=='D'&&x+1<=n)x++;
    }
  }
  if(!flag){
    x = sx,y=sy;
    for(int i=0;i<t;i++){
      if(s1[i]=='D') {
        x++;
        if (x>n) {
          flag = 1;
          break;
        }
      }
      if(s2[i]=='U'&&x-1>0)x--;
    }
  }
  if(flag)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 776
L = int(input().strip())

bL = bin(L)[2:]
N = len(bL)
M = 0
result = []
for i in range(N-1):
    result.append((N-i-1, N-i, pow(2, i)))
    result.append((N-i-1, N-i, 0))
    M += 2

max_n = pow(2, N-1) - 1
for i, j in enumerate(bL[1:][::-1]):
    if j == "1":
        result.append((1, N-i, max_n + 1))
        max_n += pow(2, i)
        M += 1

print(N, M)
for item in result:
    print(item[0], item[1], item[2])


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

int maxi(int a, int b , int c)
{
	return max(a,max(b,c));
}

int main()
{
	int n ;  cin >> n;
	int a[n+1],b[n+1],c[n+1],g = 0;
	int i = 1;
	while(i<=n)
	{
		cin >> a[i] >> b[i] >> c[i] ;
		i ++ ;
	}
	
	
	
	int da[n+1] = {0} ,db[n+1]= {0},dc[n+1] = {0};
	da[1] = a[1];
	db[1] = b[1];
	dc[1] = c[1];
	

	i = 2;
	while(i<=n )
	{
		da[i] = a[i] +max(db[i-1],dc[i-1]);
		db[i] = b[i] +max(da[i-1],dc[i-1]);
		dc[i] = c[i] +max(db[i-1],da[i-1]);
		i++;
	}
	cout<< maxi(da[n],db[n],dc[n]) ;
}

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



const int N = 1000000;
int lp[N+1];
vector<int> pr;

int used[N+1];

void sieve() {
    for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}

vector< int >primeFactors(int x) {
    vector< int >rt;
    while (x > 1) {
        int d = lp[x];
        rt.push_back(d);
        x /= d;
    }
    rt.erase(unique(rt.begin(), rt.end()), rt.end());
    return rt;
}

int A[N+1];

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

    sieve();

    int n;
    cin >> n;

    int allGCD = 0;
    bool pairWise = true;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
        vector< int >factors = primeFactors(A[i]);
        for (int d : factors) {
            if (used[d]) {
                pairWise = false;
            }
            used[d] = 1;
        }
        allGCD = __gcd(allGCD, A[i]);
    }

    if (pairWise) {
        cout << "pairwise coprime" << "\n";
    } else if (allGCD == 1) {
        cout << "setwise coprime" << "\n";
    } else {
        cout << "not coprime" << "\n";
    }


    return 0;
}


Measured memory_bytes: 15340
#include<iostream>
#include<vector>

using namespace std;
using ll = long long;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n), b(n), c(100002);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[a[i]] += b[i];
	}
	for (int i = 1; i < 100003; i++) {
		if (k <= c[i]) {
			cout << i << endl;
			return 0;
		}
		k -= c[i];
	}

	return 0;
}

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

int main() {
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int ans=0;
  if(a+b<=2*c)ans=a*x+b*y;
  else{
    a=min(a,2*c);
    b=min(b,2*c);
    int dob=min(x,y);
    ans=2*dob*c+a*(x-dob)+b*(y-dob);
  }
  cout << ans;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
vector<int> k[1000],ans;
bool t[1000*1000]={};
 int used[1000]={},c=-1;
void dfs(int a){
  
  if(used[a]==1)return ;
  if(used[a]==-1){
    c=a;
    return ;
  }
  used[a]=-1;
  for(int i=0;i<k[a].size();i++){
    dfs(k[a][i]);
    if(c!=-1)break;
  }
  if(c>=0){
   
    ans.push_back(a+1);
    if(a==c)c=-2;
   
  }
  used[a]=1;
  return ;
}
signed main() {
  int n,m;
  cin>>n>>m;
  int a,b;
 
  for(int i=0;i<m;i++){
    cin>>a>>b;
    k[a-1].push_back(b-1);
    t[(a-1)*n+b-1]=true;
  }
 
  stack<int> s;
  for(int i=0;i<n;i++){
   
    dfs(i);
    if(c!=-1)break;
  }
 if(ans.empty()){
   cout<<-1;
   return 0;
 }
 reverse(ans.begin(),ans.end());

  int u=0,w;
  while(ans[u]>=0){
    w=ans.size()-1;
    while(!t[(ans[u]-1)*n+abs(ans[w])-1])w--;
    ans.push_back(-ans[u]);
    u=w;
  }
  cout<<ans.size()-u<<endl;
  for(int i=u;i<ans.size();i++)cout<<-ans[i]<<endl;

  
  


  


  return 0;
}


Measured memory_bytes: 1408
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
int main(void){

	while(1){
		int n,m;
		int d[101],v[101];
		int total=0;
		int maxi=-1;

		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}

		FOR(i,1,n){
			cin>>d[i]>>v[i];
		}

		FOR(i,1,m){
			maxi=-1;
			FOR(j,1,n){
				if(d[j]==i){
					if(v[j]>maxi){
						maxi=v[j];
					}
				}
			}
			total+=maxi;
		}

		cout<<total<<endl;

	}

}


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

int main() {
  int x, y, z;
  cin >> x >> y >> z;

  printf("%d %d %d", z, x, y);

  return 0;
}


Measured memory_bytes: 3676
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int num;
	cin>>num;
	for(int i=0;i<num;i++){
		int a[3];
		cin>>a[0]>>a[1]>>a[2];
		sort(a,a+3);
		if(a[2]*a[2]==a[1]*a[1]+a[0]*a[0])
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
    return 0;
}

Measured memory_bytes: 1168
H,W=map(int,input().split())
h,w=map(int,input().split())
masu = [[0]*W for i in range(H)]
for i in range(h):
    for j in range(W):
        masu[i][j]=1
for i in range(w):
    for j in range(H):
        masu[j][i]=1
ans = 0
for i in range(W):
    for j in range(H):
        if masu[j][i]==0:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
 #include<cstring>
 #include<algorithm>
 using namespace std;
int n,ans,a[100100];
int main(){
    scanf("%d",&n);
   for(int i=1;i<=n;i++) scanf("%d",&a[i]);
   sort(a+1,a+n+1);
   reverse(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        if(i+1>a[i+1]){
              for(int j=i+1;a[j]==i;j++) ans^=1;
              ans|=(a[i]-i)&1;
              puts(ans? "First":"Second");
              return 0;
           }    
    }    
} 

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {


    }

    void solve() {
        input();
        int a, b;
        cin >> a >> b;
        if (a >= 13) {
            cout << b << endl;
        } else if (a < 6) {
            cout << 0 << endl;
        } else {
            cout << b / 2 << endl;
        }

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    rep(i, N) { cin >> A[i]; }

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

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

    sort(all(A)), sort(all(B)), sort(all(C));

    ll ans = 0;
    rep(i, N) {
        ll b = B[i];
        ll left = lower_bound(all(A), b) - A.begin();
        ll right = C.end() - upper_bound(all(C), b);
        ans += left * right;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5556
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0 && m==0)
      return 0;
    int kaihi = m/n;
    int ans=0;
    int a;
    for(int i=0;i<n;i++){
      cin>>a;
      if(a<m/n)
	ans+=a;
      else
	ans+=m/n;
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll L;
  cin>>L;
  printf("%.12f\n",L*L*L*pow(3,-3));
}


Measured memory_bytes: 256
#include<iostream>
#define MAX 2000000
#define k 10000
using namespace std;
void Counting_Sort(int A[],int B[],int n);

int A[MAX],B[MAX],C[MAX];;
int main()
{
	int n,i,x;

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

	Counting_Sort(A,B,n);

	for(i=0;i<n-1;i++){
		cout << B[i] << ' ' ;
	}

	cout << B[i] << endl ;

	return 0;
}

void Counting_Sort(int A[],int B[],int n)
{
    int i,j;

	for(i=0;i<k;i++){
        C[i] = 0 ;

	}

    for(j=0;j<n;j++){
        C[A[j]] = C[A[j]]+1 ;
	}

    /* C[i]??????i???????????属????即???????????????????*/
    
	for(i=1;i<k;i++){
		C[i] = C[i] + C[i-1] ;
	}
    /* C[i]??????i??\????????属???????????属????即???????????????????*/
    for(j=n-1;j>=0;j--){
		C[A[j]] = C[A[j]]-1 ;
		B[C[A[j]]] = A[j] ;
      
	}
}

Measured memory_bytes: 18500
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int n, m, c; cin >> n >> m >> c;
  auto b = make_v(m, 0);
  auto a = make_v(n, m, 0);

  REP(i, m) cin >> b[i];
  
  int cnt = 0;
  REP(i, n){
    int sum = 0;
    REP(j, m){
      cin >> a[i][j];
      sum += b[j] * a[i][j];
    }
    
    if(sum + c > 0) cnt++;
  }

  cout << cnt << endl;

  return 0;
}


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

int main(){
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  auto f = [C,D](long long X){
             long long L = C/__gcd(C,D)*D;
             return X-X/C-X/D+X/L;
           };
  cout << f(B) - f(A-1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define isNum(a) (a>='0'&&a<='9')
#define SP putchar (' ')
#define EL putchar ('\n')
#define inf 2147483647
#define N 15
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
template<class T1>inline void read(T1&);
template<class T1>inline void write(T1);
int a[N];
int main () {
    int n;
    read(n);
    for (int i=1; i<=n; ++i) {
        read(a[i]);
    }
    sort(a+1, a+n+1);
    int sum=0;
    for (int i=1; i<n; ++i) {
        sum+=a[i];
    }
    sum+=(a[n]>>1);
    write(sum);
    EL;
    return 0;
}
template<class T1>void read(T1 &r_e_a_d) {
    T1 k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch)) {
        if (ch=='-') {
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch)) {
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    r_e_a_d = flag*k;
}
template<class T1>void write(T1 w_r_i_t_e) {
    if (w_r_i_t_e<0) {
        putchar('-');
        write(-w_r_i_t_e);
    }else {
        if (w_r_i_t_e<10) {
            putchar(w_r_i_t_e+'0');
        }else {
            write(w_r_i_t_e/10);
            putchar((w_r_i_t_e%10)+'0');
        }
    }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    if(x==0)
      System.out.println("1");
    else if(x==1)
      System.out.println("0");
    else
      System.out.println("-1");
  }
}

Measured memory_bytes: 35584
def main():

    N = int(input())
    a, b = [], []
    for _ in range(N):
        A, B = map(int, input().split())
        a.append(A)
        b.append(B)

    a.sort()
    b.sort()

    if N % 2 == 0:
        u = a[N//2-1] + a[N//2]
        v = b[N//2-1] + b[N//2]
        return max((v-u)+1, 0)
    else:
        u = a[(N)//2]
        v = b[(N)//2]
        return max(v-u+1, 0)

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 25304
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    map<int, int> mp;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        mp[a]++; mp[b]++;
    }

    rep(i, N) {
       cout << mp[i] << endl; 
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+233;

int main(){
	long long n,d;
	cin>>n>>d;
	long long cnt=0;
	for(int i=0;i<n;i++){
		long long x,y;
		cin>>x>>y;
		if(x*x+y*y<=d*d)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
using namespace std;

int n,k;
int w[100001];
int maxw=0;

bool C(int t){

  if(t < maxw) return false;
  
  int n_track=1;
  int p=0;
  for(int i=0;i<n;i++){
    if(p+w[i]<=t) p+=w[i];
    else{
      n_track++;
      p = w[i];
    }
  }
  if(n_track <= k) return true;
  else return false;
  
}

int solve(int lb,int ub){
  int mid;
  while(ub-lb>1){
    mid = (lb+ub)/2;
    if(C(mid)) ub=mid;
    else lb=mid;// range to search:(lb, ub]
  }
  return ub;


}
 
int main(){

  cin>>n>>k;
  
  for(int i=0;i<n;i++){
    cin>>w[i];
    if(maxw<w[i]) maxw=w[i];
  }
  cout<<solve(0,INT_MAX/3)<<endl; 
  
  return 0;
}

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

		ll m;
		string name;
	  while(n>0){
			--n;
			m=n%26;
			n=(n-m)/26;
			name += 0x61+m;
		}
		reverse(name.begin(),name.end());
    cout << name << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main()
{
	int n;
	int i;
	int ans;
	
	while(scanf("%d",&n)!=EOF)
	{
		ans=1;
		for(i=0;i<=n;i++)
		{
			ans+=i;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using vi = vector<int>;
using pii = pair<int, int>;
#define fir first
#define sec second

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

int main() {
    // input
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i, d) {
        cin >> p[i] >> c[i];
    }
    // solve
    int min_c = 1000;
    rep(bit, 1<<d) {
        int cnt = 0, scr = 0;
        rep(i, d) {
            if (bit & 1<<i) {
                scr += 100 * (i+1) * p[i] + c[i];
                cnt += p[i];
            }
        }
        if (scr >= g) chmin(min_c, cnt);
        else {
            repr(i, d) {
                if (~bit & 1<<i) {
                    rep(j, p[i]-1) {
                        scr += 100 * (i+1);
                        cnt++;
                        if (scr >= g) break;
                    }
                }
                if (scr >= g) break;
            }
            if (scr >= g) chmin(min_c, cnt);
        }
    }
    // output
    cout << min_c << endl;
}

Measured memory_bytes: 3612
N, K = map(int, input().split())
A = list(map(int, input().split()))

visited = [-1] * N
visited[0] = 0
nxt = 1
cycl = N
m = 0
for i in range(N):
    nxt = A[nxt-1]
    if visited[nxt-1] == -1:
        visited[nxt-1] = i+1
    else:
        cycl = i + 1 - visited[nxt-1]
        m = visited[nxt-1]
        break
if K < m: k = K
else:
    k = (K - m) % cycl + m

for i in range(N):
    if visited[i] == k:
        print(i+1)
        break


Measured memory_bytes: 32376
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define printd(x) printf("%.12f\n", ans);
#define print(x) cout << (x) << endl;
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
#define all(x) (x).begin(),(x).end()
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main(void) {
    int n;
    cin >> n;
    int a[n];
    rep (i, n) cin >> a[i];

    ll ans1 = 0, ans2 = 0;

    //sort(a, a + n);

    bool mae = false;
    rep (i, n) {
        if (!a[i]) mae = false;
        ans1 += a[i] / 2;

        if (mae && a[i] % 2 == 1) {
            ans1++;
            mae = false;
        }
        else if (mae && a[i] % 2 == 0) {
            mae = true;
        }
        else if (a[i] % 2 == 1) {
            mae = true;
        }
        //cout << i << " "<<ans1<<endl;
    }
    
    cout << ans1 << endl;
    return 0;
}

Measured memory_bytes: 640
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline()).split())

n,y=nii()
for i in range(n+1):
  for j in range(n-i+1):
    num=n-i-j
    money=10000*i+5000*j
    zan=(y-money)//1000
    if num==zan:
      print(i,j,num)
      exit()

print(-1,-1,-1)

Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b;
	if (b == 100)
		c = 1000 * a + b;
	else if (b >= 10)
		c = 100 * a + b;
	else
		c = 10 * a + b;
	//100100
	for (int i = 4; i <= sqrt(100100); i++) {
		if (c == i * i) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ll long long
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  if(n == 1 || m == 1) {
    cout << 1 << "\n";
    return 0;
  }
  cout << (n * m + 1) / 2 << "\n";
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int N,A,B,C,l[8];
bool f[8]={};
int dfs(int num,int a,int b,int c,int sum){
	if(num==N){
		if(a==0||b==0||c==0)return INF;
		else return abs(A-a)+abs(B-b)+abs(C-c)+sum*10-30;
	}
	int cost1=dfs(num+1,a+l[num],b,c,sum+1);
	int cost2=dfs(num+1,a,b+l[num],c,sum+1);
	int cost3=dfs(num+1,a,b,c+l[num],sum+1);
	int cost4=dfs(num+1,a,b,c,sum);
	return min({cost1,cost2,cost3,cost4});
}

int main(){
	cin>>N>>A>>B>>C;
	rep(i,0,N)cin>>l[i];
	sort(l,l+N);
	print(dfs(0,0,0,0,0));
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

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

	if (n % 2 == 0)
	{
		cout << n << endl;
	}
	else
	{
		cout << n * 2 << endl;
	}

	return 0;
}

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

int main(){
    int num[8],n;
    cin>>n;
    while(n--){
        for(int i=0;i<8;i++){
            char c;
            cin>>c;
            num[i]=c-'0';
        }
        sort(num,num+8);
        int b=0,s=0;
        for(int i=0;i<8;i++){
            b+=num[i]*pow(10,i);
            s+=num[7-i]*pow(10,i);
        }
        cout<<b-s<<endl;
    }
}

Measured memory_bytes: 1220
#include<stdio.h>

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

int main() {

	int N, K;
	int lcd = 10000000000;
	int max = 0;
	scanf("%d %d", &N, &K);
	int *A = (int *)malloc(sizeof(int)*N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
		if (max < A[i])
		{
			max = A[i];
		}
	}
	lcd = A[0];
	for (int i = 1; i < N; i++)
	{
		lcd = gcd(A[i], lcd);
	}


	if (K <= max && K%lcd == 0)
	{
		puts("POSSIBLE");
		return 0;
	}

	puts("IMPOSSIBLE");
	return 0;
}



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

using namespace std;
#define BUF (3005)
#define ll long long 

int N,T;
vector<int> A,B;
int dp1[BUF][BUF];
int dp2[BUF][BUF];

void dump_dp(){
	cout << "--- dp1 ---" << endl;
	for(int n=0;n<N;n++){
		for(int t=0;t<=T;t++){
			cout << dp1[t][n] << " ";
		}
		cout << endl;
	}

	cout << "--- dp2 ---" << endl;
	for(int n=0;n<N;n++){
		for(int t=0;t<=T;t++){
			cout << dp2[t][n] << " ";
		}
		cout << endl;
	}
}

int main(void){
	// in
	cin >> N >> T;
	for(int i=1;i<=N;i++){
		int a,b;
		cin >> a >> b;
		A.push_back(a);
		B.push_back(b);
	}

	//for(int n=0;n<=N;n++){ dp1[0][n] = 0; }
	for(int t=0;t<=T;t++){ 
		if(A[0]<=t){
			dp1[t][0] = B[0];
		}
	}
	for(int t=1;t<=T;t++){
		for(int n=1;n<N;n++){
			if(t-A[n] < 0) dp1[t][n] = dp1[t][n-1];
			else dp1[t][n] = max(dp1[t][n-1], B[n] + dp1[t-A[n]][n-1]);
		}
	}

	//for(int n=0;n<=N;n++){ dp2[0][n] = 0; }
	for(int t=1;t<=T;t++){ 
		dp2[t][0] = B[0];
	}
	
	for(int t=1;t<=T;t++){
		for(int n=1;n<N;n++){
			dp2[t][n] = max(dp2[t][n-1], dp1[t-1][n-1] + B[n]);
			if(t-A[n] >= 0) {
				dp2[t][n] = max(dp2[t][n], B[n] + dp2[t-A[n]][n-1]);
			}
		}
	}

	cout << dp2[T][N-1]<<endl;

	//dump_dp();

	return 0;
}


Measured memory_bytes: 70784
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MAXN 1000005 

int a;

int main()
{
	cin>>a;
	cout<<a+a*a+a*a*a<<endl; 
	return 0;
} 

Measured memory_bytes: 3568
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	r := list[0]
	D := list[1]
	x2000 := list[2]
	xList := make([]int, 11)

	xList[0] = x2000
	for i := 1; i <= 10; i++ {
		xList[i] = r*xList[i-1] - D
		fmt.Printf("%d\n", xList[i])
	}
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 1024*1024*10)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

int main(){
    bool cards[4][14];
    int n, r;
    char s;
    for ( int i = 0; i < 4; i++ ){
        for ( int j = 1; j <= 13; j++){
            cards[i][j] = 0;
        }
    }
    cin >> n;
    for ( int i = 0;i < n; i++ ){
        cin >> s >> r;
        if ( s == 'S' ) cards[0][r] = 1;
        if ( s == 'H' ) cards[1][r] = 1;
        if ( s == 'C' ) cards[2][r] = 1;
        if ( s == 'D' ) cards[3][r] = 1;
    }
    for ( int i = 0; i < 4; i++ ){
        for ( int j = 1;j <= 13; j++ ){
            if ( cards[i][j] ) continue;
            if ( i == 0) s = 'S';
            if ( i == 1) s = 'H';
            if ( i == 2) s = 'C';
            if ( i == 3) s = 'D';
            cout << s << " " << j << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3084
N,M=[int(i) for i in input().split(" ")]
plog={}
for i in range(M):
    p,S=input().split(" ")
    if p in plog:
        plog[p]+=[S]
    else:
        plog[p]=[S]

WA_Count=0
AC_Count=0
for pl in plog:
    _WA_Count=0
    for res in plog[pl]:
        if res=="WA":
            _WA_Count+=1
        elif res=="AC":
            AC_Count+=1
            WA_Count+=_WA_Count
            break
print("%d %d"%(AC_Count,WA_Count))


Measured memory_bytes: 30152
sx, sy, tx, ty = map( int, input().split() )
dx = tx - sx 
dy = ty - sy
sol = ""
sol = sol+"U"*dy+"R"*dx+"D"*dy+"L"*dx
sol = sol+"L"+"U"*(dy+1)+"R"*(dx+1)+"D"+"R"+"D"*(dy+1)+"L"*(dx+1)+"U"
print(sol)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int x, y, z, k, s;
    int ans = 0;
    cin >> k >> s;
    for (int i=0; i<=k; ++i){
        for (int j=0; j<=k; ++j){
            x = i;
            y = j;
            z = s - x - y;
            if(0 <= z && z <= k){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn =new Scanner(System.in);
		long x=scn.nextLong();
		long  k =scn.nextLong();
	     long d =scn.nextLong();
	     x =Math.abs(x);
	     long val1= x/d;
//	     if(x%d!=0){
//	    	 val1++;
//	     }
	    
	     long val2= x-d*val1;
	     if(val1>k){
	    	  long ans = x-d*k;
	    	 System.out.println(ans);
	     }else{
	    	   k-=val1;
	    	   long val3=Math.abs(val2-d);
	    	   if(k%2==0){
	    		   System.out.println(val2);
	    	   }else{
	    		   System.out.println(val3);
	    	   }
	    	 
//	    	  long ans = Math.min(val2, val3);
//	    	  System.out.println(ans);
	     }
	     

	}

}

Measured memory_bytes: 35836
void main()
{
    long n, k;
    rdVals(n, k);
    long[] a = rdRow;
    long[] f = rdRow;

    a.sort!"a < b";
    f.sort!"a > b";

    bool check(long x)
    {
        long total;
        foreach (i; 0 .. n)
        {
            total += max(0, a[i]-x/f[i]);
        }
        return total <= k;
    }

    long l = 1L << 40, r = -1;
    while (abs(r - l) > 1)
    {
        long m = (l + r) / 2;
        if (check(m)) l = m;
        else r = m;
    }

    l.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 14904
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int N, x = 0;
  cin >> N;
  char c;
  int ans = 0;
  rep(i, 0, N) {
    cin >> c;
    if (c == 'I')
      x++;
    else if (c == 'D')
      x--;
    ans = max(ans, x);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cstdlib>

using namespace std;

int main(){
    int r,c;
    cin>>r>>c;
    int **table;
    table=(int **)malloc(sizeof(int *)*r);
    if (table==NULL){
        cout<<"Error!"<<endl;
        return -1;
    }
    int i,j;
    for (i=0;i<r;i++){
        table[i]=(int *)malloc(sizeof(int)*c);
        if (table[i]==NULL){
            cout<<"Error!"<<endl;
            return -1;
        }
        for (j=0;j<c;j++){
            cin>>table[i][j];
        }
    }
    int sum;
    for (i=0;i<r;i++){
        sum=0;
        for (j=0;j<c;j++){
            cout<<table[i][j]<<" ";
            sum+=table[i][j];
        }
        cout<<sum<<endl;
    }
    int sum2=0;
    for (i=0;i<c;i++){
        sum=0;
        for (j=0;j<r;j++){
            sum+=table[j][i];
        }
        cout<<sum<<" ";
        sum2+=sum;
    }
    cout<<sum2<<endl;
    for (i=0;i<r;i++){
        free(table[i]);
    }
    free(table);
    return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double pi= 3.14159265358979323846264338327950288;
char a[800][800];
const ll inf = 99999999999999;
int b[800][800];
struct Q {
	ll x, y;
};
int u1[4] = { 0,0,-1,1 }, u2[4] = { -1,1,0,0 };
signed main() {
	ll h, w, x, y, k;
	cin >> h >> w >> k;
	for (ll i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (ll j = 0; j < w; j++) {
			a[i][j] = s[j];
			b[i][j] = inf;
			if (s[j] == 'S')
				x = j, y = i;
		}
	}
	queue<Q>q;
	q.push(Q{ x,y });
	b[y][x] = 0;
	ll ans = inf;
	while (!q.empty()) {
		Q t = q.front(); q.pop();
		ans = min(ans, (ll)ceil(min(t.x, min(w - 1 - t.x, min(h - 1 - t.y, t.y)))*1.0 / k) + 1);
		for (int i = 0; i < 4; i++) {
			ll x = t.x + u1[i];
			ll y = t.y + u2[i];
			if (x < w&&x >= 0 && y < h&&y >= 0 && a[y][x] == '.'&&b[t.y][t.x] + 1 < b[y][x] && b[t.y][t.x] + 1 <= k) {
				q.push(Q{ x,y });
				b[y][x] = b[t.y][t.x] + 1;
			}
		}
	}
	cout << ans << endl;
	cin >> h;
}

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

typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printArray(arr) for (int i = 0; i<size(arr); i++) cout << arr[i] << " ";cout << '\n'
#define printVerdict(verdict) cout << (verdict ? "YES": "NO") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)

const ll inf = 0x3f3f3f3f;

template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) {cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n';}
template <class T1, class T2>
void printPair(pair<T1, T2> p) {cout << p.first << " " << p.second << '\n';}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	ll a[n];
	for (int i = 0; i<n; i++) cin >> a[i];
	vector<pair<ll, ll>> buy(n);
	vector<ll> sell(n, 0);
	buy[0] = make_pair(1000/a[0], 1000%a[0]);
	sell[0] = 1000;
	for (int i = 1; i<n; i++) {
		for (int j = 0; j<i; j++) sell[i] = max(sell[i], buy[j].first * a[i] + buy[j].second);
		buy[i] = make_pair(1000/a[i], 1000%a[i]);
		for (int j = 0; j<=i; j++) {
			if (sell[j] / a[i] > buy[i].first) buy[i] = make_pair(sell[j] / a[i], sell[j] % a[i]);
			else if (sell[j] / a[i] == buy[i].first) buy[i].second = max(buy[i].second, sell[j]%a[i]);	
			sell[i] = max(sell[i], buy[j].first * a[i] + buy[j].second);
		}
		
	}
	ll ret = 1000;
	for (int i = 0; i <n; i++) ret = max(ret, sell[i]); 
	cout << ret << '\n';
}



Measured memory_bytes: 3684
def main():
    n, m = map(int, input().split(" "))
    ls=[{} for _ in range(n)]
    h = list(map(int, input().split(" ")))
    for i in range(n):
        ls[i] = [h[i]]
    ab = []
    for i in range(m):
        ab.append(list(map(lambda i:int(i)-1, input().split(" "))))
    for i in range(m):
        if ls[ab[i][0]][0] >= ls[ab[i][1]][0]:
            ls[ab[i][1]].append(ls[ab[i][0]][0]+1)
        if ls[ab[i][1]][0] >= ls[ab[i][0]][0]:
            ls[ab[i][0]].append(ls[ab[i][1]][0] + 1)
    cnt = 0
    for i in range(n):
        if ls[i][0] == max(ls[i]):
            cnt += 1
    print(cnt)

        

    

if __name__ == "__main__":
    main()

Measured memory_bytes: 47400
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

set<string> dfs(map<string,set<string> > &groups,string cur,map<string,set<string> > &dp){
	if(EXIST(dp,cur)){
		return dp[cur];
	}
	map<string,set<string> >::iterator it=groups.find(cur);
	if(it==groups.end()){
		set<string> ret;
		ret.insert(cur);
		return ret;
	}
	set<string> &group=it->second;
	set<string> ret;
	for(set<string>::iterator it2=group.begin();it2!=group.end();it2++){
		set<string> s=dfs(groups,*it2,dp);
		if(s.size()>ret.size()){
			swap(ret,s);
		}
		ret.insert(ALL(s));
	}
	return dp[cur]=ret;
}

int main(){
	int n;
	while(cin>>n,n){
		map<string,set<string> > groups;
		string first_group;
		REP(i,n){
			string s;
			cin>>s;
			string tmp;
			string group;
			set<string> tmp_members;
			REP(j,s.size()){
				if(s[j]==':'){
					group=tmp;
					tmp.clear();
				}else if(s[j]==','||s[j]=='.'){
					tmp_members.insert(tmp);
					tmp.clear();
				}else if(s[j]!='.'){
					tmp+=s[j];
				}
			}
			groups[group]=tmp_members;
			if(i==0){
				first_group=group;
			}
		}
		bool changed=true;
		map<string,set<string> > dp;
		set<string> s=dfs(groups,first_group,dp);
		cout<<s.size()<<endl;
	}
}

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

int H, W;
vector<string> fi;
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];

int main() {
    
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];

    
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Left[i][j] = cur;
        }
    }
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = W-1; j >= 0; --j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Right[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = 0; i < H; ++i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Up[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = H-1; i >= 0; --i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Down[i][j] = cur;
        }
    }

   
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') continue;
            res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 72448
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [input().split() for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0

    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    res = [0] * (M+1)
    res[-1] = min(a)+min(b)
    for i in range(M):
        x,y,c = map(int,input().split())
        res[i] = a[x-1]+b[y-1]-c
    print(min(res))


if __name__ == '__main__':
    main()



Measured memory_bytes: 68940
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami,mado[100];
	bool gg = false;
	int manji, nk[26] = {false};
	cin >> a>>b;
	for (int i = 0; i < a; i++) {
		cin >> d[i];
		c = min(d[i], abs(d[i] - b))*2;
		count += c;
		c = 0;
	}
	cout << count << endl;
	return 0;
}

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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	int64_t mod = 1000000007;

	vector<int64_t> bs(n + 1, 0);
	for (int64_t i = 0; i < n; i++)
	{
		bs[i + 1] = (bs[i] + as[i]) % mod;
	}

	int64_t ans = 0;
	for (int64_t i = 0; i < n; i++)
	{
		(ans += as[i] * ((bs[n] - bs[i + 1] + mod) % mod) % mod) %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6368
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<pair<int,int>> A(N);
  for(pair<int,int> &p:A)
    cin>>p.first>>p.second;
  map<pair<int,int>,int> B;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      if(i!=j)
        B[make_pair(A[i].first-A[j].first,A[i].second-A[j].second)]++;
  int ans=0;
  for(pair<pair<int,int>,int> p:B)
    ans=max(ans,p.second);
  cout<<N-ans<<endl;
}

Measured memory_bytes: 3728
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll N,T,Q,A[100000],D[100000],X[1000];
int main()
{
	scanf("%lld%lld%lld",&N,&T,&Q);
	for(ll i=0;i<N;i++){
		scanf("%lld%lld",&A[i],&D[i]);
	}
	for(ll i=0;i<Q;i++){
		scanf("%lld",&X[i]);
		X[i]--;
	}
	vector<ll> sec;
	for(ll i=0;i<N-1;i++){
		if(D[i]==1&&D[i+1]==2) sec.push_back((A[i]+A[i+1])/2);
	}
	ll ans,id;
	for(ll i=0;i<Q;i++){
		if(D[X[i]]==1){
			ans=A[X[i]]+T;
			id=upper_bound(sec.begin(),sec.end(),A[X[i]])-sec.begin();
			if(id<sec.size()&&sec[id]<ans) ans=sec[id];
		}
		else{
			ans=A[X[i]]-T;
			id=lower_bound(sec.begin(),sec.end(),A[X[i]])-sec.begin()-1;
			if(id>=0&&sec[id]>ans) ans=sec[id];
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 4928
#include<stdio.h> 

int main(void){
  int N, i,a, b=0,c=0;
  int abc[150];
  scanf("%d", &N);
  for(i=0;i<N;i++){
    scanf("%d", &abc[i]);
  }
  a=abc[0];
  for(i=1;i<N;i++){
    if(a<abc[i]){
     	a=abc[i]; 
      	c=i;
    }
  }
  for(i=0;i<N;i++){
    b+=abc[i];
  }
  b=b-abc[c];
  if(a<b){
    printf("Yes");
  }else {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))

t = True
if not(c1[0]-c2[0] == c1[1]-c2[1] == c1[2]-c2[2]):
  t = False
if not(c1[0]-c3[0] == c1[1]-c3[1] == c1[2]-c3[2]):
  t = False

if not(c1[0]-c1[1] == c2[0]-c2[1] == c3[0]-c3[1]):
  t = False
if not(c1[0]-c1[2] == c2[0]-c2[2] == c3[0]-c3[2]):
  t = False

if t:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
int a[6];
int main() {
	int L,N=0,M=0;
	while (cin >> N) {
		L = 1000 - N;
		if (N == 0) {
			break;
		}
		if (L >= 500) {
			a[0]++;
			L = L - 500;
		}
		while (L >= 100) {
			a[1]++;
			L = L - 100;
		}
		while (L >= 50) {
			a[2]++;
			L = L - 50;
		}
		while (L >= 10) {
			a[3]++;
			L = L - 10;
		}
		while (L >= 5) {
			a[4]++;
			L = L - 5;
		}
		a[5] = L;
		M = a[0] + a[1] + a[2] + a[3] + a[4] + a[5];
		cout << M << endl;
		M = 0;
		for (int i = 0; i < 6; i++) {
			a[i] = 0;
		}
	}
}

Measured memory_bytes: 1156
import math
N,K=map(int,input().split())

sum=0
for deme in range(1,N+1):
    need_challenge=max(0,math.ceil(math.log2(K)-math.log2(deme)))
    sum+=float((1/N)*((1/2)**need_challenge))
print('{:.13f}'.format(sum))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int A, B; cin >> A >> B;

	if (A > 8 || B > 8){
		cout << ":(" << endl;
	}else{
		cout << "Yay!" << endl;
	} // end if
	
	return 0;
}

Measured memory_bytes: 256
W,H,N=map(int,input().split())
l,r,b,t=0,W,0,H
for _ in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        l=max(l,x)
    elif a==2:
        r=min(r,x)
    elif a==3:
        b=max(b,y)
    else:
        t=min(t,y)
if l<r and b<t:
    print((r-l)*(t-b))
else:
    print(0)

Measured memory_bytes: 9208