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



public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int kazu = sc.nextInt();//お菓子の数
			if(kazu == 0){
				break;
			}
			int[][] okasi = new int[kazu][4];
			for(int i=0;i<kazu;i++){
				okasi[i][0] = sc.nextInt();//お菓子の番号
				okasi[i][1] = sc.nextInt();//たんぱく質の重量
				okasi[i][2] = sc.nextInt();//資質の重量
				okasi[i][3] = sc.nextInt();//炭水化物の重量
			}
			int[] seigen = new int[4];
			for(int i=0;i<4;i++){
				seigen[i] = sc.nextInt();
			}
			int NAflg = 0;
			//制限を越えているか判定
			for(int i=0;i<kazu;i++){
				if(okasi[i][1] > seigen[0] |
				   okasi[i][2] > seigen[1] |
				   okasi[i][3] > seigen[2] |
				   (okasi[i][1] + okasi[i][3])* 4 + okasi[i][2] * 9 > seigen[3]){
					NAflg++;
					continue;
				}
				System.out.println(okasi[i][0]);
			}
			if(NAflg == kazu){
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 13000
t1, t2 = map(int, input().split())
a1,a2 = map(int, input().split())
b1, b2 = map(int, input().split())
#t1で生まれる差
P = (a1 - b1) * t1
#t2で生まれる差
Q = (a2 - b2) * t2
#P < 0 のことを仮定する
if P > 0:
    P *= -1
    Q *= -1

if P + Q < 0:
    print(0)
elif P + Q == 0:
    print("infinity")
else:
    #つぎのPを足したときに、負にいくかどうか？
    i = P * (-1)
    if i % (P + Q) == 0:
        print(2 * (i // (P + Q)))
    else:
        print(2 * (i // (P + Q)) + 1)


Measured memory_bytes: 38256
#include <iostream>

using namespace std;

const int MAXN = 3007, MOD = 1000000007;
int R[MAXN], N, M, dp[MAXN][MAXN];
bool S[MAXN];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= N; ++i) {
		char ch;
		cin >> ch;
		S[i] = ch - '0';
	}
	for (int i = 0; i < M; ++i) {
		int l, r;
		cin >> l >> r;
		R[l] = max(R[l], r);
	}

	dp[0][0] = 1;
	for (int i = 1; i <= N; ++i) {
		R[i] = max(i, max(R[i], R[i - 1]));
		int add = 0;
		for (int j = R[i - 1] + 1; j <= R[i]; ++j) add += S[j];

		for (int j = 0; j <= N; ++j) if (dp[i - 1][j]) {
			if (j + add <= R[i] - i) {
				dp[i][j + add] += dp[i - 1][j];
				if (dp[i][j + add] >= MOD) dp[i][j + add] -= MOD;
			}
			if (j + add - 1 >= 0) {
				dp[i][j + add - 1] += dp[i - 1][j];
				if (dp[i][j + add - 1] >= MOD) dp[i][j + add - 1] -= MOD;
			}
		}
	}

	cout << dp[N][0] << endl;
}

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

int findsum(int n){
    int sum=0;
    while (n>0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main(){
 int n,a,b;
 cin >> n >> a >> b;
 int count = 0;
 for(int i=1;i<n+1;i++){
     if(a<=findsum(i)&&findsum(i)<=b) count+=i;
 }
 cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
   
   int a, b, c;
   cin >> a >> b >> c;

   int d = a+b+c;
   if(d>=22) cout << "bust";
   else cout << "win";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, count1 = 0, count2 = 0, a;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
        A.at(i)--;
    }
    for (int i = 0; i < N - 1; i++) {
        if (i == A.at(i) && A.at(i + 1) == i + 1) {
            count1++;
            i++;
        }
        else if (A.at(i) == i) {
            count2++;
        }
        a = i;
    }
    if (A.at(N - 1) == N - 1 && a != N - 1) {
        count2++;
    }
    cout << count1 + count2 << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[110],fro[110];
int main()
{
    int n,sum=0,minn=1000000000;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    fro[1]=a[1];
    for(int i=2;i<=n;i++)
    {
        fro[i]=fro[i-1]+a[i];
        int k=abs(fro[i]-(sum-fro[i]));
        if(k<minn) minn=k;
    }
    printf("%d\n",minn);
    return 0;
}


Measured memory_bytes: 128
def average_length(s, t, a, b, u):
    if u == s:
        return str(a - 1) + ' ' + str(b)
    elif u == t:
        return str(a) + ' ' + str(b - 1)
    return

if __name__ == "__main__":
    s, t = map(str, input().split())
    a, b = map(int, input().split())
    u = input()
    print(average_length(s, t, a, b, u))

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

using namespace std;

//#define ll long long
typedef long long ll;

int main(){
  ll L, R, begin, end;
  cin >> L >> R;
  int ans = 2018;
  if((R-L)>= 2018) cout << 0 << endl;
  else{
    for(ll i = L; i <= R-1; i++){
      for(ll j = i+1; j <= R; j++){
        int x = (i*j)%2019;
        ans = min(x, ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    string s, t ;
    ll ans = 0 ;
    cin >> s >> t ;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i])   ans++ ;
    }
    cout << ans ;

    return 0 ;
}


Measured memory_bytes: 3912
a = gets.split.map(&:to_i)
if a[0] == 1 && a[1] ==1
  puts 1
elsif a[0] == 1 || a[1] ==1
  puts a[0] * a[1] - 2
else
  puts a[0]*a[1] - 2*a[0] -2*a[1] + 4
end

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

int main(){
  int tmp;
  while(1){
    int n;
    cin >> n;
    if(n == 0) break;
    int p,d1,d2;
    int ansp,ansd = -1;

    for(int i = 0;i < n;i++){
      cin >> p >> d1 >> d2;
      if(d1 + d2 > ansd){
        ansp = p;
        ansd = d1 + d2;
      }
    }

    cout << ansp << " " << ansd << endl;
  }

  return 0;
}







Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  for (int count = 0; count < W + 2; count++) {
    cout << "#";
  }
  cout << endl;
  
  for (int i = 0; i < H; i++) {
    cout << '#';
    vector <char> v_i (W);
    for (int j = 0; j < W; j++) {
      cin >> v_i.at(j);
    }
    v_i.push_back('#');
    for (int k = 0; k < W + 1; k++) {
      cout << v_i.at(k);
    }
    cout << endl;
  }
  
  for (int count_ = 0; count_ < W + 2; count_++) {
    cout << "#";
  }
  cout << endl;
  
}

Measured memory_bytes: 256
class GenomeDB
  class GenomeData
    def initialize
      @length = 0
      @num = 0
      @data_array = []
    end

    attr_accessor :num

    def size
      @length
    end

    def << data
      @length += data.size * @num
      @data_array << data
      self
    end

    def [] i
      return nil if i >= @length
      index = i
      @num.times do
        @data_array.each do |data|
          if index >= data.size
            index -= data.size
            next
          end
          return data[index]
        end
      end
    end
  end

  class << self
    def parse seq
      result = GenomeData.new
      result.num = 1
      data_array = genome_parse(seq, 0).first
      if data_array.instance_of?(Array)
        data_array.each do |data|
          result << data
        end
      else
        result << data_array
      end
      result
    end

    private
    def genome_parse seq, start
      i = start
      result = []

      word = ''
      while i < seq.size
        case seq[i]
        when /[A-Z]/
          word << seq[i]
          i += 1
        when /[0-9]/
          unless word.size == 0
            result << word
            word = ''
          end
          genome_data,next_index = get_compress_data(seq, i)
          result << genome_data
          i = next_index
        when ")"
          unless word.size == 0
            result << word
            word = ''
          end
          i += 1
          break
        end
      end
      result << word unless word.size == 0
      [result, i]
    end

    def get_compress_data seq, start
      num = get_num_token(seq, start)
      data_array,next_index = get_data(seq, start + num.size)
      genome_data = GenomeData.new
      genome_data.num = num.to_i
      if data_array.instance_of?(Array)
        data_array.each do |data|
          genome_data << data
        end
      else
        genome_data << data_array
      end
      [genome_data, next_index]
    end

    def get_data seq, start
      i = start
      data_array = []
      case seq[i]
      when "("
        i += 1
        data_array,next_index = genome_parse(seq, i)
        i = next_index
      when /[A-Z]/
        data_array << seq[i]
        i += 1
      end
      [data_array, i]
    end

    def get_num_token seq, start
      num = ''
      i = start
      while i < seq.size
        if seq[i] =~ /[A-Z(]/
          break
        end
        num << seq[i]
        i += 1
      end
      num
    end
  end
end

def main
  loop do
    seq,index = gets.chomp.split(' ')
    break if seq.eql?('0') and index.eql?('0')
    puts GenomeDB.parse(seq)[index.to_i] || '0'
  end
end

if $0 == __FILE__
  main
end

Measured memory_bytes: 6200
#include<iostream>
#include<math.h>
using namespace std;
struct vect{
  double x,y;
};
double leng(vect a,vect b){
  return sqrt((a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y));
    }
double Sc(vect a,vect b,vect c){
  double S,l1,l2,l3; 
  l1 = leng(a,b);
  l2 = leng(b,c);
  l3 = leng(c,a);
  S = (l1 + l2 + l3) / 2;
  return sqrt(S*(S-l1)*(S-l2)*(S-l3));
  
}

int main(){
  vect a,b,c,p;
  double s1,s2,s3,s;
  while(cin >> a.x >> a.y  >> b.x >> b.y >>c.x >>c.y >> p.x >> p.y){
    s1 = Sc(a,b,p); s2 = Sc(a,p,c); s3 = Sc(p,b,c); 
    s = Sc(a,b,c);
    if( Sc(a,b,p) + Sc(a,p,c) < Sc(a,b,c)&&Sc(p,b,c) + Sc(a,p,c) < Sc(a,b,c) && Sc(a,b,p) + Sc(p,b,c) < Sc(a,b,c) ){cout << "YES" << endl;
    }else {cout << "NO" << endl;}
    
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
#define INF (int)2e9

int main() {
    int N, s, r = 0, m = INF, i;

    cin >> N;
    for (i = 0; i < N; i++) {
        cin >> s;
        if (s % 10) m = min(s, m);
        r += s;
    }

    if (m == INF) {
        cout << "0\n";
    } else {
        if (r % 10) {
            cout << r << '\n';
        } else {
            cout << r-m << '\n';
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

vvi g;
int ans = 1;
int n,k;

bool f(int now, int par, int invalid){
    if(k < invalid){
        ans = 0;
        return false;
    }
    (ans *= k-invalid) %= MOD;
    rep(i,g[now].size())if(g[now][i] == par){
        g[now].erase(g[now].begin()+i);
    }
    rep(i,g[now].size()){
        int ne = g[now][i];
        if(f(ne,now,i+1 + (par != -1)) == false)return false;
    }
    return true;
}

signed main(void) {
    cin >> n >> k;
    g = vvi(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    f(0,-1,0);
    cout << ans << endl;
}


Measured memory_bytes: 9216
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=1e5+10;
int n,lst[N],fa[N],m,k,cnt;
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	return x*f;}
inline int f(int son){return fa[son]==son ? son : f(fa[son]);}
int main()
{
	//freopen("Interpretation.in","r",stdin);
	n=read(); m=read();
	for(RG int i=1;i<=n;i++) fa[i]=i;
	for(RG int i=1;i<=n;i++)
	{
		k=read();
		for(RG int j=1,a;j<=k;j++)
		{
			a=read();
			if(!lst[a]) { lst[a]=i; continue; }
			int fx=f(lst[a]), fy=f(i);
			if(fx!=fy) fa[fx]=fy;
			lst[a]=i;
		}
	}
	for(RG int i=1;i<=n;i++)
	{
		if(fa[i]==i) cnt++;
		if(cnt>=2) return printf("NO\n"), 0;
	}
	return printf("YES\n"), 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
ll a[2][110];
ll sum[2][110];
int main(){
	ll n;
	cin>>n;
	ll ans = -1;
	for(int i=1;i<=n;i++){
		cin>>a[0][i];
		sum[0][i] = sum[0][i-1]+a[0][i];
	}
	for(int i=1;i<=n;i++){
		cin>>a[1][i];
		sum[1][i] = sum[1][i-1]+a[1][i];
	}
	for(int i=1;i<=n;i++){
		ll tmp = sum[0][i] + (sum[1][n] -sum[1][i-1]);
		if(tmp>ans)ans=tmp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n,m;
	cin >> n>> m;
    int a[n];
    int b[m];
    int c[m];
    bool end = false;
    vector<pair<long, long>> pairs(m);
    fr(i,n){
      cin >> a[i] ;
    }
    fr(i,m){
      cin >> b[i]>> c[i];
      pairs[i] = make_pair(c[i], b[i]);
    }
    sort(pairs.begin(), pairs.end());
    sort(a,a+n);
    int k=0;
    ifr(i,m){
      fr(j,pairs[i].second){
        if(a[k]<pairs[i].first)a[k]=pairs[i].first;
        else{
          end = true;
          break;
        }
        k++;
        if(k>=n){
          end = true;
          break;
        }
      }
      if(end==true)break;
    }
  ll ans=0;
    fr(i,n){
      ans+=a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)

struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};

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

ll lcm(ll a, ll b) {
	return a /gcd(a, b) *b;
}
typedef pair<int,int> pii;
const int mod = 1e9+7;

ll xorr(ll n){

    if(n%4==0)
        return n;

    else if(n%4==1)
        return 1;

    else if(n%4==2)
        return n+1;

    else
        return 0;



}

int main() {

   ll x,y,z,k;
   cin>>x>>y>>z>>k;

   ll a[x],b[y],c[z];
   sort(a,a+x,greaterr());
   sort(b,b+y,greaterr());
   sort(c,c+z,greaterr());
   fo(i,x)
    cin>>a[i];

    fo(i,y)
    cin>>b[i];

    fo(i,z)
    cin>>c[i];

    priority_queue<ll> pq,pqr;

    fo(i,x)
    fo(j,y)
      pq.push(a[i]+b[j]);

    for(int i=0;pq.size()&&i<k;++i){
        ll res = pq.top();pq.pop() ;
        for(int j=0;j<z;++j)
        pqr.push(res+c[j]);
    }

    fo(i,k){
        ll ans = pqr.top();pqr.pop();
        cout<<ans<<"\n";
    }



























    return 0;

      }


Measured memory_bytes: 43236
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

k=int(input())
a, b = map(int, input().split())
flg = True
for i in range(b-a+1):
    if (a+i)%k==0:
        print("OK")
        break
    if i==b-a:
        flg=False
if not flg:
    print("NG")

Measured memory_bytes: 9200
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long int
void dfs(int src,vector<int> adj[],bool visited[])
{
	if(visited[src])
	  return ;
	else
	{
		visited[src]=true;
		for(int x:adj[src])
		  dfs(x,adj,visited);
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	vector<int> adj[n+1];
	int j;
	for(j=0;j<m;j++)
	{
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int answer=0;
	bool visited[n+1]={false};
	for(j=1;j<=n;j++)
	{
		if(!visited[j])
		{
			answer++;
			dfs(j,adj,visited);
		}
	}
	cout<<answer-1<<endl;
}


Measured memory_bytes: 10792
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String q ="";
    if(a.equals(b)){
      q="H";
    }else{
      q="D";
    }
    System.out.println(q);

  }
  

  
}


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

int main(void){
	int x = 0, n, max = 0;
	char s[100];

	cin >> n;
	cin >> s;

	for (int i = 0; i < n; i++){
		if (s[i] == 'I') x++;
		else x--;
		if (max < x) max = x;
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
signed main() {
	string s, t; cin >> s >> s >> t;
	for0(i, s.size())cout << s[i] << t[i];
	cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nn 200008
int n;int val[nn];
vector<int> ex,ey;

void sub(int x,int y){
	ex.push_back(val[x]),ey.push_back(val[y]);
	val[x]-=val[y];
}
int main()
{
	cin>>n;for(int i=1;i<=n;i++) scanf("%d",&val[i]);
	sort(val+1,val+n+1);
	if(val[1]>0){
		for(int i=2;i<n;i++) sub(1,i);
		sub(n,1);
	}
	else if(val[n]<0){
		for(int i=1;i<n;i++) sub(n,i);
		
	}
	else{
		for(int i=2;i<n;i++){
			if(val[i]>0){
				sub(1,i);
			}
			else{
				sub(n,i);
			}
		}
		sub(n,1);
	}
	printf("%d\n",val[n]);
	
	for(int i=0;i<ex.size();i++) printf("%d %d\n",ex[i],ey[i]);
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    uint64_t L = 0, f = 1, ff = 2;
        for ( int i = 0; i < n; ++i ) {
            L += f;
            f = ff;
            ff = L;
        }
        cout << L << "\n"s;
}

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(X: int, Y: int):
    for i in range(0,X+1):
        if i*2 + 4*(X-i) == Y:
            print(YES)
            exit()
    print(NO)
    exit()
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defvar n (read))
(defvar h (coerce (loop repeat n collect (read)) 'vector))

(defun cul-cost (from to)
  (labels ((height (x)
             (if (>= x n) (expt 10 10)
                 (aref h x))))
    (abs (- (height from) (height to)))))

(dp func (x) '(100010)
    (if (>= x (1- n)) 0
        (apply #'min
               (loop for i from 1 to 2
                     collect (+ (cul-cost x (+ x i)) (func (+ x i)))))))

(princ (func 0))



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

using namespace std;

int nrc(int n)
{
    int nr=0;
    while(n)
    {
        nr++;
        n/=10;
    }
    return nr;
}

int main()
{
    int a,b;
    int nr;
    cin>>a>>b;
    nr=nrc(b);
    while(nr)
    {
        a*=10;
        nr--;
    }
    a+=b;
    if(int(sqrt(a))==sqrt(a))
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<int> A(N,0);
	int loop,Num;
	for(loop=0;loop<N-1;loop++){
		cin >> Num;
		A[Num-1]++;
	}
	for(loop=0;loop<N;loop++){
		cout << A[loop] << endl;
	}
	return 0;
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
int cntRed[4005]{};
int cntGreen[4005]{};
int cntBlue[4005]{};
int main()
{
 
    int n;
    string s;
    cin >> n >> s;
    ll sum = 0 ;
 
    for(int i = 0 ; i<n ; i++){
        if(s[i] == 'R'){
            cntRed[i]++;
        }
        if(s[i] == 'G'){
            cntGreen[i]++;
        }
        if(s[i] == 'B'){
            cntBlue[i]++;
        }
 
        if(i>0){
            cntRed[i] += cntRed[i-1];
            cntBlue[i] +=cntBlue[i-1];
            cntGreen[i] += cntGreen[i-1];
        }
    }
    // for(int i=0;i<10;i++)
    // {
    //     cout<<cntRed[i]<<" ";
    // }
    // cout<<endl;
    // for(int i=0;i<10;i++)
    // {
    //     cout<<cntGreen[i]<<" ";
    // }
    // cout<<endl;
    // for(int i=0;i<10;i++)
    // {
    //     cout<<cntBlue[i]<<" ";
    // }
    // cout<<endl;
 
    for(int i = 0 ; i<n ; i++){
        for(int j = i+1 ; j<n ; j++){
 
            char c1 = s[i];
            char c2 = s[j];
            if(c1 =='R' && c2 == 'G' || c1 == 'G' && c2 == 'R'){
 
                ll x = cntBlue[n-1] - cntBlue[j-1];
                sum+=x;
                if(j + j-i <n && s[j+j-i]=='B')
                {
                    //cout<<"1st"<<endl;
                    //cout<<i<<" "<<j<<endl;
                    sum--;
                }
 
            }
            else if(c1 =='R' && c2 == 'B' || c1 == 'B' && c2 == 'R'){
 
                ll x = cntGreen[n-1] - cntGreen[j-1];
                sum+=x;
                if(j + j-i <n && s[j+j-i]=='G')
                {
                    //cout<<"2nd"<<endl;
                    //cout<<i<<" "<<j<<endl;
                    sum--;
                }
 
            }
            else if(c1 =='B' && c2 == 'G' || c1 == 'G' && c2 == 'B'){
 
                ll x = cntRed[n-1] - cntRed[j-1];
                sum+=x;
                if(j + j-i <n && s[j+j-i]=='R')
                {
                    //cout<<"3rd"<<endl;
                    //cout<<i<<" "<<j<<endl;
                    sum--;
                }
            }
        }
    }
 
    cout<<sum<<endl;
    return 0;
}

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

int main() {
  int N, A;
  cin >> N;
  int ans = 1e9;
  while (cin >> A) {
    int cnt = 0;
    while (A % 2 == 0) A /= 2, cnt++;
    ans = min(ans, cnt);
  }
  cout << ans << "\n";
}

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

int main(){
  int N; cin >> N;
  int A[100000], B[100000], C[100000];
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> B[i];
  for(int i=0; i<N; i++) cin >> C[i];
  sort(A,A+N);
  sort(B,B+N);
  sort(C,C+N);
  long long AB[100000];
  int j=0;
  for(int i=0; i<N; i++){
    while(j<N&&A[j]<B[i]){
      j++;
    }
    AB[i]=j;
  }
  for(int i=1; i<N; i++){
    AB[i]+=AB[i-1];
  }
  j=0;
  long long result=0;
  for(int i=0; i<N; i++){
    while(j<N&&B[j]<C[i]){
      j++;
    }
    if(j!=0){
      result+=AB[j-1];
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 2176
// <3 Appy!
#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
typedef vector<long long int> vi;
ll has[100009] = {0};
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll n, sum = 0, count = 0, m, flag = 0, ans = 0, k;
    cin>>n;
    //vi v(n+1);

    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        has[x]++;
        if(x-1 >= 0)
            has[x-1]++;
        has[x+1]++;

        ans = max(has[x], max(has[x+1], max(has[x-1], ans)));

    }
    cout<<ans;
    return 0;
}


/* freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 */


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
 
using namespace std;
 
typedef long long ll;
 
const ll INF = 1e9, MOD = 1e9 + 7, MOD2 = 1e6 + 3;

string s;

ll dp[100][2], last[100];

ll p[100], sz[100], n;

vector < pair <ll, ll> > v;

ll qpow (ll a, ll b) {
	ll s = 1;

	while (b) {
		if (b & 1) s = s * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}

	return s;
}

ll find (ll x) {
	if (x == p[x]) return x;
	return p[x] = find (p[x]);
}

void actualize (ll x, ll y) {
	dp[x][0] = dp[x][0] * qpow (2, last[x] - y) % MOD;
	last[x] = y;
}

void unite (ll a, ll b) {
	a = find (a);
	b = find (b);

	if (a == b) return;

	if (sz[a] < sz[b]) swap (a, b);

	actualize (a, min (last[a], last[b]));
	actualize (b, min (last[a], last[b]));

	dp[a][1] = (dp[a][1] * (2 * dp[b][0] % MOD + dp[b][1]) % MOD) % MOD + 2 * dp[a][0] * (dp[b][0] + dp[b][1]) % MOD;
	dp[a][0] = dp[a][0] * dp[b][0] % MOD;

	p[b] = a;

	sz[a] += sz[b];
}

int main () {
	cin >> n;

	for (ll i = 0; i < n; i++) {
		ll h;

		scanf ("%lld", &h);

		last[i] = h;

		v.emplace_back (h, i);

		dp[i][0] = 1;
		dp[i][1] = 0;

		sz[i] = 1;
		p[i] = i;
	}

	sort (v.begin(), v.end());
	reverse (v.begin(), v.end());

	for (auto a : v) {

		if (a.second != n - 1 && last[a.second + 1] >= last[a.second]) {
			unite (a.second, a.second + 1);
		}
		if (a.second && last[a.second - 1] >= last[a.second]) {
			unite (a.second - 1, a.second);
		}
	}

	actualize (find (0), 1);

	cout << (2 * dp[find (0)][0] + dp[find (0)][1]) % MOD;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

const int mod=1e6+7;
bool slot[mod];

void Solve(){
	int n,m;
	string s;
	cin >> n >> m >> s;
	
	ull h[300001],pow[300001],b=1000000007;
	h[0]=0;
	pow[0]=1;
	rep(i,1,n+1){
		h[i]=h[i-1]*b+s[i-1];
		pow[i]=pow[i-1]*b;
	}

	//unordered_set<ull> slot;
	ull a[300001];
	int l=0,r=1,ans=0;
	rep(i,0,m){
		string q;
		cin >> q;
		
		int *d;
		if(q[0]=='L') d=&l;
		else d=&r;
		if(q[1]=='+') ++*d;
		else --*d;

		//slot.insert(h[r]-h[l]*pow[r-l]);
		a[i]=h[r]-h[l]*pow[r-l];
	}

	sort(a,a+m);
	cout << unique(a,a+m)-a << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 8480
#include<iostream>
#include<vector>
#include<complex>
#define EPS 1e-10
using namespace std;    

typedef complex<double> P;

double cross(P a, P b){
  return (a.real()*b.imag() - a.imag()*b.real());
}

int main()
{
  int i,j;
  int n;
  P point[3],ans;

  cin >> n;
  for(i=0;i<n;i++){

    for(j=0;j<3;j++){
      cin >> point[j].real() >> point[j].imag();
    }

    P p01 = point[0] + point[1];
    P p12 = point[1] + point[2];
    P h01 = P(p01.real()/2 , p01.imag()/2);
    P h12 = P(p12.real()/2 , p12.imag()/2);
    P n1 = (point[0] - h01) * P(0,1) + h01;
    P n2 = (point[1] - h12) * P(0,1) + h12;

    ans = n1 + (h01-n1) * cross(h12-n2,n2-n1) / cross(h12-n2,h01-n1);


    printf("%.3lf %.3lf %.3lf\n",real(ans) + EPS,imag(ans) + EPS,abs(point[0]-ans) );
  }
  return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<ll> divisor(ll n){
	vector<ll> ret;
	for(ll i=1;i<=(ll)sqrt(n);i++){
		if(n%i==0){
			ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
		}
	}
	sort(ret.begin(),ret.end(),greater<ll>());
	return(ret);
}
int main(){
 ll n,d;
 cin>>n>>d;
 V<ll> a(n);
 ll sum=0;
 for(int i=0;i<n;i++){
     cin>>a[i];
     sum+=a[i];
 }
 sort(all(a));
 V<ll> tmp=divisor(sum);
 for(int k=0;k<tmp.size();k++){
     V<ll> b(n);
     ll t;
     sum=0;
     for(int i=0;i<n;i++){
          b[i]=a[i]%tmp[k];
          sum+=a[i]%tmp[k];
     }
     if(sum%tmp[k]!=0)continue;
     sum/=tmp[k];
     sort(all(b));
     ll need=0;
     for(int i=n-1;i>=n-sum;i--){
         need+=(tmp[k]-b[i])%tmp[k];
     }
     if(need<=d){
         cout<<tmp[k]<<"\n";
         return 0;
     }
 }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string word;
	string answer="1";
	cin >> word;
	for (int i = 0; i < word.size(); ++i) {
		if (word[i] == 'T'&&answer.back() == 'S') {
			answer.pop_back();
		}
		else {
			answer += word[i];
		}
	}
	cout << answer.size()-1 << endl;
	return 0;
}

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

const int maxn=2e5+10;
int n,p[maxn],sum[maxn];
char ans[maxn];

inline void init(){
	for(int i=1,top=0;i<=n;++i)
		if(p[i]>top)
			sum[i]=sum[i-1]+1,top=p[i];
		else
			sum[i]=sum[i-1];
}
namespace segt{
	const int size=maxn*20;
	int cnt,root[maxn];
	int odd[size],even[size],lson[size],rson[size];
	inline void init(){
		odd[cnt]=-1e9;
		even[cnt]=0;
	}
	inline int newnode(int rt){
		++cnt;
		odd[cnt]=odd[rt];
		even[cnt]=even[rt];
		lson[cnt]=lson[rt];
		rson[cnt]=rson[rt];
		return cnt;
	}
	void query(int rt,int l,int r,int x,int&reso,int&rese){
		if(l==x){
			if(reso<odd[rt])
				reso=odd[rt];
			if(rese<even[rt])
				rese=even[rt];
			return;
		}
		int mid=l+r>>1;
		if(x<=mid)
			query(lson[rt],l,mid,x,reso,rese),query(rson[rt],mid+1,r,mid+1,reso,rese);
		else
			query(rson[rt],mid+1,r,x,reso,rese);
	}
	int modify(int rt,int l,int r,int x,int valo,int vale){
		rt=newnode(rt);
		if(odd[rt]<valo)
			odd[rt]=valo;
		if(even[rt]<vale)
			even[rt]=vale;
		if(l==r)
			return rt;
		int mid=l+r>>1;
		if(x<=mid)
			lson[rt]=modify(lson[rt],l,mid,x,valo,vale);
		else
			rson[rt]=modify(rson[rt],mid+1,r,x,valo,vale);
		return rt;
	}
	inline void run(){
		init();
		for(int i=n,o,e;i;--i){
			o=-1e9;e=0;
			query(root[i+1],1,n,p[i],o,e);
			if(sum[i]==sum[i-1])
				root[i]=modify(root[i+1],1,n,p[i],e+1,o+1);
			else
				root[i]=modify(root[i+1],1,n,p[i],o+2,e+2);
		}
	}
}
inline bool check(int pos,int numx,int numy,int maxx,int maxy){
	int odd,even,res;
	odd=-1e9;even=0;
	if(maxy<n)segt::query(segt::root[pos],1,n,maxy+1,odd,even);
	if(numx-numy+sum[n]-sum[pos-1]>=0&&(numx-numy+sum[n]-sum[pos-1]&1?odd:even)>=numx-numy+sum[n]-sum[pos-1])
		return true;
	odd=-1e9;even=0;
	if(maxx<n)segt::query(segt::root[pos],1,n,maxx+1,odd,even);
	if(numy-numx+sum[n]-sum[pos-1]>=0&&(numy-numx+sum[n]-sum[pos-1]&1?odd:even)>=numy-numx+sum[n]-sum[pos-1])
		return true;
	return false;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>p[i];
	init();
	segt::run();
	if(check(1,0,0,0,0)){
		for(int i=1,numx=0,numy=0,maxx=0,maxy=0;i<=n;++i)
			if(p[i]>maxx?check(i+1,numx+1,numy,p[i],maxy):check(i+1,numx,numy,maxx,maxy)){
				ans[i]='0';
				if(p[i]>maxx)
					++numx,maxx=p[i];
			}
			else{
				ans[i]='1';
				if(p[i]>maxy)
					++numy,maxy=p[i];
			}
		puts(ans+1);
	}
	else
		puts("-1");
	return 0;
}

Measured memory_bytes: 65536
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i,s,e) for (int64_t i=s; i<e; i++)
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int64_t K, P=0;
  cin >> K;
  vector<int64_t> A(K);
  A[0]=7;
  if (K==1||K==7) {
    cout << 1 << endl;
  }
  else {
    rep(i,1,K) {
      A[i]=10*A[i-1]+7;
      A[i]%=K;
    }
    rep(i,0,K) {
      if (A[i]==0) {
        cout << i+1 << endl;
        break;
      }
      else {
        P++;
      }
    }
    if (P==K) {
      cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 11164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n;
    cin >> n;
    vector<int> w(n), sub_w(n, 0);
    int mi = INT_MAX;
    for (int i = 0; i < n; i++)
    {
        cin >> w[i];
        sub_w[i] = w[i];
        if (0 < i)
            sub_w[i] += sub_w[i - 1];
    }
    for (int i = 0; i < n; i++)
    {
        mi = min(abs(sub_w[i] - (sub_w[n - 1] - sub_w[i])), mi);
    }
    cout << mi << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	int a, b; cin >> a >> b;
	int x = a * b;
	if (x % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
}

Measured memory_bytes: 256
import math

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    """
    3点を通る円の中心と半径を取得
    """
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if d == 0:
      return (0, 0), 0
    x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
    y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
    r = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
    return (x, y), r
  
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
answer = []
if N == 2:
  xy1, xy2 = XY
  x1, y1 = xy1
  x2, y2 = xy2
  answer.append(((x2 - x1)**2 + (y2 - y1)**2)**0.5 / 2)
else:
  for i in range(N):
    xi, yi = XY[i]
    for j in range(i + 1, N):
      xj, yj = XY[j]      
      r = ((xi - xj)**2 + (yi - yj)**2)**0.5/2
      x0, y0 = ((xi + xj) / 2, (yi + yj) / 2)
      flag = 1
      for ii in range(N):
        xii, yii = XY[ii]
        if ((x0 - xii)**2 + (y0 - yii)**2)**0.5 > r:
          flag = 0
          break
      if flag:
        answer.append(r)

  for i in range(N):
    xi, yi = XY[i]
    for j in range(i + 1, N):
      xj, yj = XY[j]
      for k in range(j + 1, N):
        xk, yk = XY[k]
        xy0, r = get_circle_center_and_radius(xi, yi, xj, yj, xk, yk)
        x0, y0 = xy0
        
        if r:
          flag = 1
          for ii in range(N):
            xii, yii = XY[ii]
            if ((x0 - xii)**2 + (y0 - yii)**2)**0.5 > r:
              flag = 0
              break
          if flag:
            answer.append(r)
print(min(answer))

Measured memory_bytes: 48876
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	char s1[3];
	char c;
	for(int i=0;i<3;i++)
		cin >>s1[i];
	getchar();
	int t=0;
	for(int i=0;i<3;i++){
		cin >>c;
		if(c==s1[i]){
			t++;
		}
	}
	cout<<t<<endl;
	return 0;
}



Measured memory_bytes: 256
from collections import deque

N, Q = map(int, input().split())

connect_lst = [[] for _ in range(N + 1)]

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

query_weight = [0] * (N + 1)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x

used = set()
dq = deque([1])
used.add(1)
ans = [0] * (N + 1)

while dq:
    node = dq.popleft()
    can = connect_lst[node]

    used.add(node)
    ans[node] += query_weight[node]

    for c in can:
        if c not in used:
            ans[c] += ans[node]
            dq.append(c)


ans = [str(w) for w in ans[1:]]
print(' '.join(ans))


Measured memory_bytes: 80952
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0 ) break;
			int[][] map1 = new int[5][5];
			int s = sc.next().charAt(0) - 'A';
			int t = sc.next().charAt(0) - 'A';
			int b = sc.next().charAt(0) - 'A';
			int cnt;
			for(int[] a: map1) fill(a, -1);
			for(int i=1;i<=3;i++) for(int j=1;j<=3;j++) map1[i][j] = 0;
			map1[ b/3+1 ][ b%3+1 ] = -1;
			cnt = 1;
			map1[ s/3+1 ][ s%3+1 ] = 1;
//			for(int[] a: map1) debug(a);
			for(int c=0;c<n;c++) {
				int[][] tmp = new int[3][3];
				for(int x=1;x<=3;x++) for(int y=1;y<=3;y++)  {
					if(map1[x][y] == -1) {
						tmp[x-1][y-1] = map1[x][y];
						continue;
					}
					for(int j=0;j<4;j++) {
						if(map1[x+dx[j]][y+dy[j]] != -1) {
							tmp[x+dx[j]-1][y+dy[j]-1] += max(0, map1[x][y]);
						}
						else
							tmp[x-1][y-1] += max(0, map1[x][y]);
					}
				}
				for(int x=1;x<=3;x++) for(int y=1;y<=3;y++) {
					map1[x][y] = tmp[x-1][y-1];
				}
				cnt *= 4;
			}
			System.out.println(( (double)map1[t/3+1][t%3+1]/cnt ));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin>>s;
  int k;
  cin>>k;
  int n = s.size();
  ll dp[n+1][k+1][2] = {}; // ith digit, j non-zero digits, less/greater than N
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      dp[i+1][j][1] += dp[i][j][1];
      if (s[i] == '0') dp[i+1][j][0] += dp[i][j][0];
      if (s[i] != '0') dp[i+1][j][1] += dp[i][j][0];
      for (int h = 1; h <= 9; h++) {
        if (j + 1 <= k && s[i] == ('0'+h)) dp[i+1][j+1][0] += dp[i][j][0];
        if (j+1<=k){
          dp[i+1][j+1][1] += dp[i][j][1];
          if ('0' + h < s[i]) dp[i+1][j+1][1] += dp[i][j][0];
        }
      }
    }
  }
  ll ans = dp[n][k][0] + dp[n][k][1];
  cout << ans << endl;
}


Measured memory_bytes: 384
from math import sqrt, cos, sin, radians

A, B, H, M = map(int, input().split(' '))

# A, B, H, M = 3, 4, 10, 40
# A, B, H, M = 3, 4, 9, 0

deg_h = H * 30 + M * 0.5
deg_m = M * 6

rad_h = radians(deg_h)
rad_m = radians(deg_m)

x_h, y_h = cos(rad_h) * A, sin(rad_h) * A
x_m, y_m = cos(rad_m) * B, sin(rad_m) * B

d = sqrt((x_h - x_m) ** 2 + (y_h - y_m) ** 2)

# print('h_pos',x_h, y_h)
# print('m_pos',x_m, y_m)
print(d)


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

typedef long long ll;

int main() {
    int N;
    double total = 0.0;
    int a = 1;
    cin >> N;
    vector<int>v(N);
    vector<int>x(N);
    vector<int>y(N);

    for (int i = 0; i < N; i++) {
        v[i] = i;
        cin >> x[i] >> y[i];
    }

    do {
        for (int i = 1; i < N; i++) {
            total += sqrt(pow(x[v[i]]-x[v[i-1]], 2)+pow(y[v[i]]-y[v[i-1]], 2));
        }
    } while(next_permutation(v.begin(), v.end()));
    
    while (N > 0) {
        a *= N;
        N--;
    }
    printf("%.10f\n", total/(double)a);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long dp[3001][3001][2];
long solve(vector<long>&v,long i,long j,long turn){
        if (i>j)
           return 0;
        if (dp[i][j][turn]!=-1)
          return dp[i][j][turn];
       if (turn)
       return  dp[i][j][turn]=max(v[i]+solve(v,i+1,j,0),v[j]+solve(v,i,j-1,0));
       else
         return dp[i][j][turn]=min(solve(v,i+1,j,1),solve(v,i,j-1,1));
}

int main(){
     long n,a,s=0;
  cin>>n;
  vector<long>v;
  for (long i=0;i<n;i++){
    cin>>a;v.push_back(a);
  s+=a;
  }
  memset(dp,-1,sizeof(dp));
  long X=solve(v,0,n-1,1);
  long Y=s-X;
  cout<<X-Y<<endl;
 return 0; 
}

Measured memory_bytes: 141312
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        while (true) {
            int n = in.nextInt();
            int k = in.nextInt();
            if((n|k) == 0) break;
            boolean[] app = new boolean[n + 1];
            boolean joker = false;
            for (int i = 0; i < k; i++) {
                int x = in.nextInt();
                if (x == 0) joker = true;
                else app[x] = true;
            }
            int[] l = new int[n + 2];
            int[] r = new int[n + 2];
            for (int i = 0; i <= n; i++) {
                if (app[i]) l[i] = r[i] = 1;
            }
            for (int i = 1; i <= n; i++) {
                if (app[i]) {
                    l[i] = l[i - 1] + 1;
                } else {
                    l[i] = 0;
                }
            }
            for (int i = n - 1; i >= 0; i--) {
                if (app[i]) {
                    r[i] = r[i + 1] + 1;
                } else {
                    r[i] = 0;
                }
            }
            int res = 0;
            if (joker) {
                for (int i = 2; i <= n - 1; i++) {
                    res = Math.max(l[i - 1] + r[i + 1] + 1, res);
                }
            } else {
                for (int i = 1; i <= n; i++) {
                    res = Math.max(res, r[i]);
                }
            }
            System.out.println(res);
        }
    }
}

Measured memory_bytes: 62536
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Arrays;
public class Main {

  public static Integer getMinNode(HashSet<Integer> unvisited, int[] results) {
    Integer minNode = null;
    int min = Integer.MAX_VALUE;
    Iterator<Integer> it = unvisited.iterator();
    while(it.hasNext()){
      Integer currNode = it.next();
      if (results[currNode] < min) {
        minNode = currNode;
        min = results[currNode];
      }
    }
    return minNode;
  }

  public static int[] dijkstras(
    ArrayList<ArrayList<Integer>> graph,
    ArrayList<ArrayList<Integer>> graphWeights) {

    // Initialize an empty visited set
    HashSet<Integer> visited = new HashSet<Integer>();

    // Initialize unvisisted set with all nodes
    HashSet<Integer> unvisited = new HashSet<Integer>();
    for (int i = 0; i < graph.size(); i++) {
      unvisited.add(i);
    }

    // Initialize results set with all infinity values (except for initial node 0)
    int[] results = new int[graph.size()];
    for (int i = 1; i < graph.size(); i++) {
      results[i] = Integer.MAX_VALUE;
    }

    while (visited.size() < graph.size()) {
      Integer currNode = getMinNode(unvisited, results);
      visited.add(currNode);
      unvisited.remove(currNode);
      ArrayList<Integer> neighbors = graph.get(currNode);
      ArrayList<Integer> neighborsWeights = graphWeights.get(currNode);
      for (int i = 0; i < neighbors.size(); i++) {
        if (results[currNode] + neighborsWeights.get(i) < results[neighbors.get(i)])
          results[neighbors.get(i)] = results[currNode] + neighborsWeights.get(i);
      }
    }

    return results;
  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    ArrayList<ArrayList<Integer>> graph = new ArrayList<ArrayList<Integer>>();
    ArrayList<ArrayList<Integer>> graphWeights = new ArrayList<ArrayList<Integer>>();
    for (int i = 0; i < n; i++) {
      Integer idx = s.nextInt();
      ArrayList<Integer> neighbors = new ArrayList<Integer>();
      ArrayList<Integer> neighborsWeights = new ArrayList<Integer>();
      int numNeighbors = s.nextInt();
      for (int j = 0; j < numNeighbors; j++) {
        neighbors.add(s.nextInt());
        neighborsWeights.add(s.nextInt());
      }
      graph.add(neighbors);
      graphWeights.add(neighborsWeights);
    }
    s.close();
    int[] results = dijkstras(graph, graphWeights);
    for (int i = 0; i < results.length; i++) {
      System.out.println(i + " " + results[i]);
    }
  }

}



Measured memory_bytes: 40388
n, d = map(int, input().split())
x = list(list(map(int, input().split())) for _ in range(n))

#print(x)

lis = []
for i in range(n):
    for j in range(i + 1, n):
        #各点語との距離
        lis1 = []
        for k in range(d):
            l_x = (x[i][k] - x[j][k]) ** 2
            lis1.append(l_x)
        lis.append(sum(lis1) ** 0.5)

ans = 0
for i in range(len(lis)):
    if lis[i].is_integer() == True:
        ans += 1

print(ans)


Measured memory_bytes: 9412
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
    Q[tail]=x;
    tail=(tail+1)%LEN;
}

P dequeue(){
    P x=Q[head];
    
    head=(head+1)%LEN;
    return x;
}

int min(int a,int b) {
    return a<b ? a:b;
}

int main(void){

    int elaps=0,c;
    int i,q;
    P u;
    scanf("%d %d",&n,&q);

    for(i=1;i<=n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head=1;tail=n+1;

    while(head!=tail){
      
        u=dequeue();
	c=min(q,u.t);
        u.t-=c;
        elaps+=c;

	if (u.t>0)
	  enqueue(u);
        else{
            printf("%s %d\n",u.name,elaps);
        }
    }
    return 0;
}




Measured memory_bytes: 11876
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 998244353;
const int K = 1000001;
int sum[K];
int p[K];

int mult(int x, int y){
	return ((ll) x * (ll) y) % (ll) mod;
}

int add(int x, int y){
	if (x+y<0) return x+y+mod;
	if (x+y>=mod) return x+y-mod;
	return x+y;
}

int pw(int x, int y){
	if (y==0) return 1;
	if (y==1) return x;
	if (y%2) return mult(x, pw(x, y-1));
	int Q = pw(x, y/2);
	return mult(Q, Q);
}

signed main()
{
	#ifdef LOCAL
	    freopen("H_input.txt", "r", stdin);
	    //freopen("B_output.txt", "w", stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	int n;
   	cin >> n;
   	vector<int> v(n);
   	for (int i=0;i<n;++i) cin >> v[i];
   	for (int i=0; i < n; ++i) sum[v[i]] = add(sum[v[i]], v[i]);
   	for (int i=1; i < K; ++i){
   		for (int j=i+i; j < K; j += i){
   			sum[i] = add(sum[j], sum[i]);
   		}
   	}
   	int ans=0;
   	for (int i=K-1; i >= 1; i--){
   		int P = mult(sum[i], sum[i]);
   		for (int j=i+i; j < K; j += i){
   			P = add(P, -p[j]);
   		}
   		p[i] = P;
   		ans = add(ans, mult(p[i], pw(i, mod-2)));
   	}
   	for (int i=0;i<n;++i){
   		ans = add(ans, -v[i]);
   	}
   	ans = mult(ans, (mod+1)/2);
   	cout << ans;
    return 0;
}

Measured memory_bytes: 8832