akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
	 static int divisors(long x) {
		    long limit = x;
		    int numberOfDivisors = 0;

		    if (x == 1) return 1;

		    for (int i = 1; i < limit; ++i) {
		        if (x % i == 0) {
		            limit = x / i;
		            if (limit != i) {
		                numberOfDivisors++;
		            }
		            numberOfDivisors++;
		        }
		    }

		    return numberOfDivisors;
		} 
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int n = s.nextInt();
		String i =  s.next();
		String m = "ABC";
		int c=0;
		for(int j=0;j<n-2;j++) {
			
			if(i.charAt(j)==m.charAt(0) && i.charAt(j+1)==m.charAt(1) && i.charAt(j+2)==m.charAt(2)) {
					c++;
			}
				
			
			
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 32836
module mod_radix_sort
  implicit none
  integer, private, parameter :: intkind = 4
  integer, private, parameter :: nbit = 8
  integer, private, parameter :: upper = lshift(1, nbit) - 1
contains
  subroutine radix_sort(a)
    integer(intkind), intent(inout) :: a(:)
    integer(intkind), allocatable :: queue(:, :)
    integer :: n, m, i, j, k, cnt(0:upper)
    n = size(a)
    m = 0
    do i = 0, 8 * intkind - 1, nbit
      cnt = 0
      do j = 1, n
        k = and(rshift(a(j), i), upper)
        cnt(k) = cnt(k) + 1
      end do
      m = max(m, maxval(cnt))
    end do
    allocate(queue(m, 0:upper))
    do i = 0, 8 * intkind - 1, nbit
      cnt = 0
      do j = 1, n
        k = and(rshift(a(j), i), upper)
        cnt(k) = cnt(k) + 1
        queue(cnt(k), k) = a(j)
      end do
      k = 0
      do j = 0, upper
        if (cnt(j) == 0) cycle
        a(k + 1:k + cnt(j)) = queue(1:cnt(j), j)
        k = k + cnt(j)
      end do
    end do
  end
end module mod_radix_sort
program mix_juice
  use mod_radix_sort
  implicit none
  integer :: n, k, p(1000) = 0
  read(*,*) n, k
  read(*,*) p(1:n)
  call radix_sort(p(1:n))
  write(*,'(i0)') sum(p(1:k))
end program mix_juice

Measured memory_bytes: 3400
#include<bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
#define ALL(x) x.begin(),x.end()
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;

/*--------------------template--------------------*/


int main() {
	cin >> n >> k;
	REP(i, n) {
		cin >> s;
		cout << s << endl << s << 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++)
#define ll long long

int main() {
	string s;
	cin >> s;
	int N = s.size();
	int r = 0, b = 0;
	rep(i, N) {
		if (s.at(i) == '0') r++;
		if (s.at(i) == '1') b++;
	}
	if (r >= b) {
		cout << N - r + b;
	}
	else {
		cout << N + r - b;
	}
	return 0;
}





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

li = sorted(li,key = lambda x : x[0])
drink = 0
ans = 0
for i in range(n):
  if drink + li[i][1] < m:
    ans += li[i][0]*li[i][1]
    drink += li[i][1]
  else:
    ans += li[i][0]*(m - drink)
    print(ans)
    exit()

Measured memory_bytes: 29796
n,m = map(int,input().split())
hyou = list(map(int,input().split()))
sum = 0
flg = 0

list.sort(hyou, reverse=True)

for i in range(n):
  sum += hyou[i]

sum = sum / (4 * m)
  
for i in range(m):
  if hyou[i] >= sum:
    continue
  else:
    flg = 1
    break
    
if flg == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9184
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == '#']
n = h * w - len(p)
r = 0
while n:
    r += 1
    s = []
    for i, j in p:
        for di, dj in d:
            di += i
            dj += j
            if 0 <= di < h and 0 <= dj < w and a[di][dj] == '.':
                a[di][dj] = '#'
                s.append((di, dj))
    p = s
    n -= len(p)
print(r)


Measured memory_bytes: 132432
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  ll x,y;
  std::cin >> x >> y;

  int cnt = 0;
  while(x <= y) {
    x*=2;
    ++cnt;
  }

  std::cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
int pic[51][51];
int n,m;

vector< vector<int> > rotate(int a){
    vector< vector<int> > ret(m,vector<int>(m));
    if(a == 0){
	REP(i,m)REP(j,m){
	    ret[i][j] = pic[i][j];
	}
    }else if(a == 3){
	REP(i,m)REP(j,m){
	    ret[i][j] = pic[m-1-j][i];
	}
    }else if(a == 2){
	REP(i,m)REP(j,m){
	    ret[i][j] = pic[m-1-i][m-1-j];
	}
    }else if(a == 1){
	REP(i,m)REP(j,m){
	    ret[i][j] = pic[j][m-1-i];
	}
    }
    return ret;
}

int main(){
    while(true){
	int map[101][101];
	cin >> n >> m;
	if(n==0&&m==0) break;
	memset(map,-1,sizeof(map));
	memset(pic,-1,sizeof(pic));
	REP(i,n)REP(j,n){
	    cin >> map[i][j];
	}
	REP(i,m)REP(j,m){
	    cin >> pic[i][j];
	}
	bool flg = true;
	int ansx,ansy;
	int isans = false;
	ansx = 101;
	ansy = 101;
	REP(a,4){
	    
	    vector< vector<int> > p = rotate(a);
	    for(int i=0;i+m<=n;i++){
		for(int j=0;j+m<=n;j++){
		    flg = true;
		    int il,ik;
		    il = -1;
		    ik = -1;
		    REP(k,m)REP(l,m){
			if(p[k][l]!=-1&&p[k][l]!=map[i+k][j+l]){
			    flg = false;
			    break;
			}else if(p[k][l]==map[i+k][j+l]&&il == -1 && ik == -1){
			    il = j+l+1;
			    ik = i+k+1;
			}
		    }
		    if(flg){
			if(ansy > ik){
			    ansx = il;
			    ansy = ik;
			}else if(ansy == ik && ansx > il){
			    ansx = il;
			}
			isans = true;
			break;
		    }
		}
		if(flg){
		    break;
		}
	    }
    }
	if(!isans) cout << "NA" << endl;
	else cout << ansx << " " << ansy << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
  string S; cin >> S;
  bool n = false, s = false, e = false, w = false;

  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == 'N') n = true;
    else if (S[i] == 'S') s = true;
    else if (S[i] == 'E') e = true;
    else if (S[i] == 'W') w = true;
  }

  if (n^s || e^w) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

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 FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
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 pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

vector<P>G[MAX];
int x[MAX];
bool used[MAX];
vector<int>ans;
int dfs(int v) {
	used[v] = true;
	int res = x[v];
	for (P nxt : G[v]) {
		if (used[nxt.first])continue;
		int r = dfs(nxt.first);
		if (r) {
			ans.push_back(nxt.second);
			res ^= 1;
		}
	}
	return res;
}
void solve() {
	int N, M; cin >> N >> M;
	vector<P>A(N);
	REP(i, N)cin >> A[i].first >> A[i].second;
	VSORT(A);
	x[0] = A[0].second;
	REP(i, N - 1) {
		x[i + 1] = A[i].second^A[i + 1].second;
	}
	x[N] = A[N - 1].second;
	REP(i, M) {
		int l, r; cin >> l >> r;
		l = lower_bound(all(A), P( l,0 )) - A.begin();
		r = upper_bound(all(A), P( r,1 )) - A.begin();
		G[l].push_back({ r,i + 1 });
		G[r].push_back({ l,i + 1 });
	}
	REP(i, N + 1) {
		if (used[i])continue;
		if (dfs(i)) {
			print(-1); return;
		}
	}
	print(ans.size());
	VSORT(ans);
	print_space(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


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

int main(){
  string s, t; cin >> s >> t;
  bool ok = false;
  for(int i = 0; i < s.size(); i++){
    char c = s.at(s.size()-1);
    s.pop_back();
    s = c + s;
    if(s == t){
      ok = true;
      break;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
int p,q,r;
cin>>p>>q>>r;
int a[3]={p+q,q+r,p+r};

int index=min_element(a,a+3)-a;

cout<<a[index]<<endl;



return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> d(N, INF);
  d[0] = 0;
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    for (int w : E[v]){
      if (d[w] == INF){
        d[w] = d[v] + 1;
        Q.push(w);
      }
    }
  }
  int s = 0;
  for (int i = 0; i < N; i++){
    if (d[i] > d[s]){
      s = i;
    }
  }
  vector<int> d2(N, INF);
  d2[s] = 0;
  queue<int> Q2;
  Q2.push(s);
  while (!Q2.empty()){
    int v = Q2.front();
    Q2.pop();
    for (int w : E[v]){
      if (d2[w] == INF){
        d2[w] = d2[v] + 1;
        Q2.push(w);
      }
    }
  }
  int t = 0;
  for (int i = 0; i < N; i++){
    if (d2[i] > d2[t]){
      t = i;
    }
  }
  if (d2[t] % 3 == 1){
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }
}

Measured memory_bytes: 17356
//By Krishna Yadav
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define testcase(t) int t; cin>>t; while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<ln
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef map<int, int> m32;
const int LIM = 2e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;

int main(){
  fastio;
  int n, m, c, count = 0;
  cin>>n>>m>>c;
  int A[m], B[m];
  forn(i, m) cin>>B[i];
  forn(i, n){
    forn(i, m) cin>>A[i];
    int sum = c;
    forn(i, m) sum+=(A[i]*B[i]);
    if(sum > 0) count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    double a,b,c,d;
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    printf("%.8lf\n",(sqrt((c-a)*(c-a)+(d-b)*(d-b))));
    return 0;
}

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

int main() {
  int N;
  int sum = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    
    if (S == "Y") {
      sum = sum + 1;
    }    
  }
  
  if (sum > 0) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	Scanner stdin = new Scanner(System.in);
	
	int i = 0;
	int[] read = new int[123456];

	while(stdin.hasNext()) {
	    read[i] = stdin.nextInt();
	    i++;
	}	

	i = 0;
	while(read[i] != 0) {
	    System.out.println(Pcount(read[i]));
	    i++;
	}
    }


    //与えられた整数に対して、n < x <= 2*n の素数を探し個数を数え返却する
    static int Pcount(int a) {
	int count = 0;
	for(int i = (a+1); i <= 2*a; i++) {
	    if(isPrime(i)) count++;
	}
	return count;	
    }

    //ある数が素数かどうか判定する
    static boolean isPrime(int n) {
	int f = (int)Math.sqrt(n);
	while((n % f)  > 0) f--;
	return f == 1;
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=55;
int n,m,d,prt[Maxn],sz[Maxn],id[Maxn];
ll cost[Maxn],f[Maxn][Maxn*Maxn*Maxn],ans;
vector<int>son[Maxn];
void upd(ll&x,ll y){x=min(x,y);}
int main(){
    scanf("%d%d%d",&n,&m,&d);
    scanf("%lld",&cost[1]);
    for(int i=2;i<=n;i++){
        scanf("%lld%d",&cost[i],&prt[i]);
        son[prt[i]].push_back(i);
    }
    for(int i=1;i<=n;i++)id[i]=i;
    for(int x=n;x>=1;x--){
        sz[x]=1;
        for(int y:son[x]){
            sz[x]+=sz[y];
            cost[x]+=cost[y];
        }
    }
    sort(id+1,id+n+1,[](int x,int y){
        return sz[x]*cost[y]>sz[y]*cost[x];
    });
    memset(f,0x3f,sizeof(f));
    f[0][0]=0;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=n*n*n;j++)
            for(int k=0;k<=min(n,i==1?INT_MAX:d)&&k*sz[i]<=j;k++)
                upd(f[i][j],f[i-1][j-k*sz[i]]+cost[i]*k);
    for(int j=0;j<=n*n*n;j++){
        ll left=m-f[n][j],sum=j;
        if(left<0)continue;
        for(int i=1;i<=n;i++){
            ll cnt=min(id[i]==1?LLONG_MAX:max(0,d-n),left/cost[id[i]]);
            sum+=cnt*sz[id[i]];left-=cnt*cost[id[i]];
        }
        ans=max(ans,sum);
    }
    cout<<ans<<"\n";
    return 0;
}

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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

ll T,n,m;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    double r;
    cin >> r;
    cout << 3.1426 * 2 * r;
 
    return 0;
}


Measured memory_bytes: 3800
#include<stdio.h>
int main()
{
    long int a,b,c,d;
    long long int A,B,C,D;
    scanf("%ld %ld",&a,&b);
    scanf("%ld %ld",&c,&d);
    
    A=a*c;
    B=b*c;
    C=a*d;
    D=b*d;
    long int temp=A;
    if(A>B)
    {
        temp = A;
        A=B;
        B=temp;
    }
    if(B>C)
    {
        
        temp=B;
        B=C;
        C=temp;
    }
    if(C>D)
    {
        
        temp=C;
        C=D;
        D=temp;
    }
    if(D>A)
    {
        temp=D;
        D=A;
        A=temp;
    }
    if(A>B)
    {
        
        temp=A;
        A=B;
        B=temp;
    }
    printf("%ld\n",temp);
    return 0;
    
}



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

left = 0
right = 0
ans = 0
tmp = 0

for left in range(N):
    while right < N and tmp + A[right] == tmp ^ A[right]:
        tmp += A[right]
        right += 1
        
    ans += right - left
    
    if right == left:
        right += 1
    else:
        tmp -= A[left]
        
print(ans)

Measured memory_bytes: 24840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
    if (y == 0) return x;
    return gcd(y, x%y);
}
ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}
int main(void){
    ll n,m;cin>>n>>m;
    vector<ll> b(n);
    ll xx=-1;
    for(int i=0;i<n;i++){
        cin>>b[i];b[i]/=2;
        if(xx==-1){
            ll x=b[i];
            while(x>0){
                if(x%2!=0){
                    xx=b[i]/x;
                    break;
                }
                x/=2;
            }
        }else{
            if((b[i]/xx)%2==0){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    ll L=b[0];
    for(int i=0;i<n;i++){
        L=lcm(L,b[i]);
    }
    ll res=m/L;
    if(res%2!=0){
        res/=2;
        res++;
    }else{
        res/=2;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 1024
from numba import jit
@jit
def main():
  n,k=map(int,input().split(" "))
  p=list(map(int,input().split(" ")))
  c=list(map(int,input().split(" ")))
  ans=-10**18
  for i in range(n):
    start,count=i,1
    val=c[start]
    while p[start]-1!=i: #ループ部分. iに戻る直前まで続ける.
      start=p[start]-1
      count+=1
      val+=c[start]
    start=i
    # この時点でvalは1ループのスコア合計, カウントは1ループのsizeになっている
    '''
    以下の基本的な方針は
    - 1ループ分のスコア合計が正であればできるだけループしてスコアを稼ぎ、残りの余りの分の最大をとる。
    - 1ループ分のスコア合計が負であればループ回数を0にして、1ループ以内で最大となる移動を求める。
    しかし、ループ回数が最大であればいいとは限らない。
    x回ループできたとしてcount%k回の余りの分を調べても、x-1回ループし次の1回のループのなかで1周仕切らない移動が最大になる可能性がある。
    なのでx-1回分のループだけ取り切ってしまい、残りcount+k%count(＝「1周半」)の中で最大を調べる必要がある。
    また、負の場合は基本的に1周以内だが、kが極端に小さいときの処理が必要。
    '''
    if val>0:
      a=(k//count-1)*val  # 最後に余りのk%count回ぶんだけでなく1周半ぶんは試したいので(ループ余りではk%count回しか移動できないわけではない)
      ans=max(a,ans)
      num=count+k%count
    else:
      a=0
      num=min(k,count)  # 1周以内におさめたい. k<countという非常に限られた場合のみk回までの移動になることを考慮。
    for _ in range(num):
      start=p[start]-1
      a+=c[start]
      ans=max(a,ans)
  print(ans)
main()


Measured memory_bytes: 120288
import java.util.*

enum class TriangleType{
    None, Acute, Obtuse, Right
}
fun triangleType(a:Int, b:Int, c:Int): TriangleType{
    val (x, y, z) = listOf(a, b, c).sorted()
    return when{
        z >= x + y -> TriangleType.None
        z * z > x * x + y * y -> TriangleType.Obtuse
        z * z == x * x + y * y -> TriangleType.Right
        else -> TriangleType.Acute
    }
}
fun main(args:Array<String>): Unit {
    val memo = Stack<TriangleType>()
    while(true){
        val (a, b, c) = readLine()!!.trim().split(' ').map(String::toInt)
        val type = triangleType(a, b, c)
        when(type){
            TriangleType.None -> {
                println("${memo.size} ${memo.count { it == TriangleType.Right }} ${memo.count{it == TriangleType.Acute}} ${memo.count{it == TriangleType.Obtuse}}")
                return
            }
            else -> memo.push(type)
        }
    }
}


Measured memory_bytes: 27376
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
import numpy as np
for i in range(len(A)-1):
    for k in range(i+1,len(A)):
        ans.append(np.sqrt(((A[i][0]-A[k][0])**2)+(A[i][1]-A[k][1])**2))
print(sum(ans)*2/N)

Measured memory_bytes: 27140
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>; //pop_back pop_front push_back push_front front back clear empty
using L = vector<long long>;
using M = map<int,long long>;  //erase  (でキーごと削除) 追加削除検索O(log(N))
using A = vector<vector<long long>>;
using U = unordered_map<int,long long>; //map  (との違いはkeyの順番を保持していない)
using PQL = priority_queue<long long>; //erase  (でキーごと削除) push pop top 
using PQG = priority_queue<long long,L,greater<long long>>; //erase  (でキーごと削除) push pop top 

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define vdel(vector,a) vector.erase(vector.begin()+a)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define max max<unsigned long>
#define min min<unsigned long>
#define inf 1000000000000000000+10
#define setans long long ans=0;

long long MOD=1000000007;

template <typename PQ>
long long pqsum(PQ pq){long long tmp=0;while(!pq.empty()){tmp+=pq.top();pq.pop();};return tmp;};

template <typename T>
void print(T a){for (auto b:a){cout<<b<<" ";};cout<<endl;}
template <>
void print(unsigned long a){cout<<a<<endl;}
template <>
void print(char a){cout<<a<<endl;}
template <>
void print(bool a){cout<<a<<endl;}
template <>
void print(long long a){cout<<a<<endl;}
template <>
void print(A a){for (auto b:a){for (auto c:b){cout<<c<<" ";}cout<<endl;};cout<<endl;}
template <>
void print(string a){cout<<a<<endl;}



//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ
//printf("%.16f", ans); 誤差落ち対応君

vector<long long> cumsum(vector<long long> numbers){
    for(int i=1  ;i<numbers.size()  ;i++){
        numbers[i]+=numbers[i-1];
    }
    return numbers;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    long long n,x;
    cin>>n>>x;
    L a(n+1,0);
    for(long long i=1  ;i<n+1  ;i++){
        cin>>a[i];
    }
    L b=cumsum(a);
    setans;
    //print(b);
    for(long long i=0  ;i<b.size()  ;i++){
        ans+=b[i]<=x;
    }
    
    print(ans);
}


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

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  cout << endl;
  for(int i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0; i<n; i++) cin >> a[i];

  ll ans = 0;
  for(int i=1; i<n; i++){
    if(a[i-1] > a[i]){
      ans += a[i-1] - a[i];
      a[i] += a[i-1] - a[i];
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 4836
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
alp = "abcdefghijklmnopqrstuvwxyz"
dir = [(-1,0),(0,-1),(1,0),(0,1)]

#UnionFindのクラス,0-indexed
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    h,w = map(int,ipt().split())
    brd = [input()+"-" for i in range(h)]
    brd.append("-"*(w+1))
    d = {"#":0, ".":1, "-":-4}
    al = [True]*(h*w)
    ans = 0

    for i in range(h):
        for j in range(w):
            if al[i*w+j]:
                q = [(i,j)]
                al[i*w+j] = False
                nm = [0,0]
                nm[d[brd[i][j]]] += 1
                while q:
                    qi,qj = q.pop()
                    qs = d[brd[qi][qj]]
                    for di,dj in dir:
                         ni = qi+di
                         nj = qj+dj
                         if d[brd[ni][nj]] == 1-qs and al[ni*w+nj]:
                             al[ni*w+nj] = False
                             nm[1-qs] += 1
                             q.append((ni,nj))
                ans += nm[0]*nm[1]

    print(ans)





    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 81412
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	ll N;
	cin >> N;
	string res;
	while (N) {
		--N;
		res.push_back('a' + N % 26);
		N /= 26;
	}
	REV(res);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3644
n,x = map(int,input().split())
a=list(map(int,input().split()))

a=sorted(a)

ans= 0

for i in range(n-1):
    if x>=a[i]:
        ans+=1
        x-=a[i]
    else:
        break

if x==a[n-1]:
    ans+=1

print(ans)

Measured memory_bytes: 9176
MOD = 10 ** 9 + 7
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = (cmb(n-1,r) + cmb(n-1,r-1)) % MOD
    return nCr[(n,r)]

s = int(input())
surplus = s % 3
s -= surplus

ans = 0
while s > 0:
    ans = (ans +cmb(s//3 + surplus - 1, surplus)) % MOD
    s -= 3
    surplus += 3

print(ans)

Measured memory_bytes: 180012
H,W = map(int,input().split())
S = []

S.append(list('@'*(W+2)))
for i in range(H):
  s = list(input())
  s.insert(0,'@')
  s.append('@')
  S.append(s)
S.append(list('@'*(W+2)))

judge = 1 #1: 可,0:不可
count = 0
vy = [0,0,1,-1]
vx = [1,-1,0,0]
for i in range(H+2):
  if(count == 4): break  
  if((i != 0)and(i != H+1)):    
   for j in range(W+2):
    if(count == 4): break  
    if((j != 0)and(j != W+1)):
      if(S[i][j] == '#'):
        count = 0
        for k in range(4):
          if(S[i+vy[k]][j+vx[k]] == '#'): break
          count += 1
        if(count == 4):
          judge = 0
          break

if(judge == 1):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>

#define REP(i,n) for(int i=0; i<n; ++i)
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v;
    REP(i,n*2){
        int a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    int sum=0;
    REP(i,n){
        sum += v[2*i];
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

def resolve():
    n=int(input().strip())
    la= list(map(int,input().strip().split()))

    res="APPROVED"

    for a in la:
        if a%2==0:
            if a%3==0 or a%5==0:
                a=1
            else:
                res="DENIED"

    print(res)

resolve()

Measured memory_bytes: 51056
# Fast IO (be careful about bytestring, not on interactive)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N = int(input())

sumList = []
subList = []

for _ in range(N):
    x,y = map(int,input().split())
    sumList.append(x + y)
    subList.append(x - y)

print(max(max(sumList) - min(sumList),max(subList) - min(subList)))

Measured memory_bytes: 88448
#include<stdio.h>

int main(void){
int a,b;
int x=0;

scanf("%d",&a);
scanf("%d",&b);

for(int i=0;i<2;i++){
if(a>=b){
x+=a;
a--;
}
else if(b>a){
x+=b;
b--;
}
}

printf("%d\n",x);

}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int ans = 0;
        if (x == 1 && y == 1) {
            ans += 400000;
        }
        if (x == 1) {
            ans += 300000;
        } else if (x == 2) {
            ans += 200000;
        } else if (x == 3) {
            ans += 100000;
        }
        if (y == 1) {
            ans += 300000;
        } else if (y == 2) {
            ans += 200000;
        } else if (y == 3) {
            ans += 100000;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
//#include"stdc++.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define cases ll t;cin>>t;while(t--)
#define md 1000000007
int main() {
    fast
    ll n,m;
    cin>>n>>m;
    string st[1001];
    for(ll i=0;i<n;i++)
        cin>>st[i];
    
    ll dist[1001][1001];
    memset(dist,0,sizeof(dist));
    
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            if(i==0&&j==0)
                dist[i][j]=1;
            if(st[i][j]=='.')
            {
                if(st[i+1][j]=='.')
                    dist[i+1][j]=(dist[i][j]+dist[i+1][j])%md;
                if(st[i][j+1]=='.')
                    dist[i][j+1]=(dist[i][j+1]+dist[i][j])%md;
            }
        }
    }
    
    cout<<dist[n-1][m-1];
    
    return 0;
}




Measured memory_bytes: 9088
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int H; cin >> H;
  int W; cin >> W;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      string s;
      cin >> s;
      if (s == "snuke") {
        string ans;
        ans += ('A' + j);
        cout << ans << (i+1) << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <iostream>
#include <vector>]
#include <cmath>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	double d = (a + b) * 0.5;
	cout << ceil(d);
	return 0;
}

const int mod = 1000000007;
struct mint {
	long long x; // typedef long long ll;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(long long t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc169/tasks/abc169_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B = 0;
    string s;
    cin >> A >> s;
    int pos = 0;
    REP(i, s.length()) {
        if (s[i] == '.') {
            pos = s.length() - i - 1;
        } else {
            B *= 10;
            B += s[i] - '0';
        }
    }
    cout << A * B / (int)powf(10, pos) << endl;

    return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <stack>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
const int mxn = 1e6+10;
const int mod = 1e9+7;
long long fact[mxn], inv_fact[mxn];

long long powmod(long long a, long long b) {
	long long ret = 1;
	while(b) {
		if(b&1ll) ret*=a, ret%=mod;
		a*=a; a%=mod;
		b>>=1;
	}
	return ret;
}

void pre() {
	fact[0] = inv_fact[0] = 1;
	for(int i=1; i<mxn; i++) {
		fact[i] = fact[i-1]*i%mod;
		inv_fact[i] = powmod(fact[i], mod-2);
	}
}

long long C(long long n, long long k) {
	if(n<k) return 0;
	return fact[n]*inv_fact[k]%mod*inv_fact[n-k]%mod;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	pre();

	int n; cin>>n;
	if(n==2) {
		cout << 1<< '\n'; return 0;
	}

	vector<long long> allBlack(n+1, 0);

	for(int k=1; k<n; k++) {
		allBlack[k] = C(k-1, n-k-1)*fact[k]%mod*fact[n-k-1]%mod;
	}

	long long ans = 0;
	for(int k=1; k<n; k++) {
		ans = ans+(allBlack[k]+mod-allBlack[k-1])*k%mod;
		ans%=mod;
	}

	cout << ans << '\n';

	return 0;
}
//comparator function in sorting
//swapping arguments
//missing cases in dp
//dividing in modulo
//Beware of overflow and modulo
//Be mindful of overflow
//s is a matrix but forget
//length of ranges
//working with bit using ull

Measured memory_bytes: 26632
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

vvll edges;
vll d;

ll dfs(ll i) {
    if (d[i]!=-1) return d[i];
    else {
        d[i] = 0;
        for (auto j: edges[i]) chmax(d[i], dfs(j)+1);
        return d[i];
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    edges.resize(n);
    d.resize(n, -1);
    REP(_, m) {
        ll x, y; cin >> x >> y;
        edges[x-1].push_back(y-1);
    }
    ll ans = 0;
    REP(i, n) chmax(ans, dfs(i));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 7936
#include<iostream>

using namespace std;
     int main(){
        int x,y;
        while(cin>>x>>y){
           if(x==0 && y==0){
           return 0;
           }
           else if(x<y){
              cout<<x<<" "<<y<<endl;
           }     
           else{
               cout<<y<<" "<<x<<endl;
               }
           }
           }

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n)    FOR(i, 0, n)
#define pb           push_back
#define all(a)       (a).begin(), (a).end()
#define UNIQUE(v)    v.erase(unique(all(v)), v.end());
#define fill(a, x)   memset(a, x, sizeof(a))
#define zero(a)      fill(a, 0)
#define minus(a)     fill(a, -1)
#define dbg(x)       cout << #x "=" << x << endl

struct Point {
  double x;
  double y;
};

// Stackで実装してみるのも良さそう
void koch(int n, Point a, Point b) {
  if (n == 0) {
    return;
  }

  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}

int main() {
  // ios::sync_with_stdio(false);

  int n;
  cin >> n;

  Point ss = {0.00000000, 0.00000000};
  Point ll = {100.00000000, 0.00000000};

  printf("%.8f %.8f\n", ss.x, ss.y);
  koch(n, ss, ll);
  printf("%.8f %.8f\n", ll.x, ll.y);

  return 0;
}



Measured memory_bytes: 3216
# Author: cr4zjh0bp
# Created: Sat Mar 14 11:05:23 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

r, g = nin(2)

print(2 * g - r)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int inf = 1000000000; // 10^9

int com_dsc_int(const void *n1,const void *n2){
   if(*(int*)n1 < *(int*)n2)return 1;
   else if(*(int*)n1 > *(int*)n2)return -1;
   else return 0;
}

int main(){
   int n;scanf("%d",&n);
   int a[100];
   for(int i = 0;i < n;i++)scanf("%d",&a[i]);
   qsort(a,n,sizeof(int),com_dsc_int);
   int ali=0,bob=0;
   for(int i = 0;i < (n%2==0?n:n-1);i+=2){
      ali+=a[i];
      bob+=a[i+1];
   }
   ali +=(n%2==0?0:a[n-1]);
   printf("%d",ali-bob);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll n,h[100010],ans=0;


void init(){
	cin>>n;
	rep(i,n)cin>>h[i];
}

int main(void){
	init();
	ll t=1,b=-1;
	rep(i,n){
		if(b>=h[i]){
			t++;
		}else{
			t=1;
		}
		// cerr<<i<<":"<<t<<endl;
		ans=max(ans,t);
		b=h[i];
	}
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 1024
def main():
    N = int(input())
    li = list(map(int, input().split()))

    num_of_operation = 0
    is_dividable = True

    while True:
        for num in li:
            if num % 2 != 0:
                is_dividable = False
                break

        if not is_dividable:
            break

        for i in range(N):
            li[i] //= 2
        num_of_operation += 1

    print(num_of_operation)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
#include <stdio.h>

int main(void){
    int a, b;
    char op;

    while(1){
         scanf("%d %c %d", &a, &op, &b);
         if(op == '?')
             break;
         switch(op){
             case '+':
                  printf("%d\n", a + b);
                  break;
             case '-':
                  printf("%d\n", a - b);
                  break;
             case '*':
                  printf("%d\n", a * b);
                  break;
             case '/':
                  printf("%d\n", a / b);
                  break;
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    vector<int> vec(5);
    for(int i=0;i<5;i++) cin >> vec[i];
    for(int i=0;i<5;i++){
        if(vec[i]==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3628
#include <cstdio>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN=1005;
char str[MAXN];
int main()
{
    int flag=0;
    scanf("%s", str);
    for(int i=0;i<strlen(str)-1;++i)
    {
        if(str[i]==str[i+1]&&str[i+1]==str[i+2])
            flag=1;
    }
    if(flag)
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
n = input()

#文字列nを１文字ずつリストに入れる
#l = [0]*4 これは不要
l = list(n)

#print(l)

ans = 'Good'

for i in range(3):
	if l[i]==l[i+1]:
		ans = 'Bad'
		break

print(ans)




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

int main() {
  int N, A;
  
  cin >> N >> A;
  
  int X = N % 500;
  
  if(X <= A){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long n,i,j,ans=0;
  scanf("%lld",&n);
  if(n!=2)ans=n-1;
  for(i=2;i*i<n;i++){
    if(n%i)continue;
    j=n/i;
    if(n/(i-1)==n%(i-1))ans+=i-1;
    if(n/(j-1)==n%(j-1))ans+=j-1;//printf("%d\n",ans);
  }
  if(i*i==n){
    if(n/(i-1)==n%(i-1))ans+=i-1;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

map<char, int> mm;

bool check()
{
    if (mm['N'] > 0 && mm['S'] == 0) return false;
    if (mm['S'] > 0 && mm['N'] == 0) return false;

    if (mm['E'] > 0 && mm['W'] == 0) return false;
    if (mm['W'] > 0 && mm['E'] == 0) return false;

    return true;
}

int main()
{
    string s; cin >> s;

    for (char &c: s) mm[c]++;

    cout << (check() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,b) for(int i=a;i<=b;i++)
int n,m,k,l,r;
LL f[505][505];
inline int read(){
    int x=0,h=1; char ch=getchar();
    while (ch<'0'||ch>'9') { if (ch=='-') h=-1; ch=getchar(); }
    while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
    return x*h;
}
int main()
{
	n=read(),m=read(),k=read();
	rep(i,1,m)
	{
		l=read(),r=read();
		f[l][r]++;
	}
	rep(i,1,500)rep(j,1,500)f[i][j]+=f[i][j-1]+f[i-1][j]-f[i-1][j-1];
	rep(i,1,k)
	{
		l=read(),r=read();
		l--;
		cout<<f[r][r]-f[l][r]-f[r][l]+f[l][l]<<endl;
	}
}


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

public class Main {

	static int n, h, a[][];
	
	public static boolean judge(int x) {
		long d = 0;
		int c = 0;
		for(int i = n - 1; i >= 0; --i) {
			if(a[1][i] >= a[0][n - 1]) {
				d += a[1][i];
				c++;
				if(d >= h) {
					if(c <= x)
					return true;
					else return false;
				}
			}
			else break;
		}
		long tmp = (h - d) / a[0][n - 1];
		if((h - d) % a[0][n - 1] != 0)tmp++;
		if(x - c < tmp)return false;
		return true;
	}
	
	public static int solve() {
		int l = 0, r = 1000000000;
		int mid = (r + l) /2;
		while(1 + l < r) {
			mid = (r + l) / 2;
			if(judge(mid))r = mid;
			else l = mid;
		}
		return r;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt(); h = sc.nextInt();
		a = new int[2][n];
		for(int i = 0; i < n; ++i) {
			a[0][i] = sc.nextInt();
			a[1][i] = sc.nextInt();
		}
		Arrays.sort(a[0]);
		Arrays.sort(a[1]);
		sc.close();
		int ans = solve();
		System.out.println(ans);
	}

}


Measured memory_bytes: 80896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll ans;
ll r,g,b;
r=g=b=0;
string s;
int n;
cin>>n;
cin>>s;
for(int i=0;i<n;i++)
{
    if(s[i]=='R')
        r++;
    if(s[i]=='G')
        g++;
    if(s[i]=='B')
        b++;
}
ans=r*g*b;
//cout<<ans<<endl;
for(int i=1;i<=(n-1)/2;i++)
    for(int k=0;k<n-2*i;k++)
{
    if(s[k]!=s[k+i]&&s[k+i]!=s[k+i+i]&&s[k]!=s[k+i+i])
        ans--;
}
cout<<ans<<endl;
}



Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>

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

using namespace std;

const int M=1000000007;

int main(){
	while(1){
		char a[64],b[64],c[64];
		scanf("%s%s%s",a,b,c);
		if(a[0]=='0') break;

		int len=strlen(a);
		int dp[64][2]={}; // dp[x][y] := ( x 桁目以下の部分問題についての解 with x 桁目の carry が y )
		dp[len][0]=1;
		for(int x=len-1;x>=0;x--){
			rep(i,10) if((x>0 || i>0) && (a[x]=='?' || a[x]==i+'0'))
			rep(j,10) if((x>0 || j>0) && (b[x]=='?' || b[x]==j+'0'))
			rep(k,10) if((x>0 || k>0) && (c[x]=='?' || c[x]==k+'0')) {
				// 一つ下の桁からの carry がないとき
				if((i+j)%10==k){
					dp[x][(i+j)/10]+=dp[x+1][0];
					dp[x][(i+j)/10]%=M;
				}
				// 一つ下の桁からの carry があるとき
				if((i+j+1)%10==k){
					dp[x][(i+j+1)/10]+=dp[x+1][1];
					dp[x][(i+j+1)/10]%=M;
				}
			}
		}

		printf("%d\n",dp[0][0]);
	}

	return 0;
}

Measured memory_bytes: 972