akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int MOD=1000000007;

ll modpow(ll x, ll n, ll mod) {
  if (n==0) return 1;
  ll res=modpow(x*x%mod, n/2, mod);
  if (n & 1) res=res*x%mod;
  return res;
}

int main() {
  int n,k; cin>>n>>k;
  vector<ll> dp(k+1);
  ll res=0;
  for (int i=k; i>=1; i--) {
    dp[i]=modpow(k/i, n, MOD);
    for (int j=i*2; j<=k; j+=i) dp[i]-=dp[j];
    dp[i]=(dp[i]%MOD+MOD)%MOD;
    res+=(i*dp[i])%MOD;
    res%=MOD;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 4048
#include<stdio.h>
int linearSearch();
int n,S[10000],key;

int main(){
  int i,q,T[10000],C=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    key=T[i];
    if(linearSearch()==-1){
      continue;
    }
    else{
      C++;
    }
  }

  printf("%d\n",C);
}

  int linearSearch(){
    int i=0;
    for(i=0;i<n;i++){
      if(S[i]==key)
	return i;      
    }
    return -1;
  }



Measured memory_bytes: 2144
//Moh_K_Imar .......
//22/08/2020  ... 11,40
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b;
    cin>>a>>b;
    if(a>b)cout<<"safe"<<endl;
    else cout<<"unsafe"<<endl;

    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
      #define hell                         1000000007 
      #define M                            1000000007
      #define Maxi                      10000000000000000
      #define lcm(a,b)                     (a*b)/__gcd(a,b)
      #define ll                           long long
           
      #define vll                          vector<ll>
      #define vi                           vector<long long>
      #define pll                          vector< pair<ll,ll> >
      #define pb                           push_back
                  //#define mp                           make_pair
      #define all(v)                       v.begin(),v.end()
      #define lbnd                         lower_bound
      #define ubnd                         upper_bound
      #define bs                           binary_search
      #define F                            first
      #define S                            second
      #define rep(i,a,b)                   for(i=a;i<b;i++)
      #define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
      #define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
      #define ret(x)                       return cout<<x,0;
      #define dbg(x)                       cout << #x << " is " << x << endl;
      #define endl                           '\n'
           
           
                  // Debug //
           
      #define trace(x)                 cerr << #x << ": " << x << endl;
      #define trace1(x)                cerr << #x << ": " << x << endl;
      #define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
      #define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
      #define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
      #define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
      #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
           
           
      using namespace std;
      
     
      int main()
          {
           
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);cout.tie(NULL);
        
          
          ll i,j;
          ll n;
          cin>>n;
          for(i=1;i<=9;i++)
          {
            for(j=1;j<=9;j++)
            {
              if(i*j==n)
              {
                cout<<"Yes"<<endl;
                return 0;
              }
            }
          }
          cout<<"No"<<endl;

       return 0;
        }

Measured memory_bytes: 256
#include<stdio.h>

int m[10][10];

int dfs(int v, int N, int visited[10]) {
	int all_visited = 1,ret=0;
	int i;
	for (i = 0; i < N; i++) {
		if (visited[i] == 0)
			all_visited = 0;
	}
	if (all_visited)return 1;

	for (i = 0; i < N; i++) {
		if (m[v][i] == 0)continue;
		if (visited[i])continue;

		visited[i] = 1;
		ret += dfs(i, N, visited);
		visited[i] = 0;
	}
	return ret;
}

int main(void) {
	int N, M, a, b, visited[10] = {0};
	int i;
	scanf("%d %d",&N,&M);

	for (i = 0; i < M; i++) {
		scanf("%d %d",&a,&b);
		m[a-1][b-1] = 1;
		m[b-1][a-1] = 1;
	}

	visited[0] = 1;
	printf("%d\n",dfs(0, N, visited));
	
	return 0;
}

Measured memory_bytes: 128
from collections import Counter

class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size

    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)

    def same(self, x, y):
        return (self.find(x) == self.find(y))

    def size(self, x):
        return -self.data[self.find(x)]


MAX = 10 ** 5 + 10
uf = UnionFind(2 * MAX)

N, *XY = map(int, open(0).read().split())

for x, y in zip(*[iter(XY)] * 2):
    uf.union(x, y + MAX)

X = Counter(uf.find(i) for i in range(MAX))
Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
res = sum(X[i] * Y[i] for i in range(MAX * 2))

print(res - N)


Measured memory_bytes: 38580
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

S = str(input())
n = len(S)
K = I()

for i in range(1,n):
    if S[i]!=S[i-1]:
        break
    else:
        if i==n-1:
            print(K*n//2)
            exit()

if n==1:
    print(K//2)
    exit()

ren = 1
num = 0
for i in range(1,n):
    if S[i]==S[i-1]:
        ren += 1
    else:
        if i!=n-1:
            num += ren//2
            ren = 1

last = ren

if S[0]==S[-1]:
    num2 = 0
    for i in range(n):
        if S[i]==S[-1]:
            ren += 1
        else:
            now = i
            break
    num2 += ren//2
    ren = 1
    for i in range(now,n):
        if S[i]==S[i-1]:
            ren += 1
        else:
            if i!=n-1:
                num2 += ren//2
                ren = 1
    num3 = 0
    ren = 1
    for i in range(n-1-last+2,n):
        if S[i]==S[i-1]:
            ren += 1
        else:
            num3 += ren//2
            ren = 1
    num3 += ren//2
    print(num+num2*(K-1)+num3)
else:
    num += ren//2
    print(num*K)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, t[100], m, p[100], x[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      ans += (j == p[i] - 1 ? x[i] : t[j]);
    }
    cout << ans << '\n';
    ans = 0;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace WA055C
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').ToArray();

            var A = int.Parse(line[0]); var B = int.Parse(line[1]); var C = int.Parse(line[2]);
            var X = int.Parse(line[3]); var Y = int.Parse(line[4]);

            int minCost = 1000000000; int maxP = Math.Max(X, Y) * 2;

            for(var i = 0; i < maxP; i++)
            {
                int total = 0;

                total += i * 2 * C;

                int exA = X - i; int exB = Y - i;

                if(exA > 0)
                {
                    total += exA * A;
                }

                if(exB > 0)
                {
                    total += exB * B;
                }

                if(total < minCost)
                {
                    minCost = total;
                }
            }

            Console.WriteLine(minCost);
        }
    }
}


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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int main(){
	int a, b;
	cin >> a >> b;
	if(a <= b){
		cout << "un";
	}
	cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,c,sum[200010] = {},ma = 0;
	vector<P> vec[30];
	cin >> n >> c;
	for(int i = 0;i < n;i++){
		int s,t,cc;
		cin >> s >> t >> cc; cc--;
		vec[cc].push_back(P(s,t));
	}
	for(int i = 0;i < c;i++){
		if(vec[i].size() == 0) continue;
		sort(all(vec[i]));
		int l = vec[i][0].first,r = vec[i][0].second;
		for(int j = 1;j < vec[i].size();j++){
			if(vec[i][j].first == r) r = vec[i][j].second;
			else{
				sum[l * 2 - 1]++;
				sum[r * 2 + 1]--;
				l = vec[i][j].first;
				r = vec[i][j].second;
			}
		}
		sum[l * 2 - 1]++;
		sum[r * 2 + 1]--;
	}
	for(int i = 1;i <= 200005;i++) sum[i] += sum[i - 1];
	for(int i = 0;i <= 200005;i++){
		ma = max(ma,sum[i]);
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std ;
int main( void )
{
	short holy ;
	short jap ,math ;
	short japrite ,mathrite ;
	short amari ;
	cin >> holy ;
	cin >> jap ;
	cin >> math ;
	cin >> japrite ;
	cin >>mathrite ;
	amari = jap % japrite > 0 ? 1 : 0 ;
	jap = ( jap / japrite ) + amari ;
	amari = math % mathrite > 0 ? 1 : 0 ;
	math = ( math / mathrite ) + amari ;
	holy -= jap > math ? jap : math ;
	cout << holy << endl ;
	return 0 ;
}

Measured memory_bytes: 3076
#include <iostream>

using namespace std;
using ll = long long;

int main(int argc, char *argv[])
{
  string s;
  ll k;
  cin >> s >> k;

  char ans = '1';
  for (int i=0; i<k; i++) {
    if (s[i]!='1') {
      ans = s[i];
      break;
    }
  }

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

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        if (n == 1) { Console.WriteLine(1); goto end; }
        var w = getNum(n);
        var te = w * (w + 1) / 2;
        if (te == n) write(w);
        else
        {
            var ng = (w + 1) * (w + 2) / 2 - n;
            write2(w + 1, ng);
        }
        end:;
    }
    public static void write2 (long n , long ng )
    {
        for (int i = 1; i <= n; i++)
            if (i != ng) Console.WriteLine(i);
    }
    public static void write(long n)
    {
        for (int i = 1; i <= n; i++)
            Console.WriteLine(i);
    }
    public static long getNum(long n)
    {
        var ok = 1L; var ng = n;
        while (ng - ok > 1)
        {
            var mid = (ng + ok) / 2;
            if (check(mid, n)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
    public static bool check(long n, long t)
    {
        var w = n * (n + 1) / 2L;
        return w <= t;
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B; cin >> A >> B;
    if(A==1) A+=20;
    if(B==1) B+=20;
    if(A>B){
        cout << "Alice" << endl;
    }else if(A==B){
        cout << "Draw" << endl;
    }else{
        cout << "Bob" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
n=int(input())
a,b,c=input(),input(),input()
ct=0
for i in range(n):
  if a[i]==b[i]==c[i]:ct+=0
  elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i]:ct+=1
  else:ct+=2
print(ct)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>
#include <functional>

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

int main() {
	int n, m, ans=0;
	cin >> n >> m;
	vector<int> a(m),b(m),h(n);
	vector<vector<int>> t(n);
	rep(i, n) {
		cin >> h[i];
	}
	rep(i, m) {
		cin >> a[i] >> b[i];
		t[a[i] - 1].push_back(b[i]);
		t[b[i] - 1].push_back(a[i]);
	}
	rep(i, n) {
		if (t[i].size() == 0)
			ans++;
		else {
			int f = 0;
			rep(j, t[i].size()) {
				if (h[i] <= h[t[i][j] - 1])
					f = 1;
			}
			if (f == 0)
				ans++;
		}
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 9600
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

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

    int l[N];
    REP(i, N)
    {
        cin >> l[i];
    }
    sort(l, l+N);
    
    int sum = 0;
    for (int i = 0; i < K; i++)
    {
        sum += l[N-1-i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))


INF = 2147483647


import sys
stdin = sys.stdin

T =        int( stdin.readline().strip() )

ct = 1
ca = 1
for icase in range(1, T+1):
    t, a = map(int, stdin.readline().strip().split())
    n = max((ct + t - 1) // t,
            (ca + a - 1) // a)
    ct = n*t
    ca = n*a

print ct + ca




Measured memory_bytes: 2696
import java.util.Deque;
import java.util.ArrayDeque;
import java.io.BufferedReader;
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class Main {
  public static void main(String[] args) throws NumberFormatException, IOException {
	//long start = System.nanoTime();

	//System.setIn(new FileInputStream("./ALDS1_3_C-in10.txt"));
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	final int n = Integer.parseInt(br.readLine());
	Deque<Integer> d = new ArrayDeque<Integer>();
	
	String[] com;
	for(int i = 0; i < n; ++i) {
		com = br.readLine().split(" ");
		switch(com[0]) {
			case "insert":
				d.addFirst(Integer.parseInt(com[1]));
				break;
			case "delete":
				d.remove(Integer.parseInt(com[1]));
				break;
			case "deleteLast":
				d.removeLast();
				break;
			case "deleteFirst":
				d.remove();
				break;
		}
	}
	
	PrintWriter out = new PrintWriter(System.out);
	if(d.size() > 0) {
		out.print(d.pop());
	}
	for(int i : d) {
		out.print(" " + i);
	}
	out.println();
	out.flush();
	
	//System.out.println("Time:" + (System.nanoTime() - start) / 1000000f + " ms");
  }
}

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

using namespace std;

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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int N;
int a[112345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", a + i);
	
	vector<int> cx;
	REP(i, N) cx.push_back(a[i]);
	sort(ALL(cx));
	REP(i, N) a[i] = lower_bound(ALL(cx), a[i]) - cx.begin();
	
	vector<int> v[2];
	REP(i, N) {
		if (i & 1) v[1].push_back(a[i]);
		else v[0].push_back(a[i]);
	}
	
	int even = 0, odd = 0;
	REP(i, v[0].size()) if (v[0][i] & 1) even++;
	REP(i, v[1].size()) if (v[1][i] & 1 == 0) odd++;
	
	cout << abs(even - odd) << endl;
	
	return 0;
}


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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,b,c,d;

main() {
    cin >> a >> b >> c >> d;
    ct(max((long long)0,min(b,d)-max(a,c)))
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
const int M=1e5+10;
struct city{
    int p,y,id;
    bool operator <(city tmp){
        return y<tmp.y;
    }
}a[M];
int cnt[M],n,m;
ll ans[M];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++) scanf("%d%d",&a[i].p,&a[i].y),a[i].id=i;
    sort(a,a+m);
    for(int i=0;i<m;i++)
    {
        cnt[a[i].p]++;
        ans[a[i].id]=((a[i].p*(1000000ll))+cnt[a[i].p]);
    }
    for(int i=0;i<m;i++) printf("%.12lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 3840
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int H, W;
string[] A;

void main() {
  try {
    for (; ; ) {
      H = readInt();
      W = readInt();
      A = new string[H];
      foreach (x; 0 .. H) {
        A[x] = readToken();
      }
      
      auto q = new int[2 * H * W];
      int qHead, qTail;
      auto dist = new int[][](H, W);
      foreach (x; 0 .. H) foreach (y; 0 .. W) {
        if (A[x][y] == '#') {
          dist[x][y] = 0;
          q[qTail++] = x;
          q[qTail++] = y;
        } else {
          dist[x][y] = H * W;
        }
      }
      for (; qHead != qTail; ) {
        const x = q[qHead++];
        const y = q[qHead++];
        void update(int xx, int yy) {
          if (chmin(dist[xx][yy], dist[x][y] + 1)) {
            q[qTail++] = xx;
            q[qTail++] = yy;
          }
        }
        if (x + 1 < H) {
          update(x + 1, y);
        }
        if (y + 1 < W) {
          update(x, y + 1);
        }
        if (x - 1 >= 0) {
          update(x - 1, y);
        }
        if (y - 1 >= 0) {
          update(x, y - 1);
        }
      }
      
      int ans;
      foreach (x; 0 .. H) foreach (y; 0 .. W) {
        chmax(ans, dist[x][y]);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 15100
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

int main()
{
	int dp[3][1000000] = {},N;
	cin >> N;
	vector<int>a(N);
	vector<int>b(N);
	vector<int>c(N);
	for (int i = 0; i < N; i++)cin >> a[i] >> b[i] >> c[i];
	for (int i = 1; i <= N; i++)
	{
		dp[0][i] = max(dp[1][i - 1] + a[i - 1], dp[2][i - 1] + a[i - 1]);
		dp[1][i] = max(dp[0][i - 1] + b[i - 1], dp[2][i - 1] + b[i - 1]);
		dp[2][i] = max(dp[1][i - 1] + c[i - 1], dp[0][i - 1] + c[i - 1]);
	}
	cout << max(dp[0][N], max(dp[1][N], dp[2][N]));
}


Measured memory_bytes: 13184
#include <stdio.h>

#define MAXN 50
int Tako[MAXN];

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

	for (int n = 0; n < N; n++)
		scanf("%d", &Tako[n]);

	int Result = 0;
	for (int n = 0; n < N; n++)
		for (int j = n + 1; j < N; j++)
			Result += Tako[n] * Tako[j];
	
	printf("%d", Result);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int a;
  std::cin >> a;
  string s;
  std::cin >> s;
  if(a>=3200) std::cout << s << '\n';
  else std::cout << "red" << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 57;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;

lli dp[N];

void solve()
{
    lli n, m;
    cin>>n>>m;
    lli a[m + 1], b[m + 1], c[n + 1][m + 1];
    for(int i = 0; i < N; i ++)
        dp[i] = inf;
    dp[0] = 0;
    for(int i = 0; i < m; i ++)
    {
        lli a, b;
        cin>>a>>b;
        lli mask = 0;
        for(int j = 0; j < b; j ++)
        {
            lli x;
            cin>>x;
            x --;
            mask |= (1 << x);
        }
        for(int j = 0; j <= (1 << n); j ++)
        {
            dp[j | mask] = min(dp[j | mask], dp[j] + a);
        }
    }
    if(dp[(1 << n) - 1] == inf)
        cout<<-1;
    else
        cout<<dp[(1 << n) - 1];
    return ;
}
/*
7
6 7 4 1 2 11 6
5
1 2 10 4 5
*/

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

    lli t;
    t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>

int main()
{
  int i, j, H, W;

  while(1){
    scanf("%d%d", &H, &W);
    if(H == 0 && W == 0) break;

    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++){
        if((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0)) printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
using System;

public class Test
{
	public static void Main()
	{
		int S = 0, T = 0;
		var X = Console.ReadLine();
		for (int i = 0; i < X.Length; i++)
		{
			switch (X[i])
			{
				case 'S':
					++S;
					break;
				case 'T':
					if (S > 0)
					{
						--S;
					}
					else
					{
						++T;
					}
					break;
			}
		}
		Console.WriteLine(S + T);
	}
}

Measured memory_bytes: 3416
/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was

Only through dedication will I destroy all preconception

No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past

Only through dedication will I destroy all preconception

Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration

Join me,
Walk with me
Shatter the bonds that tie us
To what we strive to never be

Join me,
Walk with me
*/
#include<bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const ll maxn=1000001,mod=1e9+7;


int main(){

ll a,b,c;
ll ans=INT_MAX;
cin>>a>>b>>c;
vi v;
v.pb(a);v.pb(b);v.pb(c);
do{
   ans=min(ans,abs(v[0]-v[1])+abs(v[1]-v[2]));
}
while(next_permutation(all(v)));

cout<<ans;
//ll ans=min(abs(a-b)+abs(b-c,min(abs(b-c)+a,abs(a-c)+b));
//cout<<ans;
return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n;
	int a;
	int sum;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		sum = 0;
		for (int i = 0; i < n/4; i++) {
			cin >> a;
			sum += a;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

ll n;

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

    ll dp[n+1][2];
    dp[0][0]=0;
    dp[0][1]=-pow(10,15);

    for(int i=1;i < n+1;i++)
    {
        dp[i][0]=max(dp[i-1][0]+v.at(i-1),dp[i-1][1]-v.at(i-1));
        dp[i][1]=max(dp[i-1][0]-v.at(i-1),dp[i-1][1]+v.at(i-1));
    }

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


Measured memory_bytes: 2560
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int n;
    cin >> n;
    int room[4][3][10] = {0};
    REP(i, n) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        room[b-1][f-1][r-1] += v;
    }
    REP(i, 4){
        REP(j, 3){
            REP(k, 10)
                cout << " " << room[i][j][k];
            cout << endl;
        }
        if (i == 3)
            break;
        cout << "####################" << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  long ans = S.at(0) - '0' - 1, sub = 0; 
  ans += 9 * (S.size() - 1);
  for(char a: S)sub += a - '0';
  cout << max(sub, ans) << endl;
}


Measured memory_bytes: 256
inf = float('inf')

N,W = map(int,input().split())
w, v = [], []
for _ in range(N):
    wi, vi = map(int,input().split())
    w.append(wi)
    v.append(vi)

dp = [[-inf]*(W+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(1,N+1):
    for j in range(W+1):
        if j - w[i-1] >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1])
        else:
            dp[i][j] = dp[i-1][j]

ans = max(dp[N])
print(ans)

Measured memory_bytes: 311668
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int cnt=0,c=0,mi=10000;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<s.size();j++){
      if(s[i]==s[j]){
        c=max(c,cnt);
        cnt=0;
      }else{
        cnt++;
      }
    }
    c=max(c,cnt);
    cnt=0;
    mi=min(c,mi);
    c=0;
  }
  cout<<mi<<endl;
}


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


int main(){
    int64_t x, ans = 0, a = 100;
    cin >> x;

    while(1){
        ans++;
        a = a + a / 100; 
        if(x <= a)break;
    }

    cout <<  ans  << endl;
}

Measured memory_bytes: 3636
a, b, c = map(int,input().split())

xs = [list(map(int, input().split())) for i in range(a)]
ys = [list(map(int, input().split())) for i in range(b)]
ss = []
for i in range(a):
    rs = []
    for k in range(c):
        ppp=0
        for j in range(b):
            ppp+=xs[i][j] * ys[j][k]
        rs.append(ppp)
    ss.append(rs)

for i in ss:
    print(" ".join(map(str,i)))


Measured memory_bytes: 6912
import java.util.Comparator

fun main(args: Array<String>) {
    val N = nextInt()
    val F = Array(N) { listOfInt().map { it == 1 }.toBooleanArray() }
    val P = Array(N) { listOfInt().toIntArray() }
    var ans = Int.MIN_VALUE
    for (b in 1 until (1 shl 10)) {
        var cc = 0
        for (n in 0 until N) {
            var c = 0
            for (m in 0 until 10)
                if (((b shr m) and 1) == 1 && F[n][m]) c += 1
            cc += P[n][c]
//if (c > 0) System.err.println("$b $c")
        }
        if (ans < cc) ans = cc
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 41144
int_n = int(input())
str_s = input()

li_west = [0] * int_n
for i in range(int_n - 1):
    if str_s[i] == 'W':
        li_west[i + 1] = li_west[i] + 1
    else:
        li_west[i + 1] = li_west[i]
li_east = [0] * int_n

for i in range(int_n - 1, 0, -1):
    if str_s[i] == 'E':
        li_east[i - 1] = li_east[i] + 1
    else:
        li_east[i - 1] = li_east[i]

minimum = 999999
for i in range(int_n):
    int_w = li_west[i] + li_east[i]
    minimum = min(minimum, int_w)

print(minimum)

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

int main() {
    int n, d, ans = 0;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    rep(i, n) rep(j, d) cin >> x.at(i).at(j);
    rep(i, n - 1) {
        for(int j = i + 1; j < n; j++) {
            int k = 0, temp = 0;
            rep(k, d) temp += pow(x.at(i).at(k) - x.at(j).at(k), 2);
            while(temp >= k * k) {
                if(temp == k * k) ans++;
                k++;
            }
        }
    }
    cout << ans << endl;
}

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

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

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') {
			length++;
		}
		else {
			if (length > ans) {
				ans = length;
			}
			length = 0;
		}
	}

	if (length > ans) {
		ans = length;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

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

int main(void) {
	int n, a, b, sum = 0;
	scanf("%d %d %d", &n, &a, &b);
	for (int i = 1; i <= n; i++) {
		int _sum = sum_digits(i);
		if ((a <= _sum) && (_sum <= b)) {
			sum += i;
		}
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<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;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

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

int main() {
    long double a;
    long double b;
    cin >> a >> b;
    unsigned long long c = a*b;
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3740
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      _n: usize,
      c: Bytes
   }
   let r: usize = c.iter().map(|&b| if b == b'R' { 1 } else { 0 }).sum();
   let ans: usize = (0..r).map(|i| if c[i] == b'W' { 1 } else { 0 }).sum();

   println!("{}", ans);
}


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


def main():
    n = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for i in range(n-2):
        for j in range(i, n-1):
            for k in range(j, n):
                if L[k] < L[j] + L[i] and len({L[i], L[j], L[k]}) == 3:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
#include <stdio.h>

int main(){

	int H[100], W[100];
	int i, j, k,p;
	for (k = 0;; k++){
		scanf("%d %d", &H[k], &W[k]);
		if (H[k] == 0 && W[k] == 0)
			break;
	}

	for (p = 0; p < k; p++){
		for (i = 0; i < H[p]; i++){
			for (j = 0; j < W[p]; j++){
				printf("#");
			}
			printf("\n");
		}
		
			printf("\n");
		
	}
}

Measured memory_bytes: 1000
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;

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

    int n, k, a[112345], b[112345];

    cin >> n >> k;
    REP(i, n)
    cin >> a[i] >> b[i];

    ll res = 0;
    for (int i = -1; i <= 30; i++)
    {
        if (i > -1 && !(k & (1 << i)))
            continue;

        ll tmp = 0;

        REP(j, n)
        {
            if (i == -1 || !(a[j] & (1 << i)))
            {
                bool check = true;
                for (int l = i + 1; l <= 30; l++)
                {
                    if (!((k & (1 << l)) || !(a[j] & (1 << l))))
                        check = false;
                }

                if (check)
                    tmp += b[j];
            }
        }
        res = max(res, tmp);
    }

    cout << res << endl;

    return 0;
}

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

int main(void){
    int n, m;
    cin >> n >> m;

    ll k;
    cin >> k;

    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    vector<ll> b(m);
    rep(i,m) cin >> b[i];

    //cout << n << " " << m << " " << k << endl;
    //rep(i,n) cout << a[i] << " ";
    //cout << endl;
    //rep(i,m) cout << b[i] << " ";
    //cout << endl;

    vector<ll> sum_a;
    sum_a.push_back(0);
    for (int x : a) sum_a.push_back(sum_a.back()+x);

    vector<ll> sum_b;
    sum_b.push_back(0);
    for (int x : b) sum_b.push_back(sum_b.back()+x);

    int ans = 0;
    {
        int j = m;
        for (int i = 0; i <= n; i++) {
            if (sum_a[i] > k) break;
            while (sum_a[i]+sum_b[j] > k) j--;
            ans = max(ans, i+j);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11104
N, Q = map(int, input().split())
S = input()
ls, rs = [], []
for _ in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)

count = [0] * (N+1)
for i in range(2, N+1):
    if S[i-2:i] == "AC":
        count[i] = count[i-1] + 1
    else:
        count[i] = count[i-1]

#print(count)
        
for i in range(Q):
    l = ls[i]
    r = rs[i]
    print(count[r] - count[l])


Measured memory_bytes: 14200
package main

import "fmt"

func fill(a []int, val int) {
	for i := 0; i < len(a); i++ {
		a[i] = val
	}
	return
}

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	n := len(s)
	ss, tt := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		ss[i], tt[i] = int(s[i])-'a', int(t[i])-'a'
	}

	check := func(p []int, q []int) bool {
		a := make([]int, 26)
		fill(a, -1)
		for i := range p {
			if a[p[i]] < 0 {
				a[p[i]] = q[i]
			} else {
				if a[p[i]] != q[i] {
					return false
				}
			}
		}
		return true
	}

	ok := true
	if !check(ss, tt) {
		ok = false
	}
	if !check(tt, ss) {
		ok = false
	}

	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5376
program main; 
var a,b,c,d,e : integer;
begin
    readln(a,b,c,d,e);
    if a = 0 then
        writeln('1');
    if b = 0 then
        writeln('2');
    if c = 0 then
        writeln('3');
    if d = 0 then
        writeln('4');
    if e = 0 then
        writeln('5');
end.

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

int main() {
  int H, W;
  scanf("%d%d", &H, &W);

  vector<vector<char>> grid(H + 2, vector<char>(W + 2, '0'));
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      char s;
      cin >> s;
      grid.at(i).at(j) = s;
    }
  }

  int count = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (grid.at(i).at(j) == '#') {
        if (grid.at(i).at(j - 1) == '#') count++;
        if (grid.at(i).at(j + 1) == '#') count++;
        if (grid.at(i - 1).at(j) == '#') count++;
        if (grid.at(i + 1).at(j) == '#') count++;

        if (count == 0) {
          printf("No");
          return 0;
        } else {
          count = 0;
        }
      }
    }
  }

  printf("Yes");
  return 0;
}

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

int main()
{
	int a, b, c, i, j;
	cin >>a>>b>>c;
	j=0;
	for(i==0;i<=b-a;i++)
	{
		if(c%(i+a)==0)
		{
			j+=1;
		}
		else{}
	}
	cout <<j<<"\n";
	return 0;
}

Measured memory_bytes: 1164
<?php

# スペース区切りの整数の入力
fscanf(STDIN, "%d %d", $a, $b);

$str = sprintf("%s%s",$a,$b);

$sqrt = sqrt($str);

if( $sqrt == intval($sqrt) ){
    echo 'Yes'."\n";
}else{
    echo 'No'."\n";
}


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

//#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main(){
    int P,Q,R;
    int t;
    cin>> P >>Q >> R;
    t=min(Q,R);
    t=min(P+t,Q+R);
    cout << t <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int x[10001];
    int num;
    int m;
    for(int i=0;i<=10000;i++){
        scanf("%d",&num);
        x[i]=num;
        m=i;
        if(num==0){
            break;
        }
    }
    for(int k=1;k<=m;k++){
        printf("Case %d: %d\n",k,x[k-1]);
    }
    return 0;
}


Measured memory_bytes: 2100
import math
from functools import reduce
import itertools

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

sum = 0
Y =  int(input())

for v in itertools.combinations_with_replacement(range(1,Y+1), 3):
    if v[0] ==v[1] and v[1] == v[2]:
        sum += (gcd(v[0],v[1],v[2]))
    elif v[0] == v[1] or v[1] == v[2] or v[0] == v[2]:
        sum += (gcd(v[0],v[1],v[2])*3)
    elif v[0] != v[1] and v[1] != v[2]:
        #print("2")
        sum += (gcd(v[0],v[1],v[2])*6)
    else:
        print("nn")
           #print(gcd(i,j,k))
    #print("---------------------")

 

print(sum)

Measured memory_bytes: 9644
#include <stdio.h>

int main(void){

int A,B;
scanf("%d%d",&A,&B);
int C = A+B;

if(C%2 == 0){
printf("%d\n", C/2);
}

if(C%2 == 1){
printf("%s\n", "IMPOSSIBLE");
}



return 0;
}

Measured memory_bytes: 128
n,L=map(int,input().split())
taste = list([L+i-1 for i in range(1,n+1)])
taste_before = sum(taste)
l=min(taste)
r=max(taste)
if r<=0:
    taste_after = taste_before - r
elif l<0<r:
    taste_after = taste_before
else:
    taste_after = taste_before - l
print(int(taste_after))

Measured memory_bytes: 3064
def solve():
    S = input()

    end = len(S) - 1
    while end >= 2:
        if isEvenStr(S[:end]):
            print(end)
            break
        end -= 1

def isEvenStr(s):
    if len(s) % 2 != 0:
        return False
    
    if s[:len(s)//2] == s[len(s)//2:]:
        return True
    else:
        return False

if __name__ == '__main__':
    solve()

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

using namespace std;

int main(){
	int N, M;
	while(cin >> N >> M, N){
		vector< pair<int, int> > vp(N);
		int res = 0;
		for(int i=0;i<N;i++){
			cin >> vp[i].second >> vp[i].first;
			res += vp[i].first * vp[i].second;
		}
		sort(vp.rbegin(), vp.rend());
		for(int i=0;i<N;i++){
			int dec = min(M, vp[i].second);
			res -= dec * vp[i].first;
			M -= dec;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1276
n = int(input())
a_list = [int(input()) - 1 for _ in range(n)]
s = set()
i = 0
ans = -1
while i not in s:
    if i == 1:
        ans = len(s)
        break
    s.add(i)
    i = a_list[i]
print(ans)

Measured memory_bytes: 18948
s = input()
len = len(s)
min1,min2 = 0,0
moji1 = "10" * (len//2 +1)
moji2 = "01" * (len//2 +1)
for i in range(len) :
    if s[i] != moji1[i] :
        min1 += 1
    if s[i] != moji2[i] :
        min2 += 1
print(min(min1,min2))


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main{
	static void judge(int[] dic1,int[] dic2){
		for(int i=0;i<6;i++){
			if(dic1[i]!=dic2[i]){
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int[] dic1=new int[6];
		int[] dic2=new int[6];
		
		for(int i=0;i<6;i++) dic1[i]=scan.nextInt();
		for(int i=0;i<6;i++) dic2[i]=scan.nextInt();
		
		int top=dic1[1];
		int left=dic1[5];
		int tmp;
		
		if(top==dic2[5]){
			tmp=dic2[1];
			dic2[1]=dic2[5];
			dic2[5]=dic2[4];
			dic2[4]=dic2[0];
			dic2[0]=tmp;
		}
		if(top==dic2[3]){
			tmp=dic2[1];
			dic2[1]=dic2[3];
			dic2[3]=dic2[4];
			dic2[4]=dic2[2];
			dic2[2]=tmp;
		}
		if(top==dic2[0]){
			tmp=dic2[1];
			dic2[1]=dic2[0];
			dic2[0]=dic2[4];
			dic2[4]=dic2[5];
			dic2[5]=tmp;
		}
		if(top==dic2[2]){
			tmp=dic2[1];
			dic2[1]=dic2[2];
			dic2[2]=dic2[4];
			dic2[4]=dic2[3];
			dic2[3]=tmp;
		}
		if(top==dic2[4]){
			tmp=dic2[1];
			dic2[1]=dic2[4];
			dic2[4]=tmp;
			tmp=dic2[3];
			dic2[3]=dic2[2];
			dic2[2]=tmp;
		}
		
		if(dic2[2]==left||dic2[5]==left||dic2[3]==left||dic2[0]==left){
			if(dic2[5]==left){
				judge(dic1,dic2);
			}else if(dic2[3]==left){
				tmp=dic2[3];
				dic2[3]=dic2[0];
				dic2[0]=dic2[2];
				dic2[2]=dic2[5];
				dic2[5]=tmp;
				judge(dic1,dic2);
			}else if(dic2[0]==left){
				tmp=dic2[0];
				dic2[0]=dic2[5];
				dic2[5]=tmp;
				tmp=dic2[3];
				dic2[3]=dic2[2];
				dic2[2]=tmp;
				judge(dic1,dic2);
			}else{
				tmp=dic2[2];
				dic2[2]=dic2[0];
				dic2[0]=dic2[3];
				dic2[3]=dic2[5];
				dic2[5]=tmp;
				judge(dic1,dic2);
			}
		}else{
			System.out.println("No");
		}
		
		scan.close();
	}
}

Measured memory_bytes: 17324
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  string s;
  cin>>s;
  int sum=0;
  for(int i=0;i<s.size();i++){
    sum+=s[i]-'0';
  }
  if(sum%9==0)
    cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;
}

Measured memory_bytes: 3660
from collections import defaultdict


# 頂点がn個, 辺がw個の場合
n, w = map(int, input().split())

INF = 1 << 60
graph = defaultdict(lambda: INF)

for _ in range(w):
    a, b, c = map(int, input().split())
    graph[(a, b)] = c

# -1でdpテーブルを初期化。bitで集合を管理するので1<<n（状態数） * n（curr）
dp = [[-1] * n for _ in range(1 << n)]


# 既に訪れた集合がs, curr=vの時に0に戻る最短経路を計算
def rec(s, v):
    # 既に計算されている場合はそのまま返す（メモ化再帰）
    if dp[s][v] >= 0:
        return dp[s][v]

    # 全ての頂点を訪問済みで、かつcurr=0の場合は0を返す
    if s == (1 << n) - 1 and v == 0:
        return 0

    # INFで初期化
    res = INF

    # sが現在の状態なので、1つずつ右シフトで読んでいく。未訪問（=0）の場合に処理
    # 最初は全て未訪問
    for u in range(n):
        if not (s >> u & 1):
            # 未訪問を1つずつ潰していくイメージ。uまで訪問していて、curr=uの場合を計算
            # 1回計算された結果はメモ化再帰で再利用
            res = min(res, rec(s | (1 << u), u) + graph[(v, u)])

    dp[s][v] = res
    return dp[s][v]


ans = rec(0, 0)

print(-1 if ans == INF else ans)


Measured memory_bytes: 15844
#include<stdio.h>
int main()
{
int n,i,ans,sa1,sa2;
scanf("%d",&n);  
int w[n],sum[n];
  
  scanf("%d",&w[i]);
  sum[0]=w[0];
  
  for(i=1;i<n;++i)
  {scanf("%d",&w[i]);
  sum[i]=sum[i-1]+w[i];
  }
  
  for(i=0;sum[i]<sum[n-1]/2;++i)
  {ans=i;}
  
  sa1=sum[n-1]-sum[ans]*2;
  sa2=2*sum[ans+1]-sum[n-1];
  
  if(sa1<sa2) printf("%d",sa1);
  else printf("%d",sa2);
  
return 0;
}

Measured memory_bytes: 1704