akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n, m;
	while(cin >> n >> m) {
		vector<P> xy;
		REP(_, m) {
			int x, y;
			cin >> x >> y;
			x--; y--;
			xy.emplace_back(x, y);
		}
		reverse(ALL(xy));

		using bits = bitset<410>;
		vector<bits> bss(n);
		REP(s, n) {
			bss[s][s] = true;
			for(auto&& e : xy) {
				int x, y;
				tie(x, y) = e;
				if(bss[s][x] and bss[s][y]) {
					bss[s] = 0;
					bss[s] = ~bss[s];
					break;
				} else if(bss[s][x] || bss[s][y]) {
					bss[s][x] = true;
					bss[s][y] = true;
				}
			}
		}
		int ans = 0;
		REP(i, n) REP(j, i) {
			if((bss[i] & bss[j]) == 0) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1400
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long s = sc.nextLong();
    ArrayList<Long> list = new ArrayList<Long>();
    list.add(s);
    int ans = 0;
    for(int i = 1; i <= 1000000; i++) {
      if((s % 2) == 0) {
        s /= 2;
      } else {
        s = 3 * s + 1;
      }
      if(list.contains(s)) {
        ans = i + 1;
        break; 
      } else {
        list.add(s);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21332
N=int(input())
F=[[int(s) for s in input().split()] for i in range(N)]
P=[[int(s) for s in input().split()] for i in range(N)]
def bi(num):
  val_ls=[0 for _ in range(10)]
  for bi_i in range(10):
    if (2**bi_i)&num>0:
      val_ls[bi_i]=1
  return val_ls
def ri(bi_ls):
  val_ri=0
  for ri_i in range(N):
    val=0
    for j in range(10):
      if bi_ls[j]==F[ri_i][j] and bi_ls[j]==1:
        val+=1
    val_ri+=P[ri_i][val]
  return val_ri
print(max([ri(bi(i)) for i in range(1,1024)]))
      
  

Measured memory_bytes: 3064
a,b,c = map(int, input().split())
d,e,f = map(int, input().split())
g,h,i = map(int, input().split())

if a-b == d-e:
    if d-e == g-h:
        if b-c == e-f:
            if e-f == h-i:
                if a-d == b-e:
                    if b-e ==c-f:
                        if d-g == e-h:
                            if e-h ==f-i:
                                print("Yes")
                                exit()

print("No")

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int th,ts,ah,as;
    cin>>th>>ts>>ah>>as;
    while(th>0 && ah>0)
    {
        ah=ah-ts;
        if(ah<=0){break;}
        th=th-as;
    }
    if(th>ah){cout<<"Yes"<<endl;}
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = ni();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nl();
            b[i] = nl();
        }

        long sum = 0;
        long ans = 0;
        for (int i = n - 1; i >= 0; i--) {
            a[i] += sum;
            long t = a[i] % b[i];
            if (t != 0) t = b[i] - t;
            ans += t;
            sum += t;
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 29156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC140C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] Binput = Console.ReadLine().Split(' ');
            int[] B = new int[N-1];
            for (int i = 0; i < N-1; i++)
            {
                B[i] = int.Parse(Binput[i]);
            }
            int ans = 0;
            ans += B[0];
            for (int i = 0; i < N - 2; i++)
            {
                ans += Math.Min(B[i], B[i + 1]);
            }
            ans += B[N - 2];
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27368
using System;
using System.Collections.Generic;
class Solve{
    int N;
    long[] t;
    long[] a;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        long count = 1;
        for(int i=0;i<N;i++){
            long k;
            if((i == N-1 || a[i] > a[i+1]) && (i == 0 || t[i] > t[i-1])){
                if(a[i] == t[i]){
                    k = 1;
                }
                else{
                    k = 0;
                }
                
            }
            else if(i == N-1 || a[i] > a[i+1]){
                if(a[i] <= t[i]){
                    k = 1;
                }
                else{
                    k = 0;
                }
            }
            else if(i == 0 || t[i] > t[i-1]){
                if(t[i] <= a[i]){
                    k = 1;
                }
                else{
                    k = 0;
                }
            }
            else{
                k = a[i] > t[i] ? t[i] : a[i] ;
            }
            count = (count*k)%Define.mod;
        }
        Console.WriteLine(count);
    }
    void getinput(){
        string[] str;
        N = int.Parse(Console.ReadLine());
        a = new long[N];
        t = new long[N];
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            t[i] = Int64.Parse(str[i]);
        }
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            a[i] = Int64.Parse(str[i]);
        }
    }    
}
public static class Define{
    public const long mod = 1000000007;
}

Measured memory_bytes: 23528
import sys
while True :
    H, W = map(int, raw_input().split(" "))
    if (H == W == 0) :
        break
    for h in range(0, H) :
        for w in range(0, W) :
            if ((w + h) % 2 == 0) :
                sys.stdout.write("#")
            else :
                sys.stdout.write(".")
        print("")
    print("")

Measured memory_bytes: 6300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int H,W;
string S[20];
int ans = 0;
int d[21][21];
int did[21][21];
void cl(){
	FOR(i,0,20)FOR(j,0,20)did[i][j]=0;
}

int main(){

	cin >> H >> W;
	FOR(i,0,H){
		cin >> S[i];
	}

	FOR(i,0,H){
		FOR(j,0,W){
			if(S[i][j]=='#') continue;
			queue<int> h,w;
			cl();
			did[i][j] = 1;
			d[i][j] = 0;
			h.push(i);
			w.push(j);
			while(h.size()){
				int nowh = h.front();
				int noww = w.front();
				h.pop(); w.pop();
				ans = max(ans,d[nowh][noww]);
				if(nowh < H-1)if(S[nowh+1][noww]=='.')if(not did[nowh+1][noww]){
					did[nowh+1][noww] = 1;
					d[nowh+1][noww] = d[nowh][noww] + 1;
					h.push(nowh+1);
					w.push(noww);
				}
				if(nowh > 0)if(S[nowh-1][noww]=='.')if(not did[nowh-1][noww]){
					did[nowh-1][noww] = 1;
					d[nowh-1][noww] = d[nowh][noww] + 1;
					h.push(nowh-1);
					w.push(noww);
				}
				if(noww < W-1)if(S[nowh][noww+1]=='.')if(not did[nowh][noww+1]){
					did[nowh][noww+1] = 1;
					d[nowh][noww+1] = d[nowh][noww] + 1;
					h.push(nowh);
					w.push(noww+1);
				}
				if(noww > 0)if(S[nowh][noww-1]=='.')if(not did[nowh][noww-1]){
					did[nowh][noww-1] = 1;
					d[nowh][noww-1] = d[nowh][noww] + 1;
					h.push(nowh);
					w.push(noww-1);
				}

			}



		}
	}
	cout << ans << endl;

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,q,s[100001],t,ans=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>s[i];
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>t;
    int l=0,r=n,m;
    while(l<r){
      m=(l+r)/2;
      if(t<s[m])r=m;
      else if(t>s[m])l=m+1;
      else {ans++;break;}
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

void sayYes() {puts("Yes");}
void sayNo() {puts("No");}
template<class T> bool chmin(T&a,T b) {if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b) {if(a<b){a=b;return true;}return false;}

class FastIO {
public:
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
    }
    ~FastIO() {}

    template <class T>
    void scan(T &v) {
        cin >> v;
    }
    template <class T, class... Rest>
    void scan(T &v, Rest&... rest) {
        scan(v);
        scan(rest...);
    }

    template <class T>
    void print(T v) {
        cout << v;
    }
    template <class T, class... Rest>
    void print(T v, Rest... rest) {
        print(v);
        print(" ");
        print(rest...);
    }
    template <class T>
    void prints(vector<T> v) {
        for (T t: v) {
            print(t);
            print(" ");
        }
        print("\n");
    }
    template <class T>
    void prints(T v) {
        print(v);
        cout << "\n";
    }
    template <class T, class... Rest>
    void prints(T v, Rest... rest) {
        print(v);
        print(" ");
        prints(rest...);
    }
};
FastIO io;


int main() {
    int N, K, Q; io.scan(N, K, Q);
    vector<int> p(N, 0);
    REP(i, Q) {
        int A; io.scan(A);
        p[A-1]++;
    }
    int judge = Q - K;
    REP(i, N) {
        (p[i] > judge) ? sayYes() : sayNo();
    }
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class AtCoderr
    {

        static void Main(string[] args)
        {
            int[] nk = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nk[0];
            int k = nk[1];
            string s = ReadLine();
            int happiness = 0;
            char remain = s[0];
            for (int i = 1; i < n; i++)
            {
                if (s[i] == remain)
                {
                    happiness++;
                }
                else
                {
                    remain = s[i];
                }
            }
            WriteLine(Min(happiness + (2 * k) , n-1));
        }

    }
}


Measured memory_bytes: 13536
#include<iostream>

#include<string>

using namespace std;

int main()

{

    int n,k,m,b;

    int a[105]={0};

    cin>>n>>k;

    for(int i=0;i<k;i++)

    {

        cin>>m;

        for(int j=0;j<m;j++)

        {

            cin>>b;

            if(a[b]==0)

            a[b]++;

        }

    }

    int count=0;

    for(int i=1;i<=n;i++)

    {

        if(a[i]==0)

        count++;

    }

    cout << count << endl;

    return 0;

}

Measured memory_bytes: 3628
//Camel and Oases
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long lint;
int const N=2e5+10;
int const S=1<<19;
int n,V;
lint d[N];
int logV,a[25][N];
int U,f1[S],f2[S];
int upFind(int a[],int x)
{
    int L=1,R=a[0];
    while(L<R-1)
    {
        int mid=(L+R)>>1;
        if(a[mid]<=x) L=mid+1;
        if(a[mid]>x) R=mid;
    }
    if(a[L]>x) return a[L];
    else return a[R];
}
int lowFind(int a[],int x)
{
    int L=1,R=a[0];
    while(L<R-1)
    {
        int mid=(L+R)>>1;
        if(a[mid]<x) L=mid;
        if(a[mid]>=x) R=mid-1;
    }
    if(a[R]<x) return a[R]+1;
    else return a[L]+1;
}
void type(int s)
{
    for(int i=logV;i>=1;i--) printf("%d",(s>>(i-1))%2);
}
int main()
{
    scanf("%d%d",&n,&V);
    logV=0;
    while((1<<logV)<=V) logV++;
    logV++;
    for(int i=1;i<=n;i++) scanf("%lld",&d[i]),d[i-1]=d[i]-d[i-1];
    //for(int i=1;i<=n;i++) printf("%lld ",d[i]);
    d[n]=0;
    for(int i=1;i<=logV;i++)
    {
        a[i][0]=1;
        for(int j=1;j<=n;j++)
        {
            a[i][a[i][0]]=j;
            if(d[j]>(V>>(i-1))) a[i][0]++;
        }
    }
    /*for(int i=1;i<=logV;i++)
    {
    	printf("%d-%d ",1,a[i][1]);
        for(int j=2;j<=a[i][0];j++) printf("%d-%d ",a[i][j-1]+1,a[i][j]);
        printf("\n");
    }*/
    /*if(a[1][0]>logV)
    {
        for(int i=1;i<=n;i++)
            if(i==1) printf("Impossible-");
            else printf("\nImpossible-");
        return 0;
    }*/
    U=(1<<logV)-1;
    for(int s=0;s<=U;s++) f1[s]=0,f2[s]=n+1;
    for(int s=0;s<=U;s+=2)
        for(int i=2;i<=logV;i++)
        {
            int s0=1<<(i-1);
            if(s&s0) continue;
            f1[s|s0]=max(f1[s|s0],upFind(a[i],f1[s]));
            f2[s|s0]=min(f2[s|s0],lowFind(a[i],f2[s]-1));
        }
    /*for(int s=0;s<=U;s+=2)
        type(s),printf("   1-%2d  %2d-%2d\n",f1[s],f2[U-s-1],n);*/
    for(int i=1;i<=a[1][0];i++)
    {
        bool f=false;
        int fr=a[1][i-1]+1,to=a[1][i];
        if(i==1) fr=1;
        for(int s=0;s<=U&&!f;s+=2)
            if(fr<=f1[s]+1 && f2[U-s-1]-1<=to) f=true;
        if(f) for(int j=fr;j<=to;j++)
            if(j==1) printf("Possible");
            else printf("\nPossible");
        else for(int j=fr;j<=to;j++)
            if(j==1) printf("Impossible");
            else printf("\nImpossible");
    }
    return 0;
}

Measured memory_bytes: 25472
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const auto INF = (ll)1e9;
using v = vector<int>;

int main(){
	string s,t;
	cin >>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),greater<char>());
	cout << (s<t?"Yes":"No");
}


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

int main() {
    int k;
    vector<int> ab{0, 0};
    cin >> ab[0] >> ab[1] >> k;

    int i = 0;
    while (k--) {
        if (ab[i] & 1) {
            ab[i]--;
        }
        ab[i] >>= 1;
        ab[i ^ 1] += ab[i];
        i ^= 1;
    }
    cout << ab[0] << " " << ab[1] << endl;
}

Measured memory_bytes: 3532
N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort
OP = M.times.map{ gets.split.map(&:to_i) }.sort_by(&:last).reverse
OP.inject(0) do |offset, (b,c)|
  flag = b.times.all? do |i| 
    A[offset + i] = c if offset + i < N && A[offset + i] < c
  end
  if flag
    offset + b
  else
    break
  end
end
puts A.inject(&:+)

Measured memory_bytes: 22364
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
  int size[3];
  while (true) {
    cin >> size[0] >> size[1] >> size[2];
    if (size[0] == 0 && size[1] == 0 && size[2] == 0)
      break;
    sort(size+0, size+3);
    double a = size[0], b = size[1];
    double hoge = sqrt(a * a + b * b);
    int n, r;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> r;
      if (r * 2 > hoge)
        cout << "OK" << endl;
      else
        cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 998244353; //1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e4+2;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      char c;
      cin>>c;
      c++;
      cout<<c;
} 
// I never lose. I either win or I learn

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)

using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> vec(M, 0);
	int k,l;
	for (int i = 0; i < N; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> l;
			vec[l-1]++;
		}
	}
	sort(all(vec));
	cout << vec.end() -lower_bound(all(vec), N);

}

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

 
int main(void)
{
    int a,b,c,k,lim,i;
    bool ch1,ch2;

    cin >> a >> b >> c;
    cin >> k;

    ch1 = false;
    ch2 = false;
    lim = k+1;

    for(i=0;i<lim;i++){
        if(a<b){
            ch1 = true;
            break;
        }
        b *= 2;
    }

    if(ch1){
        lim -= i;
        for(i=0;i<lim;i++){
            if(b<c){
                ch2 = true;
                break;
            }
            c *= 2;
        }
    }

    if(ch2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

using namespace std;

int main() {
    double N, K;
    cin >> N >> K;

    double ans = 0;

    if (K == 1)
    {
        ans = 1;
        cout << setprecision(12) << ans << endl;
        return 0;
    }
    
    int a;
    int needThrow;

    for (int i = 1; i <= N; i++)
    {
        a = i;
        needThrow = 0;
        if (a >= K)
        {
            ans += 1 / N;
        }
        else
        {
            while (a < K)
            {
                a *= 2;
                needThrow++;
            }
            ans += (1/N) * pow(0.5, needThrow);
        }
    }

    cout << setprecision(12) << ans << endl;

}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
	
	public class Main {
	
		public static void main(String[] args) {
			execute17_1();
		}
		
		private static void execute17_2() {
			try 
			(Scanner sc = new Scanner(System.in)) {
				int n = sc.nextInt();
				
				if(n%2==0) {
					System.out.println(-1);
				} else {
					long a=0;
				}
			}
			
		}
		
		private static void execute17_1() {
			try 
			(Scanner sc = new Scanner(System.in)) {
				int n = sc.nextInt();
				String str = sc.next();
				
				char[] c = new char[n];
				
				int red=0;
				int white=0;
				for(int i=0; i<n;i++) {
					c[i] = str.charAt(i);
					if(c[i]=='R') {
						red++;
					} else {
						white++;
					}
				}
				
				long ans=0;
				for(int i=0; i<n-1;i++) {
					if(red>=i+1 && c[i]=='W') {
						ans++;
					}
					
				}
				
				System.out.println(ans);
			}
		}
    }

Measured memory_bytes: 32292
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <sstream>

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	reverse(a.begin(), a.end());
	for (int i = 0; i < n; i++)
	{
		if (i != 0)cout << " ";
		cout << a[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <cmath>

int main(int argc, char* argv[])
{
    int a, b;
    std::cin >> a;
    std::cin >> b;
    
    if (1 <= a && b <= 100)
        std::cout << a*b << " " << 2*(a+b) << std::endl;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

map<ii,ll> dp[21][21];
ll a[21];

ll calc(int l, int r, ll L, ll R)
{
	if(dp[l][r].find(mp(L,R))!=dp[l][r].end()) return dp[l][r][{L,R}];
	if(r-l<=1) return 0;
	ll ans = ll(8e18);
	for(int m=l+1;m<r;m++)
	{
		ans=min(ans,a[m]*(L+R)+calc(l,m,L,L+R)+calc(m,r,L+R,R));
	}
	return (dp[l][r][{L,R}]=ans);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	cout<<calc(0,n-1,1,1)+a[0]+a[n-1]<<'\n';
}	


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

int main() {
    int H,W; cin >> H >> W;
    string S[H]; rep(i,H) cin >> S[i];
    rep(i,W+2) cout << '#' << flush; cout << endl;
    rep(i,H) cout << '#' << S[i] << '#' << endl;
    rep(i,W+2) cout << '#' << flush; cout << endl;

    return 0;
}

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

typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++) // no semicoron
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>0;i--)
#define FORD(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
//#define PI 3.14159265359

using namespace std;

int main(){
    ll N, K;
    cin >> N >> K;

    ll count = 0; //あり得る数のカウント
    //ll sum = 0; //端数の合計算出
    ll range;
    ll min = 0;        
    ll max = 0;
    min = K * (K-1) / 2;
    max = (2 * N - K + 1) * K / 2;
    FOR(i, K, N+2){
        range = 0;
        
       
        //FOR(j, 0, i) min += j;
        //cout << min << endl;
        

        //FOR(j, N-i+1, N+1) max += j;
        //cout << max << endl;
        range = max - min + 1;

        count += range;

        min += i; //わざわざfor文で回さない
        max += N - i;
    }

    cout << count%1000000007 << endl;

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    for (ll p = 0; p <= N - 1; p++) {
        ll m = (N - 1) - p;
        ll maximum = A + p * D - m * C;
        ll minimum = A + p * C - m * D;
        if (minimum <= B && B <= maximum) {
            cout << "YES" << endl;
            return 0;
        }
    }

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

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int youki1 = A - B;
  int youki2 = C - youki1;
  
  if (youki2 >= 0) {
  	cout << youki2 << endl;
  } else {
  	cout << 0 << endl;
  }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main(void)
{
     int N,z=0;
     cin >> N;
     vector<int> a(N);
     for(int i =0;i < N;i++)
        cin >> a.at(i);

    for(int i = 0;true;i++){
        for(int j = 0;j < N;j++){
            if(a.at(j)%2 != 0){
                z=1;
                break;
            }
            a.at(j) /= 2;
        }
        if(z==1){
            cout << i << endl;
            break;
        }  
    }
                                                                   
}

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

typedef vector<double> vd;
typedef vector<vd> vvd;
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto& e:c)

typedef complex<double> P;
typedef vector<P> G;
double const inf=1e10;
double const eps=1e-8;

double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

struct L : public vector<P> {
    L(const P &a, const P &b) {
        push_back(a); push_back(b);
    }
};

int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;
    if (cross(b, c) < 0)   return -1;
    if (dot(b, c) < 0)     return +2;
    if (norm(b) < norm(c)) return -2;
    return 0;
}

P projection(const L &l, const P &p) {
    double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
    return l[0] + t*(l[0]-l[1]);
}

bool intersectSS(const L &s, const L &t) {
    return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
        ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < eps; // triangle inequality
}

bool intersectRS(const G &r, const L &l){
    if(r[0].real()<=l[0].real() && l[0].real()<=r[2].real() &&
       r[0].imag()<=l[0].imag() && l[0].imag()<=r[2].imag() &&
       r[0].real()<=l[1].real() && l[1].real()<=r[2].real() &&
       r[0].imag()<=l[1].imag() && l[1].imag()<=r[2].imag()){
        return true;
    }
    rep(i,4){
        L m(r[i],r[(i+1)%4]);
        if(intersectSS(l,m)) return true;
    }
    return false;
}

double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}

int n;
L l{0,0};
vector<G> rs;
vd hs;
vvd d;

double maxr(P p, G const& rect, double h){
    double res=inf;
    rep(i,4){
        double d=distanceSP({rect[i],rect[(i+1)%4]},p);
        if(d<h){
            res=min(res,d);
        }else{
            res=min(res,(d*d+h*h)/(2*h));
        }
    }
    // printf(" %lf\n",res);
    return res;
}

double solve(){
    double ans=inf;
    rep(i,n){
        if(intersectRS(rs[i],l)) return 0;
        rep(j,4){
            P prj = projection(l,rs[i][j]);
            if(!intersectSP(l,prj)) continue;
            ans=min(ans, maxr(prj,rs[i],hs[i]));
        }
        // printf(" %lf\n",ans);
        ans=min(ans,maxr(l[0],rs[i],hs[i]));
        ans=min(ans,maxr(l[1],rs[i],hs[i]));
    }
    return ans;
}

int main(){
    while(cin>>n && n){
        double sx,sy,ex,ey;
        cin >> sx>>sy>>ex>>ey;
        l = L{P(sx,sy),P(ex,ey)};
        rs.resize(n);
        hs.resize(n);
        rep(i,n){
            double mx,my,Mx,My;
            cin>>mx>>my>>Mx>>My >> hs[i];
            rs[i] = {P(mx,my),P(Mx,my),P(Mx,My),P(mx,My)};
        }
        printf("%.5lf\n",solve());
    }
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	// if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

const int M = 22;
int n, m;
char c[M][M];
int d[M][M], used[M][M];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool check(int x, int y){
	return x >= 0 && x < n && y >= 0 && y < m;
}
void bfs(int x, int y){
	queue<pii> q;
	q.push({x, y});
	d[x][y] = 0;
	used[x][y] = 1;
	while(!q.empty()){
		int u = q.front().F, v = q.front().S;
		q.pop();
		for(int i = 0; i < 4; ++i){
			int fx = u + dx[i], fy = v + dy[i];
			if(check(fx, fy) && !used[fx][fy] && c[fx][fy] == '.'){
				used[fx][fy] = 1;
				d[fx][fy] = d[u][v] + 1;
				q.push({fx, fy});
			}
		}
	}
}
void solve()
{	
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			cin >> c[i][j];
		}
	}
	int mx = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			if(c[i][j] != '.') continue;
			for(int k = 0; k < n; ++k) for(int t = 0; t < m; ++t) d[k][t] = inf, used[k][t] = 0;
			bfs(i, j); 	
			for(int k = 0; k < n; ++k) for(int t = 0; t < m; ++t) 
				if(d[k][t] != inf) mx = max(mx, d[k][t]);
		}
	}
	cout << mx << endl;
}

 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
nm = input().split()
n = int(nm[0])
m = int(nm[1])
a_li = []
b_li = []
for i in range(n):
    ab_li = input().split()
    a_li.append(int(ab_li[0]))
    b_li.append(int(ab_li[1]))
ab_connected = sorted(zip(a_li, b_li), key=itemgetter(0))
a_li, b_li = zip(*ab_connected)
item_count = 0
price_count = 0
for i in range(n):
    if item_count < m:
        if b_li[i] <= (m - item_count):
            item_count += b_li[i]
            price_count += a_li[i] * b_li[i]
        else:
            item_needed = 0
            item_needed = m - item_count
            item_count += item_needed
            price_count += item_needed * a_li[i]
    elif item_count == m:
        break
    else:
        print("error")
print(price_count)


Measured memory_bytes: 26748
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    string s;
    cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> s(n+1,0);
  rep(i,n) s[i+1] = s[i] + a[i];
  ll ans = INF;
  for(int k = 2; k <= n-2; k++) {
    int c = lower_bound(s.begin(),s.end(),s[k]/2) - s.begin();
    if(abs(s[k]-2*s[c]) > abs(s[k]-2*s[c-1])) c--;
    ll lmax = max(s[c],s[k]-s[c]), lmin = min(s[c],s[k]-s[c]);
    int d = lower_bound(s.begin(),s.end(),s[k]+(s[n]-s[k])/2) - s.begin();
    if(abs(s[n]-2*s[d]+s[k]) > abs(s[n]-2*s[d-1]+s[k])) d--;
    ll rmax = max(s[n]-s[d],s[d]-s[k]), rmin = min(s[n]-s[d],s[d]-s[k]);
    ll r = max(lmax,rmax), l = min(lmin,rmin);
    ans = min(ans,r-l);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

int main()
{
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  while (A>0 && C>0) {
    C-=B;
    if (C<=0)
      break;
    A-=D;
    if (A<=0)
      break;    
  }
  
  cout << (C<A? "Yes" : "No") << endl;

  return 0;
}


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

using namespace std;

const int dirx[] = {1, -1, 0, 0};
const int diry[] = {0, 0, 1, -1};

int black, white, h, w;
bool vis[405][405];
char s[405][405];


void dfs(int x, int y) {
    vis[x][y] = 1;

    if (s[x][y] == '#') black++;
    else white++;

    for (int i = 0; i < 4; i++) {
        int newx = x + dirx[i];
        int newy = y + diry[i];
        if (newx < 0 || newx >= h || newy < 0 || newy >= w) continue;
        if (s[x][y] == s[newx][newy]) continue;
        if (vis[newx][newy]) continue;
        dfs(newx, newy);
    }
}

int main() {
    scanf("%d%d", &h, &w);

    for (int i = 0; i < h; i++) scanf("%s", s[i]);

    long long res = 0;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (vis[i][j]) continue;
            black = 0;
            white = 0;
            dfs(i, j);
            res += 1LL * black * white;
        }
    }

    printf("%lld\n", res);
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
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(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0;
  ll n;cin>>n;
  vector<ll>a(n),b(n);
  rep(i,0,n)cin>>a[i]>>b[i];
  vector<P>p;
  rep(i,0,n)p.EB(a[i],i);
  rep(i,0,n)p.EB(b[i],i+n);
  sort(ALL(p));
  ll x=0,y=0;
  set<ll>st;
  bool judge=false;
  rep(i,0,n){
    if(p[i].se<n)x++;
    else y++;
    if(st.count(p[i].se%n))judge=true;
    st.insert(p[i].se%n);
    res+=p[i].fi;
  }
  if(x==0||y==0||judge)cout<<res<<endl;
  else {
    ll minbuf=INF;
    if(p[n].se%n==p[n-1].se%n){
      minbuf=res-p[n-1].fi+p[n+1].fi;
      chmin(minbuf,res-p[n-2].fi+p[n].fi);
    }
    else minbuf=res-p[n-1].fi+p[n].fi;
    cout<<minbuf<<endl;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(n==i*j){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3612
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int[][][] directedGraph(int n, int[] from, int[] to, int[] cost) {
		int[] cnt = new int[n];
		for (int i : from) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<from.length; i++) {
			int s = from[i];
			int t = to[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];
		}

		return g;
	}

	static int[][][] revGraph(int[][][] g) {
		int n = g.length;
		int[] cnt = new int[n];
		for (int i=0; i<n; i++) {
			for (int[] to : g[i]) {
				cnt[to[0]]++;
			}
		}
		int[][][] rg = new int[n][][];
		for (int i=0; i<n; i++) rg[i] = new int[cnt[i]][2];
		for (int i=0; i<n; i++) {
			for (int[] to : g[i]) {
				int s = to[0];
				int t = i;
				int c = to[1];

				rg[s][--cnt[s]][0] = t;
				rg[s][cnt[s]][1] = c;
			}
		}

		return rg;
	}

	static int[] kosaraju(int[][][] g, int[][][] rg) {
		int n = g.length;
		boolean[] visited = new boolean[n];
		boolean[] used = new boolean[n];
		int[] ord = new int[n];
		int pos = n-1;

		ArrayDeque<Integer> stack = new ArrayDeque<>();
		for (int i=0; i<n; i++) {
			if (visited[i]) continue;
			stack.addLast(i);
			while (!stack.isEmpty()) {
				int cur = stack.peekLast();
				visited[cur] = true;
				boolean pushed = false;
				for (int[] to : g[cur]) {
					int next = to[0];
					if (visited[next]) continue;
					stack.addLast(next);
					pushed = true;
				}
				if (pushed) continue;

				int t = stack.pollLast();
				if (!used[t]) {
					ord[pos--] = t;
					used[t] = true;
				}
			}
		}

		int[] res = new int[n];
		Arrays.fill(res, -1);

		int cmp = 0;
		for (int i : ord) {
			if (res[i] != -1) continue;
			stack.addLast(i);
			while (!stack.isEmpty()) {
				int cur = stack.pollLast();
				res[cur] = cmp;
				for (int[] to : rg[cur]) {
					int next = to[0];
					if (res[next] == -1) stack.addLast(next);
				}
			}
			cmp++;
		}

		return res;
	}

	static void solve() {
		int v = in.nextInt();
		int e = in.nextInt();
		int[] s = new int[e];
		int[] t = new int[e];
		int[] c = new int[e];
		for (int i=0; i<e; i++) {
			s[i] = in.nextInt();
			t[i] = in.nextInt();
			c[i] = 0;
		}

		int[][][] g = directedGraph(v, s, t, c);
		int[][][] rg = revGraph(g);

		int[] cmp = kosaraju(g, rg);

		int q = in.nextInt();
		while (q-- > 0) {
			int a = in.nextInt();
			int b = in.nextInt();
			out.println(cmp[a] == cmp[b] ? 1 : 0);
		}
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 101616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			char[] word = line.toCharArray();
			int N = Integer.parseInt(br.readLine());
			int count = 0;

			outer1:
			for (int i = 0; i < N; i++) {
				char[] ring = br.readLine().toCharArray();
				outer2:
				for (int j = 0; j < ring.length + word.length; j++) {
					if (ring[j % ring.length] == word[0]) {
						for (int k = 1; k < word.length; k++) {
							if (word[k] != ring[(j + k) % ring.length]) {
								j += k - 1;
								continue outer2;
							}
						}
						count++;
						continue outer1;
					}
				}
			}
			System.out.println(count);
		}
	}
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

PI mise[100100];
li n, m;

int main() {
    cin >> n >> m;
    rin{
        cin >> mise[i].F >> mise[i].S;
    }
    sort(mise, mise + n);

    li res = 0;
    li num = 0;
    li idx = 0;
    while (num < m) {
        if (mise[idx].S >= m - num) {
            res += (m - num) * mise[idx].F;
            break;
        } else {
            res += mise[idx].S * mise[idx].F;
            num += mise[idx].S;
        }
        idx++;
    }
    cout << res << endl;


    return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	private static ArrayList<Long> fib = new ArrayList<Long>();

	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
         long N = sc.nextLong();

         long init = 1;

         for(int i = 0; i < N+1; i++){
        	 if(i==0){fib.add(init);continue;}
        	 if(i==1){fib.add(init);continue;}
        	 fib.add(fib.get(i-2) + fib.get(i-1));
//        	 for(long l:fib){System.out.print(l+",");}
//        	 System.out.println();
         }

         System.out.println(fib.get(fib.size()-1));
	}
}

Measured memory_bytes: 17368
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include <deque>
using namespace std;

#define eta 0.01
#define eps 1e-6
double p[10], q[10];
double ans;

double F(double x) {
	double ans = 0;
	for (int i = 1; i <= 6; i++)
		if (x * p[i] > (1 - x) * q[i])
			ans += x * p[i];
		else
			ans += (1-x) * q[i];
	return ans;
}

void try1(double x) {
	ans = min(ans, F(x));
}

int main() {
	for (int i = 1; i <= 6; i++)
		scanf("%lf", &p[i]), p[i] /= 100;
	for (int i = 1; i <=6; i++)
		scanf("%lf", &q[i]), q[i] /= 100;
	ans = 1;
	try1(0);
	try1(1);
	for (int i = 1; i <= 6; i++)
		if (p[i] + q[i] > 0)
			try1(q[i] / (p[i] + q[i]));
	printf("%.10lf\n", ans);
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<int> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];

    int sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3556
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int a[3], mx = 0;
    for(int i = 0; i < 3; scanf("%d", &a[i++])){}
    for(int i = 0; i < 3; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            if(i == j)
            {
                continue;
            }
            for(int k = 0; k < 3; ++k)
            {
                if(i == k || j == k)
                {
                    continue;
                }
                mx = max(mx, 10 * a[i] + a[j] + a[k]);
            }
        }
    }
    printf("%d\n", mx);
}


Measured memory_bytes: 256