akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int[] arr = fs.nextIntArray(n);
        Utils.shuffleSort(arr);
        int sum = 0;
        for (int i = 0; i < n - 1; i++) {
            sum += arr[i];
        }
        System.out.println(arr[n - 1] < sum ? "Yes" : "No");
    }

    static final class Utils {
        public static void shuffleSort(int[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffle(int[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void shuffle(long[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void swap(int[] arr, int i, int j) {
            final int t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        public static void swap(long[] arr, int i, int j) {
            final long t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 32832
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
int main(){
    int n;cin>>n;
    int res=0;
    while(res<n)res+=1000;
    cout<<res-n<<endl;
    return 0;
}


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

int _;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod=1e9+7;

int n;

inline long long powlog(int x,int t)
{
	long long ans=1;
	while(t--)
	{
		ans *= x;
		ans %= mod;
	} 
	return ans;
}

int main()
{	
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	printf("%lld\n",(powlog(10,n)-powlog(9,n)-powlog(9,n)+powlog(8,n)+2*mod)%mod);
	return 0;
}   	         


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

template<typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

template<typename T>
T lcm(T a, T b) {
  return (a*b)/gcd(b%a, a);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int p, q, r;
  cin >> p >> q >> r;
  cout << min({p+q, p+r, q+r}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<bits/stdc++.h>
using namespace std;

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


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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pnn=pair<int ,int>;

#define ft first
#define sd second
#define fn front
#define pb push_back
#define it insert
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))

string yes="Yes",no="No";

int main() {
   int n;
   cin>>n;
   vin a(n);
   Graph yaku(1e6+11);
   rep(i,1e6+10){
       int j=i+1;
       for(int k=2;k*j<=1e6+10;k++){
           yaku[k*j].pb(j);
       }
   }
   
   set<int> ay;
   set<int> ww;
   rep(i,n){
       cin>>a[i];
       if(ay.count(a[i])){
           ww.it(a[i]);
           continue;
       }
       ay.it(a[i]);
   }
   int cnt=0;
   rep(i,n){
       if(ww.count(a[i])){
           cnt++;
           continue;
       }
       for(auto x:yaku[a[i]]){
           if(ay.count(x)){
               cnt++;
               break;
           }
       }
   }
   cout<<n-cnt<<endl;
   
  
  
   
}


Measured memory_bytes: 125508
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>

using namespace std;

int n,x;

int main(){
    while(scanf("%d",&n)==1)
    {
         int sum=0;
         if(n==0) break;
         for(int i=1;i<=n*(n-1)/2;i++)
         {
            scanf("%d",&x);
            sum+=x;
         }
         printf("%d\n",sum/(n-1));
    }
    return 0;
}
         
            

Measured memory_bytes: 0
n=int(raw_input())

tarou=0
hanako=0
for i in range(n):
    words=raw_input().split(" ")
    tarou_sum = 0
    hanako_sum = 0
    for idx, c in enumerate(words[0]):
        
        if len(words[1]) -1 < idx:
            tarou += 3
            break
        
        if ord(words[1][idx]) < ord(c):
            tarou += 3
            break
        elif ord(words[1][idx]) > ord(c):
            hanako += 3
            break
        else:
            continue
    else:
        if len(words[0]) < len(words[1]):
            hanako += 3
        else:
            tarou += 1
            hanako += 1

print "%d %d" % (tarou, hanako)

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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

int dx[] = { 0,0,1,-1,-1,-1,1,1 };
int dy[] = { 1,-1,0,0,-1,1,1,-1 };

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif

void solve()
{
	vector<int> bits(64);
   
    int n;
	cin>>n;

	vector<long long> items(n);

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

		for(long long j=0;j<33;j++){
            if(ison(items[i],j)){
				bits[j]++;
			}
		}
	}

	for(int j=0;j<33;j++){
		debug(bits[j]);
	}
	
	vector<long long> res;

	for(int i=0;i<n;i++){
        
		vector<int> p;

		for(long long j=0;j<33;j++){
            int cnt=bits[j];
		    if(ison(items[i],j)){
				cnt--;
			}
			
			p.push_back(cnt%2);
		}

		reverse(p.begin(),p.end());

		long long ans=0;

		for(int j=0;j<33;j++){
			ans=ans*2+p[j];
		}
		cout<<ans<<" ";
	}
}

int main()
{
	FIO;

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		DisjointSet dj = new DisjointSet(n * 2);
		
		for(int i = 0; i < m; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int z = sc.nextInt();
			
			if(z % 2 == 0) {
				dj.union(x, y);
				dj.union(x + n, y + n);
			}
			else {
				dj.union(x, y + n);
				dj.union(x + n, y);
			}
		}
//		dj.printPArray();
		System.out.println(dj.numOfGroup()/2);
	}

}

class DisjointSet {
	private int n;
	private int[] p;
	private int[] rank;
	//各グループの要素数を管理する
	private int[] num;
	//グループ数を管理する
	private int numOfGroup;

	public DisjointSet(int n){
		this.n = n;

		p = new int[n + 1];
		rank = new int[n + 1];

		num = new int[n + 1];
		
		Arrays.fill(num, 1);
		
		for(int i = 1; i <= n; i++){
			makeSet(i);
		}
		
		numOfGroup = n;
	}

	private void makeSet(int x){
		p[x] = x;
		rank[x] = 0;
	}

	public void union(int x, int y){
		int p1 = findSet(x), p2 = findSet(y);
		int num1 = num[p1];
		int num2 = num[p2];
		link (findSet(x), findSet(y));
		
		if(p1 != p2) {
			num[p1] = num[p2] = num1 + num2;
			numOfGroup--;
		}
	}
	
	public int amountOfOwnGroup(int x) {
		return num[findSet(x)];
	}

	public int numOfGroup() {
		return numOfGroup;
	}
	private int findSet(int x){
		if(x != p[x]){
			p[x] = findSet( p[x]);
		}
		return p[x];
	}

	public boolean isSameSet(int x, int y){
		return findSet(x) == findSet(y);
	}

	private void link(int x, int y){
		if(rank[x] > rank[y]){
			p[y] = x;
		}
		else {
			p[x] = y;
			if(rank[x] == rank[y]){
				rank[y]++;
			}
		}
	}
	
	//for debug
	public void printPArray() {
		for(int i = 1; i <= n; i++) {
			System.out.print(p[i]+" ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 53272
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int N = 5010;
const ll INF = 1e18;
int n;
ll a[N];
VI e[N];

void out(VVL &dp){
    REP(f,2){
        REP(i,dp[f].size()) cout << dp[f][i] << " ";
        cout << endl;
    }
    cout << endl;
}

void dfs(int now, int past, VVL &dp){
    dp.assign(2, VL(1, INF));
    if (a[now] > 0) dp[1][0] = a[now];
    else dp[0][0] = a[now];
    for (int next : e[now]){
        if (next == past) continue;
        VVL dp2(2);
        dfs(next, now, dp2);
        int n = dp[0].size(), m = dp2[0].size();
        VVL dp_next(2, VL(n + m, INF));
        REP(i,n) REP(f,2) REP(j,m) REP(g,2){
            if (dp[f][i] == INF || dp2[g][j] == INF) continue;
            dp_next[f & g][i + j] = min(dp_next[f & g][i + j], dp[f][i] + dp2[g][j]);
            if (g || dp2[g][j] < 0) dp_next[f][i + j + 1] = min(dp_next[f][i + j + 1], dp[f][i]);
        }
        // out(dp);
        // out(dp2);
        // out(dp_next);
        dp.swap(dp_next);
    }
}

int main() {
    cin >> n;
    REP(i,n) a[i] = in();
    REP(i,n-1){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    VVL dp(2);
    dfs(0, -1, dp);

    int ans = n;
    REP(i,n){
        if (dp[0][i] < 0 || dp[1][i] < INF) ans = min(ans, i);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double[] pt = new double[4];

		for (int i = 0; i < 4; i++) {
			pt[i] = sc.nextDouble();
		}

		double distance = Math.pow(pt[2] - pt[0], 2) + Math.pow(pt[3] - pt[1], 2);
		distance = Math.sqrt(distance);

		System.out.println(distance);

		sc.close();

	}

}



Measured memory_bytes: 28036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			System.out.println((n * 100 + m * 1800) * (1 << m));
		}
	}
}


Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    println(if (f(N)) "Yes" else "No")
}

fun f(x: Int): Boolean {
    val a = if (x < 4) x == 0 else f(x - 4)
    val b = if (x < 7) x == 0 else f(x - 7)

    return a || b
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n, k;
    cin >> n >> k;

    ll ans = 0;
    while(n >= 1){
        n /= k;
        ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s,year,month,day;
	cin>>s;
	year=s.substr(0,4);
	month=s.substr(5,2);
	day=s.substr(8,2);
	if(year<"2019")cout<<"Heisei"<<endl;
	else if(year>"2019")cout<<"TBD"<<endl;
	else{
		if(month<="04")cout<<"Heisei"<<endl;
		else cout<<"TBD"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    repeat(i, n) cin >> a[i];
    map<int, int> mp;
    repeat(i, n) ++mp[a[i]];
    int ans = 0;
    for (auto e : mp) {
        int num = e.fst;
        int cnt = e.snd;
        if (num > cnt) {
            ans += cnt;
        }
        else if (num == cnt) {
            // no operation
        }
        else {
            ans += (cnt - num);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120
#include<stdio.h>
#define N 100

int min(int x,int y){
	if(x<y){
		return x;
	}else{
		return y;
	}
}

int main( void ){
	int n , p[N+1],m[N+1][N+1];
	scanf("%d" , &n);
	
	for(int i = 1;i<= n;i++ ){
		scanf("%d",&p[i-1]);
		scanf("%d",&p[i]);
	}
	
	for(int i = 1; i <= n; i++) m[i][i] = 0;
	
	for(int l=2;l<= n;l++){
		for( int i = 1; i <= n-l+1; i++ ){
			int j = i+l-1;
			m[i][j] = (1<<21);
			for( int k = i; k <= j-1; k++ ){
				m[i][j] = min( m[i][j] , m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
			}
		}
	}
	
	printf("%d\n",m[1][n]);
	
	return 0;
}
	



Measured memory_bytes: 2084
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        sc.close();

        for(int i=0; i<n-1; i++){
            if(c*(n-1-i) - d*i <= b-a && b-a <= -c*i + (n-1-i)*d){
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for(int i=0; i<=A; i++){
        for(int j=0; j<=B; j++){
            for(int k=0; k<=C; k++){
                if(500*i + 100*j + 50*k == X) ans++;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int c[N];
bool f[N];

int main() {
	int n,m;cin>>n>>m;
	rep(i,n) {c[i]=0;f[i]=false;}
	rep(i,m){
		int p;string s;cin>>p>>s;p--;
		if(f[p]) continue;
		else if(!f[p]&&s=="WA") c[p]++;
		else if(!f[p]&&s=="AC") f[p]=true;
	}
	int ans_s=0,ans_p=0;
	rep(i,n) if(f[i]){ans_s++;ans_p+=c[i];}
	cout<<ans_s<<' '<<ans_p<<endl;
}


Measured memory_bytes: 768
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register int
#define rep(i,a,b)	for(RG i=a;i<=b;++i)
#define per(i,a,b)	for(RG i=a;i>=b;--i)
#define ll long long
#define inf (1<<29)
using namespace std;
int T,flg,n;
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
map<int,int> cnt;
struct Dat{
	int num[3][5];
	int x,y,step;
	int * operator [] (int x)	{return num[x];} 
}S;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

int getid(Dat p)
{
	int sum=0;
	rep(i,1,4)	sum+=pow(8,i-1)*p[1][i];
	rep(i,1,4)	sum+=pow(8,i+3)*p[2][i];
	return sum;
}

void bfs()
{
	queue<Dat> que;
	Dat u,v;int id,tx,ty;
	que.push(S);
	while(!que.empty())
	{
		u=que.front(),que.pop();
		rep(i,0,3)
		{
			tx=u.x+dir[i][0],ty=u.y+dir[i][1];
			if(tx<1||tx>2||ty<1||ty>4)	continue;
			v=u,swap(v[u.x][u.y],v[tx][ty]);
			v.x=tx,v.y=ty,v.step=u.step+1;
			id=getid(v);
			if(cnt.find(id)!=cnt.end())	continue;
			cnt[id]=v.step;
			que.push(v);
		}
	}
}

void pre()
{
	S.x=S.y=1;
	rep(i,1,4)	S[1][i]=i-1;
	rep(i,1,4)	S[2][i]=i+3;
	cnt[16434824]=0;
	bfs();
}

int main()
{
	pre();
	int sum;
	while(~scanf("%d",&S[1][1]))
	{
		rep(i,2,4)	S[1][i]=read();
		rep(i,1,4)	S[2][i]=read();
		sum=getid(S);
		printf("%d\n",cnt[sum]);
	}
	return 0;
}


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

using namespace std;

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

char g[55][55],c[55][55];

int main(){
	int n,m;
	cin>>n>>m;
	rep(i,n){
		rep(j,n){
			cin>>g[i][j];
		}
	}

	rep(i,m){
		rep(j,m){
			cin>>c[i][j];
		}
	}
	rep(i,n-m+1){
		rep(j,n-m+1){
			bool ok=1;
			rep(k,m){
				rep(q,m){
					if(g[k+i][q+j]!=c[k][q]){
						ok=0;
					}
				}
			}
			if(ok){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
}

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

using namespace std;

int 
main()
{
	int i = 0, j = 0;

	for ( i = 1 ; i < 10 ; i = i + 1 )
	{
		for ( j = 1 ; j < 10 ; j = j + 1 )
		{
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2976
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        while (true) {
            UL H, W; scanf("%d%d", &H, &W);
            if (H == 0) return;
            rep(y, H) {
                rep(x, W) {
                    if((x + y) % 2 == 0) printf("#");
                    else  printf(".");
                }
                printf("\n");
            }
            printf("\n");
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3104
class Phrase
  def initialize s, l, p
    @s = s
    @l = l
    @p = p
  end
  attr_reader :s, :l, :p
end

def main
  n = gets.chomp.to_i
  phrases = []
  min = 393;
  n.times do
    s,l,p = gets.chomp.split(' ').map(&:to_i)
    min = s if min > s
    phrases << Phrase.new(s, l, p)
  end

  error = false
  results = []
  melodys = []
  m = gets.chomp.to_i
  m.times do
    w = gets.chomp.to_i
    if w < min
      puts '-1'
      return 0;
    end
    melodys << w
  end

  max_long_melody = melodys.max
  p_arr = Array.new(max_long_melody + 1, 0)
  d_arr = Array.new(max_long_melody + 1, 0)
  phrases.each do |phrase|
    phrase.s.upto(max_long_melody) do |i|
      pp = p_arr[i-phrase.s] + phrase.p
      if pp > p_arr[i]
        p_arr[i] = pp
        d_arr[i] = d_arr[i-phrase.s] + phrase.l - phrase.s
      end
    end
  end

  melodys.each do |w|
    max_index = p_arr[0..w].index(p_arr[0..w].max)
    if w - max_index > d_arr[max_index]
      puts '-1'
      return 0;
    end

    results << p_arr[max_index]
  end

  results.each do |result|
    puts result
  end
end

main

Measured memory_bytes: 6132
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	boolean[] isprime;
	int[] prime;
	void run(){
		prime =new int[1000000];
		isprime = new boolean[1000000];
		for(int i = 2; i < 1000000;i++ )
			isprime[i] = true;
		for(int i = 2; i < 1000000;i++ ){
			if(!isprime[i])
				continue;
			for(int j = i+i;j < 1000000;j+=i){
				isprime[j] = false;
			}
		}
		int count = 0;
		for(int i = 0;i < 1000000;i++){
			if(isprime[i]) count++;
			prime[i] = count;
		}
		
		for(;;){
			if(!sc.hasNextInt())break;
			int n = sc.nextInt();
			System.out.println(prime[n]);
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
		
	}
}

Measured memory_bytes: 17000
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

template <typename Cost = int> class Edge{
public:
  int from,to;
  Cost cost;
  Edge() {}
  Edge(int to, Cost cost): to(to), cost(cost){}
  Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){}

  Edge rev() const {return Edge(to,from,cost);}
  
  friend ostream& operator<<(ostream &os, const Edge &e){
    os << "(FROM: " << e.from << "," << "TO: " << e.to << "," << "COST: " << e.cost << ")";
    return os;
  }
};

template <typename T> using Graph = vector<vector<Edge<T>>>;
template <typename T> using Tree = vector<vector<Edge<T>>>;

template <typename C, typename T> void add_edge(C &g, int from, int to, T w){
  g[from].push_back(Edge<T>(from, to, w));  
}

template <typename C, typename T> void add_undirected(C &g, int a, int b, T w){
  g[a].push_back(Edge<T>(a, b, w));
  g[b].push_back(Edge<T>(b, a, w));
}

LLI dp[300000];
LLI counter[300000];

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

  int N,Q;
  while(cin >> N >> Q){
    Tree<int> tree(N);
    REP(i,N-1){
      int a,b; cin >> a >> b;
      --a, --b;
      add_undirected(tree,a,b,1);
    }

    fill_array(counter, 0);
    fill_array(dp, 0);

    
    REP(i,Q){
      int p,x; cin >> p >> x;
      --p;
      counter[p] += x;
    }

    function<void(int,int)> dfs =
      [&](int cur, int par){
        if(par>=0) dp[cur] += dp[par];
        dp[cur] += counter[cur];

        for(auto &e : tree[cur]){
          if(e.to == par) continue;
          dfs(e.to, cur);
        }
  
        return;
      };
    
    dfs(0,-1);
    
    REP(i,N){
      if(i) cout << " ";
      cout << dp[i];
    }
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 30592
n = int(input())
A = [int(x) for x in input().split()]
flag = True
for i in range(0, n) :
	if A[i] % 2 != 0 :
		continue
	elif A[i] % 2 == 0 and (A[i]%3 == 0 or A[i]%5 == 0) :
		continue
	else :
		flag = False
		break
if flag :
	print ("APPROVED")
else :
	print ("DENIED")

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

int main() {
int n,a;
cin>>n;
set<long long>vec;
double counter=0;
double counter1=0;
for(int i=0;i<n;i++){
cin>>a;
vec.insert(a);}
if(vec.size()==n)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;}


Measured memory_bytes: 9600
from collections import defaultdict

n = int(input())
s = input()
d = defaultdict(list)
has = defaultdict(set)
for i, c in enumerate(s):
    d[c].append(i)
    has[c].add(i)
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        need = list({'R', 'G', 'B'} - {s[i], s[j]})[0]
        a = d[need]
        left, right = -1, len(a)
        while left + 1 < right:
            mid = (left + right) >> 1
            if a[mid] <= j:
                left = mid
            else:
                right = mid
        if right != len(a):
            bad = j + j - i
            ret += len(a) - right - (bad in has[need])
print(ret)

Measured memory_bytes: 69592
require 'set'

(n, m) = gets.chomp.split(' ').map(&:to_i)

src = []
dst = []

m.times do
  (a, b) = gets.chomp.split(' ').map(&:to_i)
  
  if a == 1 then
    src.push(b)
  elsif b == n then
    dst.push(a)
  end
end

src = Set.new(src)
dst = Set.new(dst)

puts (src.intersect?(dst) ? 'POSSIBLE' : 'IMPOSSIBLE')

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

using namespace std;

typedef long long llint;
long long INF = 1e18;

llint dp[1 << 12];

int main() {
  int n, m;
  cin >> n >> m;
  vector<llint> a(m), b(m);
  vector<vector<llint>> c(m, vector<llint>(n));
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    for (int j = 0; j < b[i]; j++) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }

  for (int i = 0; i < 1 << n; i++) {
    dp[i] = INF;
  }
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    int now = 0;
    for (int j = 0; j < b[i]; j++) {
      now |= (1 << c[i][j]);
    }
    for (int bit = 0; bit < 1 << n; bit++) {
      if (dp[(bit | now)] > dp[bit] + a[i]) {
        dp[(bit | now)] = dp[bit] + a[i];
      }
    }
  }
  if (dp[(1 << n) - 1] == INF) dp[(1 << n) - 1] = -1;
  cout << dp[(1 << n) - 1] << endl;

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int left,right;
    string a;
    cin>>a;
    for(int i=0;i<a.length();i++)
        if(a[i]=='A'){
            left=i;
            break;
        }
    for(int i=a.length()-1;i>=0;i--)
        if(a[i]=='Z'){
            right=i;
            break;
        }
    cout<<right-left+1<<endl;
    return 0; 
}

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

int main() {
    int A, B;
    cin >> A >> B;
    int count = 0;
    for (int i = A; i <= B; i++) {
        int j = i;
        vector<int> vec(5);
        for (int k=0; k<5; k++) {
            vec.at(k) = j % 10;
            j /= 10; 
        }
        if (vec.at(0) == vec.at(4) && vec.at(1) == vec.at(3)) {
            count++;
        } 
    }
    cout << count << endl;
}


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

typedef long long Int;

int main(){
	const int MAX_N = 50;
	int N, K;
	int X1[MAX_N], Y1[MAX_N], D1[MAX_N], X2[MAX_N], Y2[MAX_N], D2[MAX_N];
	vector<int> X, Y, D;
	Int ans = 0;
	int k;
	
	scanf("%d%d", &N, &K);
	for(int i = 0; i < N; i++){
		scanf("%d%d%d%d%d%d", &X1[i], &Y1[i], &D1[i], &X2[i], &Y2[i], &D2[i]);
	}
	
	for(int i = 0; i < N; i++){
		X.push_back(X1[i] - 1); X.push_back(X1[i]);
		X.push_back(X2[i]); X.push_back(X2[i] + 1);
		Y.push_back(Y1[i] - 1); Y.push_back(Y1[i]);
		Y.push_back(Y2[i]); Y.push_back(Y2[i] + 1);
		D.push_back(D1[i] - 1); D.push_back(D1[i]);
		D.push_back(D2[i]); D.push_back(D2[i] + 1);
	}
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	sort(D.begin(), D.end());
	X.erase(unique(X.begin(), X.end()), X.end());
	Y.erase(unique(Y.begin(), Y.end()), Y.end());
	D.erase(unique(D.begin(), D.end()), D.end());
	
	for(int d = 0; d < D.size() - 1; d++){
		for(int y = 0; y < Y.size() - 1; y++){
			for(int x = 0; x < X.size() - 1; x++){
				k = 0;
				for(int i = 0; i < N; i++){
					if(X1[i] <= X[x] && Y1[i] <= Y[y] && D1[i] <= D[d]
					 && X2[i] >= X[x + 1] && Y2[i] >= Y[y + 1] && D2[i] >= D[d + 1]){
						k++;
					}
				}
				if(k >= K){
					ans += (Int)(X[x + 1] - X[x]) * (Y[y + 1] - Y[y]) * (D[d + 1] - D[d]);
				}
			}
		}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 1060
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         String N=gs();
         long r=0;
         for (int i=0; i<N.length();i++) {
        	 int a=Integer.parseInt(N.substring(i,i+1));
        	 r+=a;
         }

         if(r%9==0) {
        	 System.out.println("Yes");
         } else {
        	 System.out.println("No");
         }

         

     }

     public static long f(int n, int s, int e) {
    	 if(s<=e) {
    		 return e-s;
    	 } else {
    		 return n-s+e;
    	 }
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

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

int main() {
	int N, tmp, button, ans=1;
	cin >> N;
	vector<int> a(N);
	for (int i = 1; i <= N; i++) {
		cin >> tmp;
		a[i] = tmp;
	}

	button = a[1];

	for (int i = 0; i < N; i++) {
		if (button == 2) {
			cout << ans << endl;
			return 0;
		}
		button = a[button];
		ans++;
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N = 505;

int n;
long long a[N][N], pos[N][N], neg[N][N]; 
long long ans, sum, f[N][N];

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	scanf("%d", &n); 
	rep(i, 1, n) rep(j, 1, n) if (j != i) {
		scanf("%lld", &a[i][j]); 
		sum += a[i][j]; 
	}
	rep(i, 1, n) rep(j, i + 1, n) {
		pos[i][j] = a[j][i];
		neg[i][j] = a[i][j];
	}
	rep(i, 1, n) dec(j, i - 1, 1) {
		pos[j][i] += pos[j + 1][i];
		neg[j][i] += neg[j + 1][i];
	}
	rep(i, 1, n) rep(j, 1, (i > 1 ? i - 1 : 1)) {
		long long w = 0;
		//Pr("f[%d][%d] = %lld\n", i, j, f[i][j]); 
		rep(k, i + 1, n + 1) {
			f[k][i] = max(f[k][i], f[i][j] + w + neg[1][k] + pos[i][k]);
			//assert(f[k][i] <= sum);
			w += pos[j][k] + neg[1][k] - neg[i][k];
		}
	}
	rep(i, 1, n) ans = max(ans, f[n + 1][i]);
	printf("%lld\n", sum - ans);
	return 0;
}

Measured memory_bytes: 8192
#include <cstdint>
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  unordered_map<int64_t, int64_t> map;
  for (int n = 0; n < N; ++n) {
    int64_t num;
    cin >> num;
    ++map[num];
  }
  int64_t sum = 0;
  for (const auto& p : map) {
    sum += p.first * p.second;
  }
  int64_t Q;
  cin >> Q;
  for (int q = 0; q < Q; ++q) {
    int64_t B, C;
    cin >> B >> C;
    sum += (C - B) * map[B];
    cout << sum << endl;
    map[C] += map[B];
    map[B] = 0;
  }
  
  return 0;
}


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

int main(){
  int n,t,a;
  cin >> n >> t >> a;
  vector<int> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  vector<double> ans(n);
  for(int i = 0; i < n; i++){
    ans[i] = t-h[i]*0.006;
  }
  double ans1 = 1000000,ans2;
  for(int i = 0; i < n; i++){
    if(ans1 > abs(ans[i]-a)){
      ans2 = i+1;
      ans1 = abs(ans[i]-a);
    }
  }
  cout << ans2 << endl;
}

Measured memory_bytes: 3688
using System;

namespace AtBC179
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            int n = int.Parse(Console.ReadLine());
            for (int i = 1;i < n; i++)
            {
                for (int ii = 1; ii < n; ii++)
                {
                    if (i * ii >= n)
                    {
                        break;
                    }
                    count += 1;

                }

            

            }
            Console.WriteLine(count);
            
        }
    }
}

Measured memory_bytes: 27400
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int M=0,fst[SZ],vb[SZ],nxt[SZ],in[SZ],ou[SZ];
int ff[SZ];
int gf(int x) {return ff[x]?ff[x]=gf(ff[x]):x;}
void uni(int a,int b)
{
	int ga=gf(a),gb=gf(b);
	if(ga^gb) ff[ga]=gb;
}
void ad_de(int a,int b)
{++in[b]; ++ou[a]; uni(a,b);
++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}
int n,h;
bool bb[SZ];
#define GG {puts("NO"); exit(0);}
int main()
{
	scanf("%d%d",&n,&h);
	for(int i=1,a,b,c,d,l,r;i<=n;++i)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(!c) l=a; else l=-c;
		if(!d) r=-b; else r=d;
		ad_de(l+n+1,r+n+1);
	}
	for(int i=n+1;i<=n+n;++i)
		if(ou[i]<in[i]) GG
	for(int i=1;i<=n;++i)
		if(in[i]<ou[i]) GG
	for(int i=1;i<=n+n;++i)
		if(in[i]!=ou[i]) bb[gf(i)]=1;
	for(int i=1;i<=n+n;++i)
		if((in[i]||ou[i])&&gf(i)==i&&!bb[i]) GG
	puts("YES");
}

Measured memory_bytes: 10496
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#ifdef ONLINE_JUDGE
const int maxn = 3e5 + 10;
#else
const int maxn = 1e3 + 10;
#endif
using namespace std;
int N;
set<string> st;
string arr[maxn];
signed main()
{
    ios::sync_with_stdio(false);
    cin >> N;
    for (ri i = 1; i <= N; ++i) {
        cin >> arr[i];
    }
    st.insert(arr[1]);
    for (ri i = 2; i <= N; ++i) {
        if (st.count(arr[i]) || arr[i][0] != arr[i - 1].back()) {
            cout << "No" << endl;
            return 0;
        }
        st.insert(arr[i]);
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}


int main(){

    ll n, q; cin >> n >> q;
    string s; cin >> s;
    vll l(q), r(q); rep(i, q) cin >> l[i] >> r[i];

    vll a(n, 0);
    a[0] = 0;

    bool b = false;
    if(s[0]=='A') b = true;

    rep2(i, 1, n){
        a[i] = a[i-1];
        if(b && s[i]=='C'){
            a[i]++;
        }

        if(s[i]=='A'){
            b = true;
        }
        else{
            b = false;
        }
    }

    rep(i, q){
        cout << a[r[i]-1]-a[l[i]-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 5912
# C - Sum of product of pairs
import numpy as np

N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7
A = np.array(A)
csA = np.zeros((N+1), np.int64)
for i in range(N):
    csA[i+1] = (csA[i] + A[i]) % MOD
    
ans = 0
for i in range(N-1):
    ans += (A[i] * (csA[N] - csA[i+1])) % MOD
print(ans%MOD)

Measured memory_bytes: 50248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		boolean[][] grid = new boolean[100][100];
		for (int x = 0; x < grid.length; x++) {
			for (int y = 0; y < grid[x].length; y++) {
				grid[x][y] = x >= grid.length / 2;
			}
		}

		{
			int x = 0, y = 0;
			for (int i = 0; i < b - 1; i++) {
				grid[x][y] = true;
				if ((y += 2) >= grid[0].length) {
					y = 0;
					x += 2;
				}
			}
			x = grid.length - 1;
			y = 0;
			for (int i = 0; i < a - 1; i++) {
				grid[x][y] = false;
				if ((y += 2) >= grid[0].length) {
					y = 0;
					x -= 2;
				}
			}
		}

		System.out.println(grid.length + " " + grid[0].length);
		for (int x = 0; x < grid.length; x++) {
			for (int y = 0; y < grid[x].length; y++) {
				System.out.print(grid[x][y] ? '#' : '.');
			}
			System.out.println();
		}
	}

}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int MOD = (int)1e9 + 7;
const int N = (int)2e6 + 5;

int k, n;
char S[N];
ll pw26[N], pw25[N], fact[N], revfact[N];

ll fastExp(ll base, int p) {
	ll ret = 1;
	while (p) {
		if (p & 1) {
			ret = (ret * base) % MOD;
		}
		base = (base * base) % MOD;
		p >>= 1;
	}
	return ret;
}

ll comb(int n, int k) {
	ll ret = fact[n];
	ret = (ret * revfact[k]) % MOD;
	ret = (ret * revfact[n-k]) % MOD;
	return ret;
}

int main() {
	pw25[0] = pw26[0] = fact[0] = revfact[0] = 1;
	for (int i = 1; i < N; i++) {
		pw25[i] = (25 * pw25[i-1]) % MOD;
		pw26[i] = (26 * pw26[i-1]) % MOD;
		fact[i] = (1ll * i * fact[i-1]) % MOD;
		revfact[i] = fastExp(fact[i], MOD-2);
	}
	scanf("%d", &k);
	scanf("%s", S);
	int len = strlen(S);
	n = k + len;
	ll ans = pw26[n];
	for (int i = 0; i < len; i++) {
		ll mins = (comb(n,i) * pw25[n-i]) % MOD;
		ans = (ans - mins) % MOD;
		if (ans < 0) ans += MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 67252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {   
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //　点の数
        double d = sc.nextInt(); // 比較する距離
      
      	double x, y; // 座標の点
      	double kyori = 0; // 原点から点までの距離
      	int count = 0; // D以下の距離の点の数
      
        for(int i = 0; i < n; i++) {
          x = sc.nextInt();
          y = sc.nextInt();

          // 原点からの距離を計算する
          kyori = Math.sqrt(x * x + y * y);

          // 原点からの距離がD以下ならカウントする
          if (kyori <= d) {
            count++;
          }
        }    
      System.out.println(count);   
    }
}

Measured memory_bytes: 59212
(A, B, C, ) = [int(n) for n in input().split()]
(K, ) = [int(n) for n in input().split()]

while A >= B:
    B *= 2
    K -= 1

while B >= C:
    C *= 2
    K -= 1

if K >= 0:
    print('Yes')
else:
    print('No')
    



Measured memory_bytes: 9168
import itertools
N = int(input())
P_list = tuple(map(int,input().split()))
Q_list = tuple(map(int,input().split()))

tem_list = []
for i in range(1,N+1):
    tem_list.append(i)

check_list = list(itertools.permutations(tem_list,N))

for i in range(0,len(check_list)):
    if check_list[i] == P_list:
        tem_1 = i
for j in range(0,len(check_list)):
    if check_list[j] == Q_list:
        tem_2 = j

print(abs(tem_2-tem_1))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
int main(){
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0&&m==0) break;
    int a[100],b[100],suma=0,sumb=0;
    lp(i,n){
      cin>>a[i];
      suma+=a[i];
    }
    lp(i,m){
      cin>>b[i];
      sumb+=b[i];
    }
    int ans1=-1,ans2=-1;
    int sum=1000000;
    lp(i,n){
      lp(j,m){
	if(suma+b[j]-a[i]==sumb+a[i]-b[j]){
	  if(sum>a[i]+b[j]){
	    sum=a[i]+b[j];
	    ans1=a[i];
	    ans2=b[j];
	  }
	}
      }
    }
    if(ans1==-1&&ans2==-1)
      cout<<-1<<endl;
    else cout<<ans1<<" "<<ans2<<endl;
  }
  return 0;
}


Measured memory_bytes: 2984
S = input()
N = len(S)
a=S[0:int((N-1)/2)]
b=S[int((N+3)/2-1):int((N))]

c=list(a)
d=list(reversed(c))

e=list(b)
f=list(reversed(e))

if a==b and c==d and e==f:
    print('Yes')
else:
    print('No')   


Measured memory_bytes: 3064
n = gets.chomp.to_i
pp = gets.chomp.split(' ').map{|i| i.to_i }

count = 0
(pp.length - 2).times {|i|
  ii = i + 1
  # p [pp[ii - 1], pp[ii], pp[ii + 1]]
  # p pp[i]
  if [pp[ii - 1], pp[ii], pp[ii + 1]].sort[1] == pp[ii]
    count += 1
  end
}

puts count


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#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 pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=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;
}

void solve(){
    int n,m;
    while(true){
        cin >> n >> m;
        if(n==0&&m==0) break;
        vector<int> a(n),b(m);
        for(auto &x:a) cin >> x;
        for(auto &x:b) cin >> x;

        int pos=0;
        for(int i=0; i<m; ++i){
            pos+=b[i];
            if(pos>n-1) pos=n-1;
            pos+=a[pos];
            if(pos>=n-1){
                cout << i+1 << endl;
                break;
            }
        }
    }
}

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

Measured memory_bytes: 1204