akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID (l+r)/2
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define UP 1
#define LEFT 2
#define DIAG 3

int main(){
	string a, b;
	cin>>a>>b;
	int n = a.size(), m=b.size();
	int dp[n+1][m+1] = {};
	dp[0][0] = a[0]==b[0];
	for(int i=1;i<n;i++){
		dp[i][0] = a[i]==b[0];
		dp[i][0] = max(dp[i][0], dp[i-1][0]);
	}
	for(int i=1;i<m;i++){
		dp[0][i] = b[i]==a[0];
		dp[0][i] = max(dp[0][i], dp[0][i-1]);
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if((i|j)==0) continue;
			if(a[i]==b[j]) dp[i][j] = dp[i-1][j-1] + 1;
			else{
				dp[i][j] = max(dp[i][j-1], dp[i][j]);
				dp[i][j] = max(dp[i-1][j], dp[i][j]);
			}
		}
	}
	int i=n-1, j=m-1;
	string s;
	while(i>=0 && j>=0){
		if(a[i]==b[j]) i--, j--, s = a[i+1] + s;
		else if(i>0 && dp[i][j]==dp[i-1][j]) i--;
		else j--;
	}
	cout<<s<<endl;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(i,n) for ( int i = 0; i < (n); ++i )
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long int;
const long long int INF = 1001001001001001LL;
const int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;


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

    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if( s==u ) a--;
    else b--;
    cout << a << ' ' << b << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

pair<int, int> dir[4] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };

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

	int H, W;
	cin >> H >> W;

	vector<string> map_info(H, "");

	for (int i = 0; i < H; i++)
	{
		cin >> map_info[i];
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (map_info[i][j] == '#')
			{
				bool no = true;
				for (int k = 0; k < 4; k++)
				{
					int nx = j + dir[k].first;
					int ny = i + dir[k].second;

					if (nx >= 0 && nx < W && ny >= 0 && ny < H)
					{
						if (map_info[ny][nx] == '#')
						{
							no = false;
						}
					}
				}

				if (no)
				{
					cout << "No";
					return 0;
				}
			}
		}
	}

	cout << "Yes";

	return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(pow(10, 6))
input = sys.stdin.readline

def dfs(i, d):
  visited[i] = True
  ans[i] = d + pp[i]
  for j in edges[i]:
    if not visited[j]:
      dfs(j, d + pp[i])

n, q = map(int, input().split())
ans = [0 for _ in range(n)]
visited = [False for _ in range(n)]
edges = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)
pp = [0 for _ in range(n)]
for _ in range(q):
  p, x = map(int, input().split())
  pp[p-1] += x
dfs(0, 0)
print(*ans)


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,data[ohara];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>s;
      if(s[0]=='0'||s[Size(s)-1]=='1')Cout(-1);
      else{
        rep(i,Size(s)){
          if(i>Size(s)-i-2)break;
          if(s[i]!=s[Size(s)-i-2]){
            Cout(-1);
            return 0;
          }
        }
        rep(i,Size(s)){
          if(s[i]=='1')data[cnt++]=i+1;
        }
        a=0;
        cmp=1;
        cmpp=2;
        pair<ll,ll> p[ohara];
        ll cntt=0;
      rrep(i,1,cnt){
         ans+=data[i]-data[i-1]-1;
       }
       pos=Size(s)-ans;
       while(1){
         p[cntt++]=make_pair(cmp,cmpp);
         cmp++;cmpp++;
         if(cmp==pos)break;
       }
       rrep(i,1,cnt){
         pos=data[i]-data[i-1];
         if(pos>=2){
           cmp=i+1;
           rep(j,pos-1){
             p[cntt++]=make_pair(cmp,cmpp);
             cmpp++;
           }
         }
       }
        rep(i,cntt)cout<<p[i].first<<" "<<p[i].second<<"\n";
      }
    
       
return 0;
}


Measured memory_bytes: 18000
N, M = map(int, input().split())

x = [0] * M
y = [0] * M
for i in range(M):
    x[i], y[i] = map(int, input().split())

if min(y) - max(x) + 1 > 0:
    print(min(y) - max(x) + 1 )
else:
    print(0)

Measured memory_bytes: 10868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)   (((a) > (b)) ? (a) : (b))       /* ２個の値の最大値 */
#define min(a, b)   (((a) < (b)) ? (a) : (b))       /* ２個の値の最小値 */
#define ENTER       printf("\n")                    /* 改行プリント */
int DBG = 1;                                        /* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
    int     p,a,b,c,i,j,k,n,m,x,y,ans = 0x70000000;

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

    m = x / 1000;
    if ( x % 1000 != 0) m++;
    n = x / 500;
    if (x % 500 != 0) n++;

    for(i=0;i<=m;i++) {
        for(j=0;j<=n;j++) {
            if ( i*1000 + j*500 >= x ) {
                ans = min(ans , i*a + b*j);
                break;
            }
        }
    }

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

    return 0;
}



Measured memory_bytes: 2140
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

int main() {
  int n, m, d; scanf("%d%d%d", &n, &m, &d);
  double ret;
  if (d == 0 || n < 1 + d + d) {
    ret = (m - 1) * 1.0 / n;
  } else {
    ret = (m - 1) * 2LL * (n - d) * 1.0 / n / n;
  }
  printf("%.10f\n", ret);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<deque>
#include<iomanip>
#include<ctime>
#include<bitset>
#include<map>
using namespace std;

int main()
{
	unsigned long long x;

	cin >> x;

	unsigned long long money = 100;

	int year = 0;

	while (money < x)
	{
		money += (unsigned long long)(money * 0.01);
		year++;
	}

	cout << year << endl;

	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

const int SZ=1005;
int a[SZ],b[SZ];
string name[SZ];

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

    int n,q;
    while(cin>>n>>q,n)
    {
        REP(i,n) cin>>name[i]>>a[i]>>b[i];
        while(q--){
            int year; cin>>year;
            bool ok=false;
            REP(i,n){
                if(b[i]-a[i]<year && year<=b[i]){
                    cout<<name[i]<<" "<<a[i]+year-b[i]<<endl;
                    ok=true; break;
                }
            }
            if(!ok) cout<<"Unknown"<<endl;
        }
    }
}



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

int main() {
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(0, (min(b, d) - max(a, c))) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define INFTY 1000000
#define NO 0
#define DISCOVERY 1
#define FINISHING 2
int n,ans[N][N];
void daikusutora() {
  int minv;
  int discover[N],check[N];
  for(int i=0;i<n;i++){
    discover[i]=INFTY;
    check[i]=NO;
  }
  discover[0]=0;
  check[0]=DISCOVERY;
  while(1){
    minv=INFTY;
    int u=-1;
    for(int i=0;i<n;i++){
      if(minv > discover[i] && check[i]!=FINISHING){
	u=i;
	minv=discover[i];
      }
    }
    if(u==-1)break;
    check[u]=FINISHING;
    for(int v=0;v<n;v++){
      if(check[v]!=FINISHING && ans[u][v]!=INFTY){
	if(discover[v]>discover[u]+ans[u][v]){
	  discover[v]=discover[u]+ans[u][v];
	  check[v]=DISCOVERY;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    printf("%d %d\n",i,(discover[i]==INFTY ? -1:discover[i]));
  }
}

int main() {
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)ans[i][j]=INFTY;
  }
  int k,c,u,v;
  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(int j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      ans[u][v]=c;
    }
  }
  daikusutora();
  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll n,l;cin>>n>>l;
	ll sum=0;
	ll a[n+1];
	for(ll i=1;i<=n;i++)
	{
		a[i]=abs(l+i-1);
		sum+=(l+i-1);
	}
	sort(a+1,a+n+1);
	if(sum>=0)cout<<sum-a[1];
	else cout<<sum+a[1];
}


Measured memory_bytes: 256
from functools import reduce

N = int(input())
input_list = sorted([int(input()) for i in range(N)])

# ユークリッドの互除法
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm(*input_list))

Measured memory_bytes: 3572
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BROTN solver = new BROTN();
        solver.solve(1, in, out);
        out.close();
    }

    static class BROTN {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            char[] arr = sc.next().toCharArray();
            for (int i = 0; i < arr.length; i++)
                arr[i] = (char) (((arr[i] + n - 'A') % 26) + 'A');
            for (char c : arr)
                pw.print(c);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}



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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define endl "\n"

ll h[100005];
ll ans[100005];

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

	ll N, K;
	cin >> N >> K;

	for(ll i=0; i<N; i++)
	{
		cin >> h[i];
	}	

	for(ll i=1; i<N; i++)
	{
		ans[i] = ans[i-1] + abs(h[i]-h[i-1]);
		for(ll j=i-2; j>=0 && j>=i-K; j--)
		{
			ans[i] = min(ans[i], ans[j]+abs(h[i]-h[j]));
		}
	}

	cout << ans[N-1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
#define ll long long

int main()
{
    int x;
    char t[200010];
    scanf("%d",&x);
    getchar();
    for(int i=1; i <= x; i++)
    {
        scanf("%c",&t[i]);
    }
    int sum = 0;
    int y=x;
    for(int i=1 ; i<=x; i++)
    {
        if(t[i]=='W')
        {
            for(y; y>=i; --y)
            {
                if(t[y]=='R')
                {
                    sum++;
                    y--;
                    break;
                }

            }
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 4020
N,M,C = map(int,input().split())
B = [int(i) for i in input().split()]
A = [list(map(int,input().split())) for i in range(N)]
count = 0
t = []
for i in range(N):
    for j in range(M):
        t.append(A[i][j]*B[j])
    if (sum(t)+C) > 0:
        count +=1
        t.clear()
    else:
        t.clear()
        
print(count)


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

int main() {
  int N;
  cin >> N;
  int MAX = 0;
  int k = 0;
  vector<int> vec(N);
  int kaburi = 0;
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  for (int p = 0; p < N; p++){
    MAX = 0;
    for (int i = 0; i < N; i++){
      if (MAX <= vec.at(i)){
        MAX = vec.at(i);
        k = i;
      }
    }
    vec.at(k) = -1;
    for (int i = 0; i < N; i++){
      if (MAX == vec.at(i)){
        MAX = vec.at(i);
        vec.at(i) = -1;
        kaburi++;
      }
    }    
  }
  cout << N - kaburi << endl;
}

Measured memory_bytes: 3608
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
import math
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  h, w = map(int, input().split())
  ans = 0
  if h==1 or w==1:
    ans = 1
  else:
    ans = (h*w+1)//2
  print(ans)
  

if __name__ == '__main__':
  main()

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1=sc.nextInt(),y1=sc.nextInt(),x2=sc.nextInt(),y2=sc.nextInt();
		int x = x2-x1;
		int y = y2-y1;
		System.out.println((x2-y)+" "+(y2+x)+" "+(x1-y)+" "+(y1+x));
	}
}


Measured memory_bytes: 21844
from collections import deque
from sys import stdin

dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

N, M = [int(_) for _ in stdin.readline().rstrip().split()]
graph = []

def bfs(graph, N, M):
    for _ in range(N):
        n = list(stdin.readline().rstrip())
        graph.append(n)

    ans = 0
    que = deque()
    dist = [[-1 for i in range(M)] for j in range(N)]
    for i in range(N):
        for j in range(M):
            if graph[i][j] == '#':
                que.append((i, j)) 
                dist[i][j] = 0

    while len(que):
        v = que.popleft()
        for d in range(4):
            nx = v[0] + dx[d]
            ny = v[1] + dy[d]
            if nx < 0 or nx >= N or ny < 0 or ny >= M:
                continue
            if dist[nx][ny] == -1:
                dist[nx][ny] = dist[v[0]][v[1]] + 1
                que.append((nx, ny))

    for i in range(N):
        for j in range(M):
            ans = max(ans, dist[i][j])

    return ans

ans = bfs(graph, N, M)
print(ans)

Measured memory_bytes: 122204
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1};
int dx[] = {1, -1, 0, 0};

int main() {
    int a, b;
    int deg[101] = {0};
    while (cin >> a >> b) {
        if (a == 0) {
            int flg = 0;
            if (deg[1] % 2 == 0 || deg[2] % 2 == 0) flg = 1;
            rrep(i, 3, 101) if (deg[i] % 2 != 0) flg = 1;
            if (flg == 0) cout << "OK" << endl;
            else cout << "NG" << endl;
            rep(i, 101) deg[i] = 0;
            continue;
        }
        deg[a]++; deg[b]++;
    }
}



Measured memory_bytes: 3088
#include <stdio.h>
#include <math.h>
#define N 10000
#define TRUE 1
#define FALSE -1

int isprime(int x){
  if(x==2) return TRUE;
  if(x<2 || x%2==0) return FALSE;
  int i=3;
  while(i<=(int)sqrt(x)){
    if(x%i==0) return FALSE;
    i=i+2;
  }
  return TRUE;
}

int main(){
  int A[N],n,i,j,count=0;
  scanf("%d",&n);
 for(i=0;i<n;i++)  scanf("%d",&A[i]);

 for(i=0;i<n;i++){
   if(isprime(A[i])==TRUE) count++;
 }

  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
 
int main() {  
  int n,d1,d2,cnt=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> d1 >> d2;
    if(d1==d2){
      cnt++;
      if(cnt==3){
        cout << "Yes";
        return 0;
      }
    }
    else{
      cnt=0;
    }
  }
  cout << "No";
}

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

bool f[10];

int n, k;

static bool bad(int x) {
	do {
		if (f[x % 10])
			return true;
		x/= 10;  }
	while (x > 0);
	return false; }

int main() {
#ifdef HOME
	freopen("arc58a.in", "r", stdin);
	freopen("arc58a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> k;
	for (int t, i = 0; i < k; ++i) {
		cin >> t;
		f[t] = true; }

	while (bad(n)) ++n;

	cout << n << endl;

	return 0; }


Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {
  loop()
  @tailrec def loop(): Unit = {
    val str: String = readLine.trim
    if (str.headOption.contains('-')) return
    if (str.contains('.')) {
      val Array(integer, underPoint) = str.split('.')
      if (integer.length > 3 || integer.toInt >= 256 || (str.toDouble * 16) - (str.toDouble * 16).toInt != 0) {
        println("NA")
      } else {
        val int = integer.toInt.toBinaryString
        val under = ((str.toDouble * 16).toInt % 16).toBinaryString
        println("0" * (8 - int.length) + int + "." + ("0" * (4 - under.length)) + under)
      }
    }else {
      if (str.toInt >= 256) println("NA")
      else {
        val int = str.toInt.toBinaryString
        println("0" * (8 - int.length) + int + ".0000")
      }
    }
    loop()
  }
  def power(base: Int, exp: Int): Int = {
    exp match {
      case 0 ⇒ 1
      case 1 ⇒ base
      case _ ⇒ power(base * base, exp / 2) * power(base, exp % 2)
    }
  }
}


Measured memory_bytes: 46176
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#define SIZE 500005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[SIZE];
int dp[SIZE];
int nxt[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",&str);
	for(int i=0;i<=n;i++) dp[i]=n;
	int all=0;
	for(int i=n-1;i>=0;i--)
	{
		if(str[i]=='1') all++;
		nxt[i]=n;
		if(str[i]=='0') nxt[i]=i;
		else if(i+1<n) nxt[i]=nxt[i+1];
	}
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='0') dp[i+1]=min(dp[i],dp[i+1]);
		else
		{
			dp[i+1]=min(dp[i+1],dp[i]+1);
			if(nxt[i]==i+1)
			{
				for(int j=i+2;j<n;j++)
				{
					if(str[j]=='0') break;
					dp[j+1]=min(dp[j+1],dp[i]+1);
				}
			}
			else
			{
				if(nxt[i]+1<n&&str[nxt[i]+1]=='1')
				{
					dp[nxt[i]+2]=min(dp[nxt[i]+2],dp[i]+1);
				}
			}
		}
	}
	printf("%d\n",all-dp[n]);
	return 0;
}


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


int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 == 1 && b % 2 == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int M, N;
int Dp[240][19];

const string Table[18] = { 
	""   , "Man", "Oku", "Cho", "Kei", "Gai",
	"Jo" , "Jou", "Ko",  "Kan", "Sei", "Sai",
	"Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts", 
};


int main() {
	
	while (cin >> M >> N, M) {
		memset(Dp, 0, sizeof(Dp));
		Dp[0][0] = 1;
		for (int i = 1; i <= N; i++) {
			for (int j = 0; j < 18; j++) {
				Dp[i][j] += Dp[i - 1][j] * M;
				Dp[i][j + 1] += Dp[i][j] / 10000;
				Dp[i][j] %= 10000;
			}
		}
		for (int i = 17; i >= 0; i--) {
			if (Dp[N][i] != 0) {
				cout << Dp[N][i] << Table[i];
			}
		}
		cout << endl;
	}
}



Measured memory_bytes: 3232
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  vector<vector<int>> as(H, vector<int>(W)), bs(H, vector<int>(W)), cs(H, vector<int>(W));
  F0R(r, H) {
    F0R(c, W) {
      cin >> as[r][c];
    }
  }
  int cmax = 0;
  F0R(r, H) {
    F0R(c, W) {
      cin >> bs[r][c];
      cs[r][c] = abs(as[r][c] - bs[r][c]);
      chmax(cmax, cs[r][c]);
    }
  }

  vector<vector<bitset<12801>>> ns(H, vector<bitset<12801>>(W, bitset<12801>(false)));
  ns[0][0][cs[0][0]] = true;

  FOR(i, 1, H + W + 1) {
    int r = i, c = 0;
    if (r > H - 1) {
      c += r - (H - 1);
      r = H - 1;
    }
    for (; r >= 0 && c < W; r--, c++) {
      //cout << r << ',' << c << newl;
      int n = cs[r][c];

      if (r > 0) {
        ns[r][c] |= ns[r - 1][c] << n;
        ns[r][c] |= ns[r - 1][c] >> n;
        F0R(j, n) {
          if (ns[r - 1][c].test(j)) {
            ns[r][c].set(n - j);
          }
        }
      }
      if (c > 0) {
        ns[r][c] |= ns[r][c - 1] << n;
        ns[r][c] |= ns[r][c - 1] >> n;
        F0R(j, n) {
          if (ns[r ][c - 1].test(j)) {
            ns[r][c].set(n - j);
          }
        }
      }
      /*
      F0R(j, 12801) {
        if (ns[r][c][j]) {
          cout << j << ' ';
        }
      }
      cout << newl;
      //*/
    }
  }

  F0R(i, 12801) {
    if (ns[H - 1][W - 1][i]) {
      cout << i;
      break;
    }
  }
}
#endif


Measured memory_bytes: 10496
h,w = map(int, input().split())
F = []
for _ in range(h):
    f = list(map(str,input()))
    F.append(f)
    
def bomb(field,i,j):
    cnt = 0
    for p in range(-1,2):
        for q in range(-1,2):
            if 0 <= i+p <= len(field)-1 and 0 <= j+q <= len(field[0])-1:
                if field[i+p][j+q] == "#":
                    cnt += 1
    return cnt
    cnt = 0

ans = [[0]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if F[i][j] != "#":
            ans[i][j] = str(bomb(F,i,j))
        else:
            ans[i][j] = "#"
for s in ans:
    print("".join(s))
        
        

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 200005

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main() {
  double a, b, x, ans;
  cin >> a >> b >>x;
  if(a*a*b*0.5<=x){
    double h=2*b-2*x/(a*a);
    ans=atan(h/a)*360/(2*M_PI);
  } else {
    double k=2*x/(a*b);
    ans=atan(b/k)*360/(2*M_PI);
  }
  cout << fixed;
  cout << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	char A;
	char B;
	char C;
	scanf("%c %c %c",&A,&B,&C);
	if(A==B&&B==C&&C==A)
	printf("No");
	else if(A==B || B==C || C==A)
	printf("Yes");
	return 0;
}

Measured memory_bytes: 1672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
int a, b, x;

bool ok(double th)
{
    if(x >= 0.5*a*a*b){
	    const double h = tan(PI*th/180)*a;
	    const double v = 0.5*a*a*h;
	    return v <= a*a*b-x;
    }else{
        const double v=2*x;
        const double h=v/(a*b);
        return th <=180*atan(b/h)/PI;
    }
}

void solve()
{
	double lo = 0.0, hi = 90.0;
	for(int i=0;i<100;++i){
		double mid = (lo+hi)/2;
		if(ok(mid)) lo=mid;
		else hi = mid;
	}
	printf("%.7lf\n", lo);
}

int main()
{
	cin >> a >> b >> x;
	solve();
	return 0;
}

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

 
int main() {
  int h1,h2,m1,m2,i,j,k,h,m,t,ans;
  cin >> h1>>m1>>h2>>m2>>k;
  h=h2-h1;
  if(h<0)
    h*=-1;
  m=m2-m1;
  t=h*60+m;
  cout << t-k << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

    long long ans = 0;
    sort(s.begin(), s.end());
    long long count = 1;
    vector<int> n;

    for (int i = 0; i < N - 1; i++){
        if (s.at(i) == s.at(i + 1)){
            count ++;
            if (i == N-2){
                n.push_back(count);
            }
        }
        else {
            n.push_back(count);
            count = 1;
        }
    }

    for (long long c: n){
        if (c != 1){
            ans += c*(c-1)/2;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 8448
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
int n,m,i,j,a[3005],f[3005],x,y;
vector<int> bi[3005];
char dfs(int x)
{
	if(f[x]!=-1) return f[x];
	f[x]=0;
	ff(bi[x],it){
		if(a[*it]<a[x]&&!dfs(*it)){
			return f[x]=1;
		}
	}
	return 0;
}
int main()
{
	memset(f,-1,sizeof(f));
	cin>>n;
	fz1(i,n)cin>>a[i];
	fz1(i,n-1){
		cin>>x>>y;
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	fz1(i,n){
		if(dfs(i)){
			cout<<i<<' ';
		}
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n)
    {
        cin >> a.at(i) >> b.at(i);
    }

    vector<vector<int>> ab(n, vector<int>(2));
    rep(i, n)
    {
        ab.at(i).at(0) = a.at(i);
        ab.at(i).at(1) = b.at(i);
    }

    sort(ab.begin(), ab.end(), [](const vector<int> &alpha, const vector<int> &beta) { return alpha[1] < beta[1]; });

    // cout << "-------------------" << endl;
    // rep(i, n)
    // {
    // cout << ab.at(i).at(0) << " " << ab.at(i).at(1) << endl;
    // }

    // cout << "-------------------" << endl;
    string answer = "Yes";
    int total_a = 0;
    rep(i, n)
    {
        total_a += ab.at(i).at(0);
        // cout << total_a << " " << ab.at(i).at(b) << endl;
        if (total_a > ab.at(i).at(1))
        {
            answer = "No";
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define pb push_back

int N, a, b;
vector<vector<int>> edge;
vector<P> edge_pair;
vector<int> degree;
map<P, int> color;
int max_degree = 0;  //最大次数

void dsf(int ver, int par, int c){
    int L = edge[ver].size(), d = 0;
    color[{par, ver}] = c;
    for(int i = 0; i < L; i++){
        if(i+1 == c) ++d;
        dsf(edge[ver][i], ver, i+1+d);
    }
}

int main(){
    cin >> N;
    edge.resize(N+1);
    degree.assign(N+1, 0);

    for(int i = 0; i < N-1; i++){
        cin >> a >> b;
        edge[a].pb(b);
        edge_pair.pb({a,b});
        ++degree[a]; ++degree[b];
        max_degree = max(max_degree, degree[a]);
    }

    cout << max_degree << endl;
    dsf(1, 0, 0);

    for(int i = 0; i < N-1; i++){
        P p = edge_pair[i];
        cout << color[p] << endl;
    }
    
    return 0;

}

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

int main() {
  string s;
  cin >> s;
  
  if(s=="RRR") cout << 3 << endl;
  else if(s=="SRR" || s=="RRS") cout << 2 << endl;
  else if(s=="SSS") cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

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

int X,Y,E,x,y;
bool D[110][110] = {};

int PY[110];
bool V[110];
bool match(int x) {
  if(x < 0) return true;
  if(V[x]) return false;
  V[x] = true;
  for(int y = 0; y < Y; ++y) {
    if(!D[x][y]) continue;
    if(match(PY[y])) {
      PY[y] = x;
      return true;
    }
  }
  return false;
}

int main() {
  cin >> X >> Y  >> E;
  for(int i = 0; i < E; ++i) {
    cin >> x >> y;
    D[x][y] = true;
  }
  fill(PY,PY+Y,-1);
  int count = 0;
  for(int x = 0; x < X; ++x) {
    fill(V,V+X,false);
    if(match(x)) ++count;
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  int H[N+1];
  rep(i,N) cin>>H[i];
  int x=0,ans=0;
  rep(i,N){
    if(H[i]>=x){
      ans++;
      x=H[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  string s; 
  cin >> s;
  int n = s.size();
  int N=0, W=0, S=0, E=0;
  if(n==1){
    cout << "No";
    return 0;
  }
  for(int i=0; i<n; ++i){
    if(s[i]=='N') N=1;
    if(s[i]=='W') W=1;
    if(s[i]=='S') S=1;
    if(s[i]=='E') E=1;
  }
  int res = N + W + S + E;
  if(N==1 && S==0) cout << "No";
  else if(N==0 && S==1) cout << "No";
  else if(W==1 && E==0) cout << "No";
  else if(W==0 && E==1) cout << "No";
  else cout << "Yes";
}

Measured memory_bytes: 3624
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
s = list(accumulate(a))
MOD = 10 ** 9 + 7

ans = 0
for i in range(n):
    ans += a[i] * (s[n - 1] - s[i])
    ans %= MOD

print(ans)

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

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int sum = 0,res = 1;
    rep(i,n){
        sum = sum + l[i];
        if(sum > x){
            cout << res << endl;
            return 0;
        }
        res++;
    }
  	cout << n+1 << endl;
}


Measured memory_bytes: 256
import math

N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

def lcm(x, y):
  return (x // math.gcd(x, y)) * y

LCM = A[0]
for i in range(N-1):
  LCM = lcm(LCM, A[i+1])

#LCM %= mod

ans = 0
for a in A:
  ans += LCM * pow(a, mod-2, mod) % mod
  ans %= mod

print(ans)

Measured memory_bytes: 74284
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long N, L, T;
  cin >> N >> L >> T;
  vector<long> xs(N, 0), ws(N, 0);
  for (long i = 0; i < N; ++i) {
    cin >> xs[i] >> ws[i];
  }

  vector<long> last_poses(N, 0);
  long counter = 0;
  for (long i = 0; i < N; ++i) {
    if (ws[i] == 1) {
      last_poses[i] = (xs[i] + T) % L;
      counter -= (xs[i] + T) / L;
    } else {
      last_poses[i] = ((xs[i] - T) % L + L) % L;
      counter += (T - (xs[i] + 1) + L) / L;
    }
  }

  sort(last_poses.begin(), last_poses.end());
  counter = (counter % N + N) % N;

  vector<long> res(N, 0);
  for (long i = 0; i < N; ++i) {
    res[(i + counter) % N] = last_poses[i];
  }

  for (auto &e : res) {
    cout << e << endl;
  }
  return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int s;
    cin>>s;
    int a[10010]={0};
    int i,j,k;
    for(i=1; i<100; i++)
    {
        for(j=1; j<100; j++)
        {
            for(k=1; k<100; k++)
            {
                 int n=i*i+j*j+k*k+i*j+i*k+j*k;
                 if(0<=n&&n<=s)
                  a[n]++;
            }
        }
    }
    for(i=1;i<=s;i++)
        cout<<a[i]<<endl;
    return 0;
}


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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n;
ll a[maxn];

//check T
void solve()
{
	cin >> n; rep(i, 0, n) cin >> a[i];
  bool flag = 1;
  rep(i, 0, n)if(a[i]%2 == 0) flag &= (a[i]%3 == 0) || (a[i]%5 == 0);
  cout << (flag ? "APPROVED" : "DENIED") << endl;
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<vector<ll>> mtx;

const ll MOD = 1000000007;

int N;
ll K;
mtx mat;

mtx mul(mtx& A, mtx& B) {
	mtx ret(N);
	for (int i = 0; i < N; i++)ret[i].resize(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				ret[i][j] += (A[i][k] * B[k][j]);
				ret[i][j] %= MOD;
			}
		}
	}
	return ret;
}

mtx mod_pow(mtx& M, ll A) {
	auto kakeru = M;
	vector<vector<ll>> ret(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++)ret[i].push_back(0);

		ret[i][i] = 1;
		
	}

	while (A > 0) {
		if (A & 1) {
			ret = mul(ret, kakeru);

		}
		kakeru = mul(kakeru, kakeru);
		A >>= 1;
	}
	return ret;
}

int main() {
	cin >> N >> K;
	mat.resize(N);
	for (int i = 0; i < N; i++) {
		mat[i].resize(N);
		for (int j = 0; j < N; j++) {
			bool f;
			cin >> f;
			mat[i][j] = f;
		}
	}
	//転置行列にする

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			swap(mat[i][j], mat[j][i]);
		}
	}
	
	mat = mod_pow(mat, K);
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans += mat[i][j];
			ans %= MOD;

		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

        int x = scanner.nextInt();
        int ab = scanner.nextInt() - scanner.nextInt();

        String result = "";

        if (ab >= 0) {
            result = "delicious";
        } else if (Math.abs(ab) <= x) {
            result = "safe";
        } else {
            result = "dangerous";
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 21972
#include<iostream>
using namespace std;
#include<vector>
#include<cmath>
#define int long long int
#define inf 2001
int memo[1001][1001];
int function(char mat[1001][1001],int i,int j,int n,int m,bool visited[1001][1001])
{
	if(i<0||i>=n||j<0||j>=m)
	    return inf;
	if(visited[i][j]==true)
	   return inf;
	if(mat[i][j]=='#')
	   return 0;
	else
	{
		visited[i][j]=true;
		int x=1+function(mat,i+1,j,n,m,visited);
		int y=1+function(mat,i-1,j,n,m,visited);
		int z=1+function(mat,i,j-1,n,m,visited);
		int t=1+function(mat,i,j+1,n,m,visited);
		memo[i][j]=min(memo[i][j],min(min(x,y),min(z,t)));
		return memo[i][j];
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
     int w=0;
     string str;
     cin>>str;
     int j;
     for(j=0;str[j]!='\0';j++)
     {
		 if(str[j]=='o')
		     w++;
	 }
	 w+=(15-str.size());
	 cout<<(w>=8?"YES":"NO")<<endl;
}


Measured memory_bytes: 256
n=int(input())
x=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x[i][0],x[i][1]=x[i][0]-x[i][1],x[i][0]+x[i][1]
x.sort(key=lambda x:x[1])
ans=0
t2=-2*10**9
for i in range(n):
    if t2<=x[i][0]:
        ans+=1
        t2=x[i][1]
print(ans)

Measured memory_bytes: 29096
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

void hora(int tc) {
	LL n, s;
	cin>>n>>s;
	LL res = -1;
	for(LL i = 2;i * i <= n;i++) {
		LL tmp = n;
		LL tot = 0;
		while(tmp) {
			tot += tmp % i;
			tmp /= i;
		}
		if(tot == s && res == -1) res = i;
	}
	for(LL i = 1;i * i <= n;i++) {
		LL targetb = s - i;
		if(targetb < 0) continue;
		if((n - targetb) % i == 0) {	
			LL p = (n - targetb) / i;
			if((res == -1 || res > p) && p > targetb && p > i) res = p;
		}
	}
	if(n == s && res == -1) res = n + 1;
	cout<<res<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 256
#[test]
fn test_solve() {
    assert_eq!(solve("5 7 9\n"), "win\n");
    assert_eq!(solve("13 7 2\n"), "bust\n");
}

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let a1: usize = sc.read();
    let a2: usize = sc.read();
    let a3: usize = sc.read();

    if a1 +a2+a3>=22 {
        "bust\n".to_string()
    } else {
        "win\n".to_string()
    }
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	VI a(3); REP(i,3) cin >> a[i];
	int p; cin >> p;
	bool yes=0;
	for(int i=0;i<=p;i++){
		for(int j=0;i+j<=p;j++){
			for(int k=0;i+j+k<=p;k++){
				VI b(3);
				b[0]=a[0]*pow(2,i);
				b[1]=a[1]*pow(2,j);
				b[2]=a[2]*pow(2,k);
				if(b[0]<b[1]&&b[1]<b[2])
					yes=1;
			}
		}
	}
	if(yes)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 4104
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n+1);
    cin >> a;
    if(n == 0) {
        cout << (a[0] == 1 ? 1 : -1) << endl;
        return 0;
    }
    if(a[0] > 0) {
        cout << -1 << endl;
        return 0;
    }
    vl mn(n+1,0),mx(n+1,0);
    rrep(i,n) {
        mn[i] = (mn[i+1]+a[i+1]+1)/2;
        mx[i] = mx[i+1]+a[i+1];
    }
    if(mn[0] > 1) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 1;
    rep(i,n+1) ans += a[i];
    ll now = 1;
    rep(i,n) {
        now = min(mx[i+1],now*2-a[i+1]);
        if(now < mn[i+1]) {
            cout << -1 << endl;
            return 0;
        }
        ans += now;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5312
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;


signed main() {
  ll a,b;
  cin>>a>>b;
  cout<<a*b<<endl;
  return 0;
}


Measured memory_bytes: 3588
N = int(input())
F = [ list(map(int,input().split())) for i in range(N) ]
P = [ list(map(int,input().split())) for i in range(N) ]
ans = -float('inf')

for i in range(1, 1024):
    B = bin(i)[2::]
    count = [0]*N
    for i, b in enumerate(str(B[::-1])):
      if b == "1":
        for j, f in enumerate(F):
          if f[i] == 1:
            count[j] += 1
    l=0
    for p, c in zip(P, count):
        l += p[c]
    ans = max(ans, l)
print(ans)


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

int main() {
  ll n, a, b; cin >> n >> a >> b;
  ll x = n / (a+b);
  ll y = n % (a+b);
  cout << a*x + min(a, y) << endl;
  return 0;
}

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

ans = 0

for i in range(n):
    for j in range(1,n):
        for k in range(2,n):
            tmp = []
            if i != j != k and i < j < k:
                tmp.append(a[i])
                tmp.append(a[j])
                tmp.append(a[k])
                tmp.sort()
                if len(tmp) == 3 and abs(tmp[0]-tmp[1]) < tmp[2] and tmp[2] < tmp[0]+tmp[1] and tmp[0] != tmp[1] != tmp[2]:
                    ans += 1

print(ans)

Measured memory_bytes: 74384
import itertools

n, m, q = map(int, input().split())
li = []
for i in range(q):
    li.append(list(map(int, input().split())))

Alist = list(itertools.combinations_with_replacement(range(1, m + 1), n))

answer = []
for i in range(len(Alist)):
    score = 0
    for j in range(q):
        b = li[j][1]-1
        a = li[j][0]-1
        if (Alist[i][b] - Alist[i][a] == li[j][2]):
            score += li[j][3]
    answer.append(score)

print(max(answer))


Measured memory_bytes: 25220
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		 int K =sc.nextInt();
      	 int sum = 0;
      
      for(int a=1; a<=K; a++){
    	  for(int b=1; b<=K; b++){
    		  for(int c=1; c<=K; c++){
    			  sum += gcd(gcd(a,b),c);
    		  }
    	  }
      }
      System.out.println(sum);
    }
      public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
}

Measured memory_bytes: 35740
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ms(x) memset(x, 0, sizeof(x))
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
    char s[123456];
    int cnt[27], book[27];
    while(scanf("%s",s)!=EOF){
        ms(cnt);
        int len = strlen(s), s1 = 0, s2 = 0;
        if(s[0] == s[len-1]) len--;
        if(len%=2) {printf("First\n");}
        else printf("Second\n");
    }
    return 0;
}


Measured memory_bytes: 384