akhauriyash/Code-Regression huggingface dataset:
N, D = gets.split(' ').map(&:to_i)
pts = N.times.map { gets.split(' ').map(&:to_i) }

cnt = 0

pts.combination(2) do |p1, p2|
  d = Math.sqrt(D.times.inject(0) { |s, i| s + ((p1[i] - p2[i]) ** 2) })
  cnt += 1 if d == d.floor
end

puts cnt


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

int main(){
  int n, w;
  cin >> n >> w;
  int dp[105][10000];
  for(int i=0; i<105; i++)
    for(int j=0; j<10000; j++)
      dp[i][j] = 0;
  vector< pair<int, int> > vec;
  rep(i, n){
    int v, w;
    cin >> v >> w;
    vec.push_back(make_pair(v, w));
  }
  for(int i=n-1; i>=0; i--){
    for(int j=0; j<=w; j++){
      if(vec[i].second > j) dp[i][j] = dp[i+1][j];
      else{
        dp[i][j] = max(dp[i+1][j], dp[i+1][j-vec[i].second]+vec[i].first);
      }
    }
  }
  cout << dp[0][w] << endl;
  return 0;
}


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

int main() {
  int N;
  cin>>N;
  if(N%1000==111||N/10==111||N%1000==222||N/10==222||N%1000==333||N/10==333||N%1000==444||N/10==444||N%1000==555||N/10==555||N%1000==666||N/10==666||N%1000==777||N/10==777||N%1000==888||N/10==888||N%1000==999||N/10==999||N%1000==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
n=int(input())

ls=set([1])
i=1
while 6**i<=100000:
  ls.add(6**i)
  i+=1
i=1
while 9**i<=100000:
  ls.add(9**i)
  i+=1

dp = [float("inf") for i in range(n+2)]
dp[0] = 0
ls=list(ls)
#円の総合計
for i in range(n+2):
  #額面のコインの種類
  for j in range(len(ls)):
    if i+ls[j]<=n:
      dp[i+ls[j]] = min(dp[i]+1, dp[i+ls[j]-1]+1,dp[i+ls[j]])
print(dp[n])

Measured memory_bytes: 6296
#include <cstdio>

char s[4];
int ans, cnt;

int getmax(int a, int b) {return a>b?a:b;}

int main() {
    scanf("%s", s);
    for (int i = 0 ; i < 3 ; i++) {
        if (s[i] == 'R') {
            ans = getmax(ans, ++cnt);
        }
        else cnt = 0;
    }
    printf("%d", ans);
}


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

int main()
{
    int a,b;
    int n,m;
    int k;
    int cnt = 0;
    int sum[40] = {};

    cin >> n >> m;
    for(int i = 0;i < n;i++){
        cin >> k;
        for(int i = 0;i < k;i++){
            cin >> a;
            sum[a]++;
        }
    }
    for(int i = 0;i <= m;i++){
        if(sum[i] == n) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args) {
       Scanner stdIn = new Scanner(System.in); 
       int p = stdIn.nextInt();
       int q = stdIn.nextInt();
       int r = stdIn.nextInt();
       System.out.println(Math.min(p+q , Math.min(q + r, r + p)));
    }
}

Measured memory_bytes: 23252
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class Main {

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

		int N = sc.nextInt();
		long K = sc.nextLong();
		int[][] S = new int[N][2];

		for(int i = 0 ; i < N ; i++){
			S[i][0] = sc.nextInt();
			S[i][1] = sc.nextInt();
		}
		sc.close();

	    Arrays.sort(S, new Comparator<int[]>() {
	        public int compare(int[] o1, int[] o2) {
	            //return o1[0] - o2[0];    //[0] をキーにソート(昇順)
	            return o1[0] - o2[0];    //[0] をキーにソート(降順)
	        }
	    });

	    long tmp = 0 ;
	    for(int i = 0 ; i < N ; i++){
	    		tmp += S[i][1];
	    		if(tmp >=K){
	    			System.out.println(S[i][0]);
	    			break;
	    		}
	    }
	}
}


Measured memory_bytes: 88896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int min=1;
		int max=N;
		for(int i=0; i<M; i++) {
			int l=sc.nextInt();
			int r=sc.nextInt();
			if(r<min) {
				pl(0);
				System.exit(0);
			}
			else if(r<=max) {
				max=Math.min(r, max);
				min=Math.max(min, l);
			}
			else if(l<=max) {
				max=Math.min(r, max);
				min=Math.max(min, l);
			}
			else {
				pl(0);
				System.exit(0);
			}
			if(min>max) {
				pl(0);
				System.exit(0);
			}
		}
		pl(max-min+1);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

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

int getDight(long long n){
    return (int)(log10(n) + 1);
}

void calculate(){
    long long n;
    cin >> n;
    int res = 20;
    for(long long i = 1;i * i <= n;++i){
        if(n % i == 0){
            res = min(res,max(getDight(i),getDight(n / i)));
        }
    }
    cout << res << '\n';
}

int main(int, char**) {
    calculate();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long sum = 0;
    for(long long i = 1;i<=n;i++)
        sum+=i;
        cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define mod(a,b) ((a-b)>0? a-b : b-a)
#define min(a,b) (a<b? a : b)

int main(){
	int n, k, pedra[100000], custo[100000], t;
	
	scanf("%d%d", &n, &k);
	for(int i=0; i<n; i++)
		scanf("%d", &pedra[i]);
	
	custo[0] = 0;
	for(int i=1; i<k && i<n; i++){
		custo[i] = custo[i-1] + mod(pedra[i-1], pedra[i]);
		for(int j=2; j<=i; j++){
			t = custo[i-j] + mod(pedra[i-j], pedra[i]);	
			custo[i] = min(custo[i], t);
		}
	}
	for(int i=k; i<n; i++){
		custo[i] = custo[i-1] + mod(pedra[i-1], pedra[i]);
		for(int j=i-k; j<i-1; j++){
			t = custo[j] + mod(pedra[j], pedra[i]);	
			custo[i] = min(custo[i], t);
		}
	}

	printf("%d\n", custo[n-1]);
	return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <string>
#include <functional>

using namespace std;


int main() {
	int N;
	cin >> N;
	(N % 2 == 0) ? cout << N << endl : cout << N * 2 << endl;
	return 0;
}

Measured memory_bytes: 256
src = list(map(int, input().split()))


def change(array, index_1st, index_2nd):
    tmp = array[index_1st]
    array[index_1st] = array[index_2nd]
    array[index_2nd] = tmp


change(src, 0, 1)
change(src, 0, 2)

print('{} {} {}'.format(src[0], src[1], src[2]))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B=99999999,C=753;
  string S,S2;cin >> S;
  int D=S.size();
  for(int i=0;i<D-2;i++){
    S2=S.substr(i,3);
    A=stoi(S2);
    A=C-A;
    if(A<0)A*=-1;
    if(B>A)B=A;
  }
  cout << B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int c = 0;
int main() {
  cin >> s;
  if(s[0] == '1') c++;
  if(s[1] == '1') c++;
  if(s[2] == '1') c++;
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	int N, D;
	cin >> N >> D;
	vector<vector<int>> x(N, vector<int>(D));
	rep(n, N) {
		rep(d, D) {
			cin >> x[n][d];
		}
	}

	int ans = 0;

	for(int i=0; i<N; i++) {
		for(int j=i+1; j<N; j++) {
			int sum = 0;
			rep(d, D) {
				sum += (x[i][d] - x[j][d])*(x[i][d] - x[j][d]);
			}

			if(sum==(int)sqrt(sum)*(int)sqrt(sum)) ans++;

		}
	}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        switch (s) {
            case "SUN":
                System.out.println(7);
                break;
            case "MON":
                System.out.println(6);
                break;
            case "TUE":
                System.out.println(5);
                break;
            case "WED":
                System.out.println(4);
                break;
            case "THU":
                System.out.println(3);
                break;
            case "FRI":
                System.out.println(2);
                break;
            case "SAT":
                System.out.println(1);
                break;
        }
    }
}

Measured memory_bytes: 23636
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
 
      int X = sc.nextInt();
      if(X>=30){
   		System.out.println("Yes");   
      }else{
      	System.out.println("No");
      }
    }
}

Measured memory_bytes: 27060
from collections import Counter

n, p = map(int, raw_input().rstrip().split(' '))
a = map(int,raw_input().rstrip().split(' '))
ct = Counter(ai%2 for ai in a)
even, odd = ct[0], ct[1]
c_even = 2**even
nCk = 1
n = odd
k = 0
d = n
c_odd = 0
while k <= n:
    if k % 2 == p:
        c_odd += nCk
    k += 1
    nCk = nCk * d / k
    d -= 1
print c_even * c_odd


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  ll t = x;
  x = y;
  y = t;

  t = x;
  x = z;
  z = t;

  cout << x << " " << y << " " << z << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<math.h>
#include<stdlib.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, pii > piii;
typedef pair<double, double> pdd;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N;
int a[1010];

int abss(int A){
    if(A < 0)return -A;
    return A;
}

signed main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a, a + N);
    cout << a[N - 1] - (a[N - 1] + a[0]) / 2 << endl;

    return 0;
}

/*

*/


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

int main(){
  int64_t n,a=0,b=0;
  cin >> n;
  vector<int64_t> h(n);
  for(int64_t i=0; i<n; i++){
    cin >> h[i];
  }
  for(int64_t i=0; i<n-1; i++){
    if(h[i]>=h[i+1]){
      a++;
    }else{
      if(a>b){
        b=a;
      }
      a=0;
    }
  }
  if(a>b){
      b=a;
  }
  cout << b << endl;
}

Measured memory_bytes: 1024
{-# LANGUAGE MultiWayIf #-}
main :: IO ()
main = do
  [n, m] <- (map read . words) <$> getLine :: IO [Int]
  print $ if
          | n== 2 || m == 2 -> 0
          | n == 1 && m == 1 -> 1
          | n == 1 -> m - 2
          | m == 1 -> n - 2
          | otherwise -> (n - 2) * (m - 2)


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    for(int i=0; i<4; i++){
        if(s[i] == '+') ans++;
        else ans--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    int N, Y;
    int x, y, z;
    
    cin >> N >> Y;
    
    bool judge = false;
    for(x = 0; x <= N; x++){
        for(y = 0; y <= N - x; y++){
            z = N - x - y;
            
            if(x * 10000 + y * 5000 + z * 1000 == Y){
                judge = true;
                break;
            }
        }
        
        if(judge){
            break;
        }
    }
    
    
    if(judge){
        cout << x << " " << y << " " << z << "\n";
    }
    else{
        cout << -1 << " " << -1 << " " << -1 << "\n";
    }
}

Measured memory_bytes: 256
n = int(input())
t = [tuple(map(int, input().split())) for _ in range(n)]

def dis(a, b, c, d):
    return ((a - c) ** 2 + (b - d) ** 2) ** (1/2)

s = 0
m = 0
for i in range(n):
    for j in range(i+1, n):
        a, b = t[i]
        c, d = t[j]
        s += dis(a, b, c, d)
        m += 1

ans = (s / m * (n-1))
print(ans)

Measured memory_bytes: 38512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    int a[1000],b[1000];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int k=1;
    b[0]=a[1];
    for(int i=1;i<n;i++)
    {
        if(a[i]!=a[i-1])
        {
            b[k]=a[i];
            k++;
        }
    }
    printf("%d",k);
    return 0;
}


Measured memory_bytes: 256
s=input()
s_l=len(s)

left=[0 for i in range(s_l+1)]
right=[0 for i in range(s_l+1)]

for i in range(s_l):
  if s[i]=='<':
    left[i+1]=left[i]+1
for i in range(s_l-1,-1,-1):
  if s[i]=='>':
    right[i]=right[i+1]+1

ans=0
for i,j in zip(left,right):
  ans+=max(i,j)
print(ans)

Measured memory_bytes: 27944
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int N;
	int M;
	cin >> N >> M;
	vector<int> A(N);
	int day = 0;
	int ans = 0;
	for(int i = 0;i<M;i++){
		std::cin >> A[i];
		day += A[i];
	}
	
	int N_day = 0;
	
	if(N-day>=0){
		N_day = N;
		ans = N_day - day;
	    std::cout << ans <<  std::endl;
	}else{
		std::cout << "-1" <<  std::endl;
	}
}

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

using namespace std;
const int datasize=200000;
int composite[datasize]={0};

int sumofprime(int n){
  int sum=0;
  int count=0;
  for(int i=0;i<datasize&&count!=n;i++){
    if(!composite[i]){
      sum+=i;
      count++;
    }
  }
  return sum;
}
int main(){
  composite[0]=composite[1]=1;
  for(int i=2;i<datasize;i++){
    if(!composite[i]){
      for(int j=2*i;j<datasize;j+=i){
        composite[j]=1;
      }
    }
  }
  int n;
  vector<int> sum;
  while(cin>>n&&n){
    sum.push_back(sumofprime(n));
  }
  for(int i=0;i<sum.size();i++){
    cout<<sum[i]<<endl;
  }
}

Measured memory_bytes: 1996
n, m, c = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
ans = 0
n.times do 
  a = gets.split.map(&:to_i)
  ans += 1 if a.zip(b).reduce(0){|s, (x, y)| s + (x * y)} + c > 0
end
p ans

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
    int n;
    cin >> n;
    double x[n], y[n];
    for (int i = 0; i < n; i++)
        cin >> x[i];
    for (int i = 0; i < n; i++)
        cin >> y[i];
    cout << fixed << setprecision(8);
    for (int j = 1; j <= 3; j++) {
        double sum = 0;
        for (int i = 0; i < n; i++)
            sum += pow(abs(x[i] - y[i]), j);
        cout << pow(sum, 1.0 / j) << '\n';
    }
    double max = abs(x[0] - y[0]);
    for(int i = 1; i < n; i++)
        if (abs(x[i] - y[i]) > max)
            max = abs(x[i] - y[i]);
    cout << max << '\n';
    return 0;
}


Measured memory_bytes: 3476
import sys
a = input()
b = map(int, input().split())
list = []
for item in b:
    if item % 2 == 0:
        list.append(item)
for item in list:
    if not(item % 3 == 0) and not(item % 5 == 0):
        print("DENIED")
        sys.exit()
print("APPROVED")

Measured memory_bytes: 3060
<?php

fscanf(STDIN, "%d %d %d %d", $x, $y, $z, $k);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$B = array_map('intval', explode(' ', trim(fgets(STDIN))));
$C = array_map('intval', explode(' ', trim(fgets(STDIN))));
rsort($A);
rsort($B);
rsort($C);

$ABC = [];
for ($a = 0; $a < $x; ++$a) {
    for ($b = 0; $b < $y; ++$b) {
        if (($a + 1) * ($b + 1) > $k) break;
        for ($c = 0; $c < $z; ++$c) {
            if (($a + 1) * ($b + 1) * ($c + 1) > $k) break;

            $ABC[] = $A[$a] + $B[$b] + $C[$c];
        }
    }
}

rsort($ABC);
for ($i = 0; $i < $k; ++$i) {
    echo $ABC[$i], PHP_EOL;
}


Measured memory_bytes: 10744
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
# define ll unsigned long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000007
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)
const ll mod = 1000000007;
const int K = 2;
//typedef vector<vector<int> > matrix;
/*
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	a += mod;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}
*/

signed main() {
	gok

  char x;
  cin>>x;
  if(x<97)
    cout<<'A';
  else
    cout<<'a';













  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <algorithm>
using namespace std;
bool same(int *a, int *b)
{
	int t1[3], t2[3];
	t1[0]=a[0];
	t1[1]=a[1];
	t1[2]=a[2];
	
	t2[0]=b[0];
	t2[1]=b[1];
	t2[2]=b[2];
	sort(t1,t1+3);
	sort(t2,t2+3);
	return (t1[0]==t2[0]&&t1[1]==t2[1]&&t1[2]==t2[2]);
}
int main()
{
	int a[3];
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	int cc= 0;
	bool infin=false;
	while(true)
	{
		if(a[0]%2==1||a[1]%2==1||a[2]%2==1) break;
		int b[3];
		b[0]=a[0]/2;
		b[1]=a[1]/2;
		b[2]=a[2]/2;
		int c[3];
		c[0]=b[1]+b[2];
		c[1]=b[0]+b[2];
		c[2]=b[0]+b[1];
		if(same(a,c))
		{
			infin = true;
			break;
		}
		a[0] = c[0];
		a[1] = c[1];
		a[2] = c[2];
		cc++;
	}
	if(infin) printf("-1");
	else printf("%d",cc);
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ===============================================================================

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

  // 累積和をとる
  map<ll, ll> rui;
  ll s = 0;
  for (int i = 0; i < n; i++) {
    s += v[i];
    rui[s]++;
  }
  rui[0]++;

  ll ans = 0;
  for (auto x : rui) {
    ans += x.second * (x.second - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 14336
S = input()
A, B, C, D = S[0], S[1], S[2], S[3]
ope = ["+++", "+-+", "++-", "+--", "-++", "--+", "-+-", "---"]


for i in range(8):
    ope1 = ope[i][0]
    ope2 = ope[i][1]
    ope3 = ope[i][2]
    val = A + ope1 + B + ope2 + C + ope3 + D
    if eval(val) == 7:
        ans = val + "=7"
        break


print(ans)


Measured memory_bytes: 3064
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	static void solve(){//Here is the main function
		ArrayList<Integer> one = nextIntArray();
		int A = one.get(0);
		int B = one.get(1);
		myout((A % B != 0) ? A : -1);
	}
	//Method addition frame start



	//Method addition frame end

	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
}


Measured memory_bytes: 32896
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

main :: IO ()
main = do
  [n,m,c] <- readInts
  bs <- readInts
  ds <- replicateM n readInts
  print $ solve c bs ds

solve :: Int -> [Int] -> [[Int]] -> Int
solve c bs = foldl' f e
  where
    e = 0
    f n ds
      | sum (zipWith (*) bs ds) + c > 0 = n+1
      | otherwise = n

-- util
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

Measured memory_bytes: 636
// Problem : D - String Formation
// Contest : AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    string s;
    int q;
    cin >> s >> q;
    
    deque<char> dq;
    for (char c : s)
        dq.push_back(c);
    
    bool rev = false;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1)
            rev = !rev;
        else {
            int f;
            char c;
            cin >> f >> c;
            if (rev)
                f = 3 - f;
            if (f == 1)
                dq.push_front(c);
            else
                dq.push_back(c);
        }
    }
    
    if (rev) {
        for (auto it=dq.rbegin(); it!=dq.rend(); it++)
            cout << *it;
        cout << "\n";
    } else {
        for (char c : dq)
            cout << c;
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 976
#include<stdio.h>
#include<stdlib.h>
const long mod = 1000000007l;
int N, K, p=0, n=0;
long posi[1<<18], nega[1<<18], ans = 1;
int cmp(const void *a, const void *b){
	return abs(*(int*)b) - abs(*(int*)a);
}
int main(){
	scanf("%d%d", &N, &K);
	if(N == K){
		long ans = 1;
		while(N--){
			long A;
			scanf("%ld", &A);
			ans *= A;
			ans %= mod;
		}
		printf("%ld\n", (ans + mod) % mod);
		return 0;
	}
	for(int i=0; i<N; i++){
		long A;
		scanf("%ld", &A);
		if(A < 0){
			nega[n++] = A;
		}else {
			posi[p++] = A;
		}
	}
	qsort(nega, n, sizeof(long), cmp);
	qsort(posi, p, sizeof(long), cmp);
	if((p==0 || N==K) && K&1){
		for(int i=0; i<K; i++){
			ans = ans * (nega[n-i-1] + mod) % mod;
		}
		printf("%ld\n", ans);
		return 0;
	}
	int np = 0, nn = 0;
	while(K){
		if(p-np <= 1 || n-nn <= 1){
			if(K == 1){
				if(p > np){
					ans *= posi[np++];
					ans %= mod;
					K--;
				}else return 1;
			}else{
				if(p-np <= 1){
					ans *= nega[nn] * nega[nn+1] % mod;
					ans %= mod;
					K -= 2;
					nn += 2;
				}else {
					ans *= posi[np++];
					ans %= mod;
					K--;
				}
			}
		}else {
			if(posi[np] * posi[np+1] > nega[nn] * nega[nn+1] || K==1){
				ans *= posi[np++];
				ans %= mod;
				K--;
			}else {
				ans *= nega[nn] * nega[nn+1] % mod;
				ans %= mod;
				nn += 2;
				K -= 2;
			}
		}
	}
	printf("%ld\n", ans);
	return 0;
}

Measured memory_bytes: 4132
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

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

    long long ans = 1;
    vector<int> v(n+1, 0);
    v[0] = 3;
    for(int i=0; i<n; ++i){
        ans *= v[a[i]];
        ans %= MOD;
        -- v[a[i]];
        ++ v[a[i]+1];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

ll gcd(ll a,ll b)
{
  if(a>b)swap(a,b);
  if(a==0){return b;}
  else return gcd(b%a,a);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  ll res=1LL;
  rep(i,n)
  {
    ll t;cin>>t;
    res=res/gcd(res,t)*t;
  }
  cout<<res<<endl;

  return 0;

}


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

int main(){
  ll n,k;
  cin >>n >>k;
  vector<ll> a(n);
  rep(i,n) cin >>a[i];
  ll sum = 0;
  sort(a.rbegin(), a.rend());
  for(int i = k; i<n; i++){
    sum += a[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int p[3];
int d[2];
void solve(){


}
int main(){
  for(int i=0;i<3;i++){
    cin>>p[i];
  }
  for(int i=0;i<2;i++){
    cin>>d[i];
  }
  sort(p,p+3);
  sort(d,d+2);
  cout<<p[0]+d[0]-50<<endl;
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
int f(int a, int b, int c) {
	int r = 0;
	r += (a % 5) * 380;
	r += (a / 5) * 1520;
	r += (b % 4) * 550;
	r += (b / 4) * 1870; 
	r += (c % 3) * 850;
	r += (c / 3) * 2244;
	return r;
}
int main() {
	int n;
	while (cin >> n, n) {
		int ans = 114514;
		for (int i = 0; i <= 10; i++) {
			for (int j = 0; j <= 10; j++) {
				for (int k = 0; k <= 10; k++) {
					if (i * 200 + j * 300 + k * 500 == n)ans = min(ans, f(i, j, k));
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned int uint;
typedef pair<int,int> pii;
//-------------------------------------------------------------------LYYY↓
namespace LYYY{
	int rd()
	{
		int s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	LL rdl()
	{
		LL s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	void wt(int x)
	{
		if(x>=10) wt(x/10);
		putchar(x%10+48);
	}
	void WT(int x)
	{
		if(x<0) x=-x,putchar(45);
		wt(x);
	}
	void wtl(LL x)
	{
		if(x>=10) wtl(x/10);
		putchar(x%10+48);
	}
	void WTL(LL x)
	{
		if(x<0) x=-x,putchar(45);
		wtl(x);
	}
}using namespace LYYY;
//-------------------------------------------------------------------bianliang↓
const int maxn=111111;
pii A[maxn];
int N,L[maxn],R[maxn];
//-------------------------------------------------------------------hanshu↓
int solve()
{
	L[N]=A[N].first,R[N]=A[N].second;
	int l=A[1].first,r=A[1].second;
	for(int i=N-1;i>=1;--i)
	{
		L[i]=max(L[i+1],A[i].first);
		R[i]=min(R[i+1],A[i].second);
	}
	int ans=0;
	for(int i=2;i<=N;++i)
	{
		ans=max(ans,max(0,r-l+1)+max(0,R[i]-L[i]+1));
		r=min(r,A[i].second),l=max(l,A[i].first);
	}
	return ans;
}
bool cmp1(pii x,pii y)
{
	if(x.first!=y.first) return x.first<y.first;
	return x.second>y.second;
}
bool cmp2(pii x,pii y)
{
	if(x.second!=y.second) return x.second<y.second;
	return x.first<y.first;
}
bool cmp3(pii x,pii y)
{
	if(x.second!=y.second) return x.second<y.second;
	return x.first>y.first;
}

bool cmp4(pii x,pii y)
{
	if(x.second-x.first!=y.second-y.first) return x.second-x.first<y.second-y.first;
	return x.first<y.first;
}
bool cmp5(pii x,pii y)
{
	if(x.second-x.first!=y.second-y.first) return x.second-x.first<y.second-y.first;
	return x.first>y.first;
}


bool cmp6(pii x,pii y)
{
	if(x.second-x.first!=y.second-y.first) return x.second-x.first<y.second-y.first;
	return x.second<y.second;
}
bool cmp7(pii x,pii y)
{
	if(x.second-x.first!=y.second-y.first) return x.second-x.first<y.second-y.first;
	return x.second>y.second;
}
//-------------------------------------------------------------------main()↓
int main()
{
	srand(time(NULL));
	N=rd();
	int ans=0;
	for(int i=1;i<=N;++i) A[i].first=rd(),A[i].second=rd(),ans=max(ans,A[i].second-A[i].first+1);
	sort(A+1,A+1+N);
	ans=max(ans,solve());
	sort(A+1,A+1+N,cmp1);
	ans=max(ans,solve());
	sort(A+1,A+1+N,cmp2);
	ans=max(ans,solve());
	sort(A+1,A+1+N,cmp3);
	ans=max(ans,solve());
	sort(A+1,A+1+N,cmp4);
	ans=max(ans,solve());
	sort(A+1,A+1+N,cmp5);
	ans=max(ans,solve());
	sort(A+1,A+1+N,cmp6);
	ans=max(ans,solve());
	sort(A+1,A+1+N,cmp7);
	ans=max(ans,solve());
	for(int i=1;i<=10;++i) random_shuffle(A+1,A+1+N),ans=max(ans,solve());
	WT(ans);
}

Measured memory_bytes: 1792
N,M,Q=map(int,input().split())
L = []
for i in range(Q):
  L.append(list(map(int, input().split())))
  L[i][0]-=1
  L[i][1]-=1

import itertools

l =list(range(1,M+1))
ans=0

v=list(itertools.combinations_with_replacement(l,N))

for arr in v:
  score=0
  for a,b,c,d in L:
    if (arr[b] - arr[a])==c:
      
      score+=d
  ans=max(ans,score)
print(ans)

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

typedef complex<double> P;

int n;
double r, t;
P p[20];
bool c[20][20][20];
double d[20][20];
double dp[10010][20][20];

int main()
{
	cin >> n >> r >> t;
	t = t / 180.0 * acos(-1.0);
	for (int i = 0; i < n; i++){
		double x, y;
		cin >> x >> y;
		p[i] = P(x, y);
	}
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			for (int k = 0; k < n; k++){
				if (i == j) continue;
				if (j == k) continue;
				if (k == i) continue;
				double a = abs(arg((p[j] - p[i]) / (p[k] - p[j])));
				if (a <= t){
					c[i][j][k] = true;
				}
			}
		}
	}

	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			d[i][j] = abs(p[i] - p[j]);
		}
	}

	fill_n(**dp, 10010 * 20 * 20, 99999.9);
	for (int i = 1; i < n; i++){
		dp[1][0][i] = d[0][i];
	}

	int res = 0;
	for (int i = 1; i < 10005; i++){
		for (int j = 0; j < n; j++){
			for (int k = 0; k < n; k++){
				if (dp[i][j][k] <= r) res = i;
				for (int l = 0; l < n; l++){
					if (!c[j][k][l]) continue;
					dp[i + 1][k][l] = min(dp[i + 1][k][l], dp[i][j][k] + d[k][l]);
					dp[i + 1][k][l] = min(dp[i + 1][k][l], 99999.9);
				}
			}
		}
	}
	
	cout << res << endl;
}

Measured memory_bytes: 34840
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int n = readln.chomp.to!int;
  int[int] cnt;
  foreach (a; readln.chomp.split.map!(to!int)) {
    cnt[a - 1]++;
    cnt[a]++;
    cnt[a + 1]++;
  }
  int ans = 0;
  foreach (k, v; cnt) {
    ans = max(ans, v);
  }
  ans.writeln;
}


Measured memory_bytes: 8892
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;

typedef struct{
	string product;
	int num;
	string stuff[100];
}recipe;

int n, m;
map<string, long> mp; //普通に買うときの値段
recipe r[100];

long rec(string a){
	long ret=0;	
	int p=-1;
	
	//合成可能か
	bool find=false;
	for(int i=0; i<m; ++i){
		if(r[i].product==a){
			find=true;
			p=i;
			break;
		}
	}
	
	if( !find ) ret=mp[a]; //無理だった		
	else{
		for(int i=0; i<r[p].num; ++i){
			ret+=rec(r[p].stuff[i]);
		}
		
		ret=min(ret, mp[a]);
	}
	
	return ret;
}

int main(){
	while(1){		
		//入力
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i){
			string s;
			long p;
			cin >> s >> p;
			mp[s]=p;
		}
		
		scanf(" %d", &m);
		for(int i=0; i<m; ++i){
			cin >> r[i].product;
			cin >> r[i].num;
			for(int j=0; j<r[i].num; ++j) cin >> r[i].stuff[j];
		}
		
		string want;
		cin >> want;
		
		//処理
		printf("%ld\n", rec(want));
	}	
}

Measured memory_bytes: 1360
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<math.h>
#include<string.h>
#define ll long long

using namespace std;
const int inf=0x3f3f3f3f;

int aa[15][15];
int la[15];
int wei[15];

void ppp(int i)
{
    memset(wei,0,sizeof(wei));
    int step=1;
    while(i)
    {
        wei[step]=i%2;
        i/=2;
        step++;
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>aa[i][0];
        for(int j=1;j<=aa[i][0];j++)
        {
            cin>>aa[i][j];
        }
    }
    for(int i=1;i<=m;i++)
    {
        cin>>la[i];
    }
    int ans=0;
    for(int i=0;i<pow(2,n);i++)
    {
        ppp(i);
        int temp=0;
        for(int j=1;j<=m;j++)
        {
            int sum=0;
            for(int k=1;k<=aa[j][0];k++)
            {
                if(wei[aa[j][k]]==1) sum++;
            }
            if(sum%2==la[j]) temp++;
        }
        if(temp==m) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>


int main()
{
   int n,k,c=0;
   scanf("%d %d", &n,&k);
   while(n/k>0)
   {
       n=n/k;
       c++;
   }
   printf("%d", c+1);
}


Measured memory_bytes: 128
def solve_max_square(arr, sz)
  maxWidth = 0
  w = Array.new(sz){Array.new(sz){-1}}
  sz.times{|i|
    w[i][0] = (arr[i][0] == "." ? 1 : 0)
    w[0][i] = (arr[0][i] == "." ? 1 : 0)
  }
  sz.times{|i|
    sz.times{|j|
      next if arr[i][j] == "*"
      if w[i-1][j-1] > -1 && w[i][j-1] > -1 && w[i-1][j] > -1 then
        w[i][j] = [w[i-1][j-1], w[i][j-1], w[i-1][j]].min + 1
        maxWidth = maxWidth > w[i][j] ? maxWidth : w[i][j]
      else
        w[i][j] = 1
      end
    }
  }
  return maxWidth
end

while n = gets.to_i
  break if n == 0
  arr = []
  n.times{|i|
    arr[i] = gets.chomp.split("")
  }
  p solve_max_square(arr,n)
end

Measured memory_bytes: 112476
#include <stdio.h>
#include <string.h>

#define LONG long

int done[128][10][1024];
LONG memo[128][10][1024];

LONG num(int i, int n, int s)
{	
	if (i > 101 || s < 0){
		return (0);
	}
	
	if (done[i][n][s]){
		return (memo[i][n][s]);
	}
	
	if (n == 0){
		return (s == 0);
	}
	
	done[i][n][s] = 1;
	memo[i][n][s] = num(i + 1, n - 1, s - i) + num(i + 1, n, s);
	
	return (memo[i][n][s]);
}

int main(void)
{
	int n, s;
	
	while (1){
		scanf("%d %d", &n, &s);
		
		if (!n && !s){
			break;
		}
		
		memset(done, 0, sizeof(done));
		memset(memo, 0, sizeof(memo));
		
		printf("%ld\n", num(0, n, s));
	}
	
	return (0);
}

Measured memory_bytes: 15972
N, A, B = map(int, input().split())
sums = 0

for i in range(1, N+1):
    tmp = 0
    num = i

    while 1:
        tmp += num%10
        num = int(num/10)
        if num == 0:
            break

    if A <= tmp <= B:
        sums += i


print(sums)

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

int main(){
  int x,y;
  cin >> x >> y;
  int ans = 0;
  if(x==1&y==1){cout << 1000000 << endl;return 0;}
  if(x==1)ans += 300000;
  if(x==2)ans += 200000;
  if(x==3)ans += 100000;
  if(y==1)ans += 300000;
  if(y==2)ans += 200000;
  if(y==3)ans += 100000;
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

bool calc(int n) {
    for (int i = 0; i * 4 <= n; i++) {
        for (int j = 0; j * 7 <= n; j++) {
            if (n == i * 4 + j * 7) {
                return true;
            }
        }
    }
    return false;
}

void main() {
    int n = readint;
    writeln(calc(n) ? "Yes" : "No");
}


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

using ll = long long;
const int maxn = 4e5 + 3;

struct node {
    int s;
    ll bc, pc, t;
    node *l, *r;
    void tag(ll u) {
        t += u;
        pc += bc * u;
    }
    void down() {
        if(t) {
            if(l->s)
                l->tag(t);
            if(r->s)
                r->tag(t);
            t = 0;
        }
    }
    void up() {
        s = l->s + r->s;
        bc = l->bc + r->bc;
        pc = l->pc + r->pc;
        t = 0;
    }
} np[maxn * 11], *root[maxn], nil{0, 0, 0, 0, &nil, &nil};

int npl;
node *alloc() {
    return &(np[npl++] = nil);
}

node *merge(node *u, node *v, int l = 0, int r = maxn / 2) {
    if(!u->s || !v->s) {
        return u->s ? u : v;
    }
    if(r - l <= 1) {
        u->pc += v->pc;
        u->pc -= u->bc * v->bc;
        u->bc += v->bc;
        return u;
    }
    u->down();
    v->down();
    int mid = (l + r) / 2;
    u->l = merge(u->l, v->l, l, mid);
    u->r = merge(u->r, v->r, mid, r);
    u->up();
    return u;
}

node * setBc(node *u, int c, ll bc, int l = 0, int r = maxn / 2) {
    if(!u || u == &nil) {
        u = alloc();
    }
    if(r - l <= 1) {
        u->s = 1;
        u->bc = bc;
        return u;
    }
    u->down();
    int mid = (l + r) / 2;
    if(c < mid) {
        u->l = setBc(u->l, c, bc, l, mid);
    } else {
        u->r = setBc(u->r, c, bc, mid, r);
    }
    u->up();
    return u;
}

int n, color[maxn], s[maxn], p[maxn];
std::vector<int> E[maxn];

void dfs(int u) {
    root[u] = setBc(&nil, color[u], 1);
    root[u]->tag(1);
    s[u] = 1;
    for(auto &&v : E[u]) {
        if(p[u] == v)
            continue;
        p[v] = u;
        dfs(v);
        root[u]->tag(s[v]);
        root[v]->tag(s[u]);
        root[u] = merge(root[u], root[v]);
        s[u] += s[v];
        root[u] = setBc(root[u], color[u], s[u]);
    }
}

void output(node *u, int l = 0, int r = maxn / 2) {
    if(r - l <= 1) {
        if(l >= 1)
            printf("%lld\n", u->pc);
        return;
    }
    u->down();
    int mid = (l + r) / 2;
    output(u->l, l, mid);
    if(mid <= n) {
        output(u->r, mid, r);
    }
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", color + i);
    }
    for(int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        E[u].push_back(v);
        E[v].push_back(u);
    }
    dfs(1);
    output(root[1]);
    return 0;
}

Measured memory_bytes: 214068
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cassert>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  string s; cin >> s;

  char c0 = s[0];
  bool same = true;
  rep(i, m) {
    if (s[i] != c0) {
      same = false;
      break;
    }
  }
  
  if (same) {
    // 0: s[0] = c[0] && s[i] = c[0]
    // 1: s[0] = c[0] && s[i] != c[0]
    // 2: s[0] != c[0] && s[i] = c[0]
    // 3: s[0] != c[0] && s[i] != c[0]
    vector<ll> dp1(4); 
    vector<ll> dp2(4);
    dp1[0] = 1;
    dp1[3] = 1;
    for(int i=1; i<n-1; i++) {
      dp2[0] = dp1[0] + dp1[1];
      dp2[0] %= mod;
      dp2[1] = dp1[0];
      dp2[2] = dp1[2] + dp1[3];
      dp2[2] %= mod;
      dp2[3] = dp1[2];
      rep(j, 4) {
        dp1[j] = dp2[j];
        //debug(j);debugln(dp1[j]);
      }
    }
    ll ans = 0;
    ans += dp1[0] + dp1[1];
    ans += dp1[0];
    ans += dp1[2] + dp1[3];
    cout << ans%mod << endl;
    return 0;
  }

  if (n%2 != 0) {
    cout << 0 << endl;
    return 0;
  }

  char before = c0;
  int cnt = 0;
  int minfirst = INT_MAX;
  int minodd = INT_MAX;
  rep(i, m) {
    if (s[i] == c0) {
      cnt++;
    } else {
      if (minfirst == INT_MAX) {
        chmin(minfirst, cnt);
      }
      if (cnt&1) {
        chmin(minodd, cnt);
      }
      cnt = 0;
    }
  }

  cnt = INT_MAX;
  if (minfirst%2 == 0) {
    chmin(cnt, minfirst+1);
  }
  chmin(cnt, minodd);
  int p = (cnt-1)/2;
  //debugln(p);
  n = n/2;
  
  vector<ll> dp(n+1);
  vector<ll> rdp(n+1);
  dp[1] = 1; rdp[1] = 1;
  dp[2] = 1; rdp[2] = 2;
  for(int i=3; i<=n; i++) {
    dp[i] = rdp[i-1] - rdp[max(0, i-p-2)] + mod;
    dp[i] %= mod;
    rdp[i] = rdp[i-1] + dp[i];
    rdp[i] %= mod;
    //debug(i); debugln(dp[i]);
  }

  ll ans = 0;
  for(ll L=0; L<=p && L<n; L++) {
    //debug(L); debugln(dp[max(0LL, n-L)]);
    ans += dp[max(0LL, n-L)]*(L+1)*2;
    ans %= mod;
  }
  cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


void Dijkstra(int s, const vector<vector<P>> &g, vi &dis) {
  priority_queue<P, vector<P>, greater<P>> que; // pair = (cost, v);
  dis[s] = 0;
  que.emplace(0,s);
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int now = p.second;
    if(dis[now] < p.first) continue;
    for(P np : g[now]) {
      int next = np.second;
      if(dis[next] > dis[now] + np.first) {
        dis[next] = dis[now] + np.first;
        que.emplace(dis[next], next);
      }
    }
  }
}


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

  int n, m, r;
  cin >> n >> m >> r;
  vi city(r);
  rep(i,r) {
    cin >> city[i];
    city[i]--;
  }
  vector<vector<P>> g(n); // pair = (cost, to);
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    g[a].emplace_back(c,b);
    g[b].emplace_back(c,a);
  }

  vii dist(n, vi(n,inf));
  rep(i,r) {
    int s = city[i];
    dist[s][s] = 0;
    Dijkstra(s, g, dist[s]);
  }
  sort(all(city));
  int ans = inf;
  do {
    int tmp = 0;
    REP(i,r) {
      tmp += dist[city[i]][city[i-1]];
    } 
    ans = min(ans, tmp);
  } while(next_permutation(all(city)));

  cout << ans << endl;
}

Measured memory_bytes: 896