akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define MOD 1000000007
#define mod 998244353
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define vvi vector<vi>
#define endl "\n"
using namespace std;
void solve1();
void solve()
{
    int T;cin>>T;
    for(int z=1;z<=T;z++)
    {
        solve1();
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve1();
    return 0;
}
void solve1()
{
    int n;cin>>n;
    int c=0,ans=0;
    for(int i=0;i<10000000;i++)
    {
        c+=7;
        c%=n;c*=10;
        ans++;
        if(c==0)
        {
            break;
        }
    }
    if(c==0)cout<<ans<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 3664
n, k = map(int, input().split())
X = []
for i in range(n):
    a, b = map(int, input().split())
    X.append((a, b))

X.sort()
cnt = 0
for i in range(n):
    a, b = X[i]
    cnt += b
    if cnt >= k:
        print(a)
        exit()


Measured memory_bytes: 53336
#include <algorithm>
#include <cstdio>
#include <climits>

int main() {
    int n, k;
    std::scanf("%d %d", &n, &k);

    int *hs = new int[n];
    for (int i = 0; i < n; i++) {
        std::scanf("%d", &hs[i]);
    }
    std::sort(hs, hs + n);

    int result = INT_MAX;
    for (int i = 0; i < n - k + 1; i++) {
        int t = hs[i+k-1] - hs[i];
        if (hs[i+k-1] - hs[i] < result) {
            result = t;
        }
    }

    std::printf("%d", result);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#define INF (1ll << 62)
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
typedef map<int, vector<int>> Graph;
typedef map<int, map<int, ll>> WGraph;
typedef pair<int, int> Edge;
vector<ll> bellmanford(int v, WGraph &g, int r)
{
    vector<ll> cost(v, INF);
    cost[r] = 0;
    rep(_, v)
    {
        rep(i, v)
        {
            for (auto x : g[i])
            {
                int j = x.first;
                ll c = x.second;
                if (cost[i] != INF && cost[j] > cost[i] + c)
                {
                    cost[j] = cost[i] + c;
                }
            }
        }
    }
    rep(i, v)
    {
        for (auto x : g[i])
        {
            int j = x.first;
            ll c = x.second;
            if (cost[i] != INF && cost[j] > cost[i] + c)
            {
                return vector<ll>(v, -INF);
            }
        }
    }
    return cost;
}

int main(int argc, char const *argv[])
{
    int n, m, r;
    cin >> n >> m >> r;
    WGraph g;
    rep(i, m)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        g[a][b] = c;
    }
    auto cost = bellmanford(n, g, r);
    if (cost[0] == -INF)
    {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else
    {
        rep(i, n)
        {
            if (cost[i] == INF)
            {
                cout << "INF" << endl;
            }
            else
            {
                cout << cost[i] << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3300
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    battles = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int, input().split())
        battles[b-1].append(a-1)

    x = -1
    ans = 0
    for i in range(1,N):
        battle = battles[i]
        if len(battle) == 0: continue

        closest_idx = max(battle)
        if x < closest_idx:
            ans += 1
            x = i-1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 17404
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int n;
ll dp[101][1<<16];

ll solve(){
	vector<pair<ll,ll>> v(n);
	for(int i=0;i<n;i++){
		int a; cin >> a;
		cin >> v[i].first;
		while(a--){
			int s,e; cin >> s >> e;
			for(int j=s;j<e;j++){
				v[i].second+=(1<<(j-6));
			}
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<(1<<16);j++){
			dp[i][j]=0;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<(1<<16);j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(v[i].second&j)continue;
			dp[i+1][j|v[i].second]=max(dp[i+1][j|v[i].second],dp[i][j]+v[i].first);
		}
	}
	ll res=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<(1<<16);j++){
			res=max(res,dp[i][j]);
		}
	}
	return res;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(cin >> n,n){
		printf("%lld\n",solve());
	}
}



Measured memory_bytes: 54900
def main():
    n = int(input())
    arr = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    sq = sum(num*num for num in arr)
    S = sum(arr)
    print(((S*S-sq)//2)%mod)

if __name__ == "__main__":
    main()

Measured memory_bytes: 31580
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,r;
	cin>>n>>r;
	cout<<(n+2*r)/(2*r+1)<<endl;


	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define nl cout<<'\n'
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pll pair<long long,long long>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define sll set<long long>
#define all(v) (v).begin(),(v).end()
#define Unique(x)           (x).erase(unique(all(x)), x.end())
#define v_present(vec, x)  (find(all(vec),x)!=(vec).end())
#define present(myset, x)    ((myset).find(x)!=(myset).end())
#define Cprint(c)  for(auto i:(c)) { cout<<i<<" "; } nl
#define trace2(x, y) cout<<x<<" "<<y<<endl;
#define trace3(x, y, z) cout<<x<<" "<<y<<" "<<z<<endl;
#define trace4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<endl;
ll mod = 1e9 + 7;
const int MAX = 1e5 + 5;

using namespace std;

ll dp[405][405];  // dp[i][j] represents ways to divide j candies among 1st i students
ll pre[405];
//
//ll solve(int i, int j){
//    if(i==j)
//        return 0;
//
//    ll &ans=dp[i][j];
//    if(ans!=-1)
//        return ans;
//    ans=1e15;
//    for(int k=i;k<=j-1;k++){
//        ans=min(ans,solve(i,k)+solve(k+1,j)+pre[j]-pre[i-1]);
//    }
//    return ans;
//}


int main() {
    FAST_IO;
    int n;
    cin >> n ;
    vll a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pre[i]=pre[i-1]+a[i];
    }
    for(int i=1;i<=n;i++)
        dp[i][i]=0;

    for(int siz=2;siz<=n;siz++){
        for(int i=1;i<=n-siz+1;i++){
            int l=i; int r=i+siz-1;
            //cout<<l<<" "<<r;nl;
            dp[l][r]=1e15;
            for(int k=l; k<=r-1; k++){
                dp[l][r] = min(dp[l][r],dp[l][k]+dp[k+1][r]+pre[r]-pre[l-1]);
            }
        }
    }
    cout<<dp[1][n];
    return 0;

}

Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		bubbleSort(list);
	}

	public static void bubbleSort(List<Integer> list) {
		int count = 0;
		for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		}
		showList(list);
		System.out.println(count);
	}

	public static void showList(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	}
}



Measured memory_bytes: 26248
from itertools import product
d = (0,1)
s = input()
for i,j,k,l in product(d,repeat=4):
  ans = "A"*i + "KIH" + "A"*j + "B" + "A"*k + "R" + "A"*l
  if s == ans:
    print("YES")
    break
else:
  print("NO")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl "\n"
#define int long long int
using namespace std;

int dp[3000][3000];
int find(int arr[], int i, int j) {
	if (dp[i][j] != -1)
		return dp[i][j];
	if (i == j)
		return arr[i];
	int taro = INT_MIN, jiro = INT_MAX;
	taro = max(arr[i] + find(arr, i + 1, j) - jiro, arr[j] + find(arr, i, j - 1) - jiro);
	jiro = min(taro - arr[i] + find(arr, i + 1, j), taro - arr[j] + find(arr, i, j - 1));
	return dp[i][j] = taro - jiro;
}


int32_t main() {
	int n;
	cin >> n;
	int arr[n];
	memset(dp, -1, sizeof dp);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	cout << find(arr, 0, n - 1);
	return 0;
}

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

using LL = long long;

int N;
int big = 0;
multiset<int> S;

int main() 
{
	cin >> N;
	for (int i = 0; i < (1 << N); ++i) {
		int elm;
		cin >> elm;
		S.insert(elm);
		big = max(big, elm);
	}
	
	vector<int> T;
	T.push_back(big);
	S.erase(S.find(big));
	
	for (int i = 0; i < N; ++i) {
		vector<int> uT;
		for (int elm : T) {
			auto itr = S.lower_bound(elm);
			if (itr == S.begin()) {
				cout << "No" << endl;
				return 0;
			}
			--itr;               
			uT.push_back(*itr);
			S.erase(itr);
		}
	
		for (int elm : uT)
		   T.push_back(elm);
	}
	
	cout << "Yes" << endl;
	return 0;
}




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

using namespace std;

int main () {
	string S;
	cin >> S;

	string ans;
	for (auto c : S) {
		if (c == 'B') {
			if (!ans.empty()) {
				ans.pop_back();
			}
		} else {
			ans.push_back(c);
		}
	}

	cout << ans << endl;
}

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

int main()
{
  int a;
  cin >> a;
  if(a % 2 == 0) cout << a << endl;
  else cout << a * 2 << endl;
  return 0;
}


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

int main() {
	vector<vector<int>> A(3,vector<int>(3)),C(3,vector<int>(3,0));
	for(int i=0;i<3;i++){
	    for(int j=0;j<3;j++){
	        cin >> A.at(i).at(j);
	    }
	}
	int N;
	cin >> N;
	vector<int> b(N);
	for(int k=0;k<N;k++){
	    cin >> b.at(k);
	    for(int i=0;i<3;i++){
	        for(int j=0;j<3;j++){
	            if(b.at(k)==A.at(i).at(j)){
	                C.at(i).at(j)=1;
	            }
	        }
	    }
	}
	int flag=0;
	int i=0;
	while(flag==0 && i<3){
	    if(C.at(i).at(0)==1 && C.at(i).at(1)==1 && C.at(i).at(2)==1){
	        flag=1;
	    }
	    i++;
	}
	i=0;
	while(flag==0 && i<3){
	    if(C.at(0).at(i)==1 && C.at(1).at(i)==1 && C.at(2).at(i)==1){
	        flag=1;
	    }
	    i++;
	}
	if(C.at(0).at(0)==1 && C.at(1).at(1)==1 && C.at(2).at(2)==1){
	    flag=1;
	}
	if(C.at(0).at(2)==1 && C.at(1).at(1)==1 && C.at(2).at(0)==1){
	    flag=1;
	}
	if(flag==1){
	    cout << "Yes" << endl;
	}
	else{
	    cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    if(n%1000==0){
      System.out.println(0);
    }else{
      System.out.println(1000-(n%1000));
    }
  }
}


Measured memory_bytes: 35712
x,n = map(int,input().split())
p = list(map(int,input().split()))
f = [False] * 301
#f[0]は-1
    
a = 1145141919
ans = 0
for i in range(-100,300):
    fl = 1
    for j in p:
        if i == j:
            fl = 0
            
    if fl == 1:
        if abs(i-x) < a:
            ans = i
            a = abs(i-x)
            
print(ans)

Measured memory_bytes: 64452
#include <bits/stdc++.h>
using namespace std;
int h,w,sum=0;
bool end={false};
string p[10][10];
string ppp[10];
void dfs(int x,int y,int sum1)
{
	if (end==true)
	{
		return;
	}
	if (x==h && y==w && sum1==sum)
	{
		cout <<"Possible";
		end=true;
		return;
	}
	if (x==h && y==w && sum1!=sum)
	{
		cout <<"Impossible";
		end=true;
		return;
	}
	if ((p[x+1][y]=="." && p[x][y+1]==".") || (x+1>h && p[x][y+1]==".") || (y+1>w && p[x+1][y]=="."))
	{
		cout <<"Impossible";
		end=true;
		return;
	}
	if (p[x+1][y]=="#" && p[x][y+1]=="#")
	{
		cout <<"Impossible";
		end=true;
		return;
	}
	if (p[x+1][y]=="#")
	{
		dfs(x+1,y,sum1+1);
	}
	if (p[x][y+1]=="#")
	{
		dfs(x,y+1,sum1+1);
	}
}
int main()
{
	cin>>h>>w;
	for (int i=1; i<=h; i++)
	{
		cin>>ppp[i];
	}
	for (int i=1; i<=h; i++)
	{
		for (int j=1; j<=w; j++)
		{
			p[i][j]=ppp[i].substr(j-1,1);
			if (p[i][j]!="#")
			{
				p[i][j]=".";
			}
			if (p[i][j]=="#")
			{
				sum++;
			}
		}
	}
	dfs(1,1,1);
	return 0;
}

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

int g(int x, int y, int z) {
	return x*x+y*y+z*z+x*y+y*z+z*x;
}

int main() {
	int n;
	cin >> n;
	vector<int> f(n+1,0);
	for (int x=1;x<=100;x++) 
		for (int y=1;y<=100;y++)
			for (int z=1;z<=100;z++) {
				int num = g(x,y,z);
				if (num>=1 && num<=n) f[num]++;
			}
	for (int i=1;i<=n;i++) cout << f[i] << endl;
	return 0;
}


Measured memory_bytes: 3572
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        List<Integer> a = new ArrayList();
        a.add(1);
        a.add(3);
        a.add(5);
        a.add(7);
        a.add(8);
        a.add(10);
        a.add(12);
        List<Integer> b = new ArrayList();
        b.add(4);
        b.add(6);
        b.add(9);
        b.add(11);
        List<Integer> c = new ArrayList();
        c.add(2);
        if (a.contains(x) && a.contains(y)) {
            System.out.println("Yes");
        } else if (b.contains(x) && b.contains(y)) {
            System.out.println("Yes");
        } else if (c.contains(x) && c.contains(y)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	char s[5]; scanf("%s", s);
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) printf("Bad\n");
	else printf("Good\n");
}


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

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  rep(i, n) {
    if ((i+1)%3!=0 && (i+1)%5!=0) res += i+1;
  }
  cout << res << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N, M, X;
ll ret = LINF;
vl c(13, 0);
vvl m(13, vl(13));
bool flg = false;

int main(void){
  
  I(N);
  I(M);
  I(X);
  FOR(i, 1, N+1) {
    I(c[i]);
    FOR(j, 1, M+1) {
      I(m[i][j])
    }
  }

  FOR(bit, 0, (1<<N)) {
    vl study(M+1, 0);
    ll price = 0;
    FOR(i, 1, N+1) {
      if ((bit >> (i-1)) & 1) {
        price += c[i];
        FOR(j, 1, M+1) {
          study[j] += m[i][j];
        }
      }
    }
    bool ok = true;
    FOR(j, 1, M+1) {
      if (study[j] < X) ok = false;
    }
    if (ok) {
      flg = true;
      chmin(ret, price);
    }
  }

  P(flg ? ret : -1);

}


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

void solve(std::vector<long long> x)
{
    for (int i = 0; i < 5; i++)
    {
        if (x[i] == 0)
            cout << i + 1 << endl;
    }
}

int main()
{
    std::vector<long long> x(5);
    for (int i = 0; i < 5; i++)
    {
        scanf("%lld", &x[i]);
    }
    solve(std::move(x));
    return 0;
}


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

int main(){
	string s; 
	cin>>s;
	string weather[3];
	weather[0]="Sunny";
	weather[1]="Cloudy";
	weather[2]="Rainy";
	for(int i=0;i<=2;i++){
		if(weather[i]==s){
			cout<<weather[(i+1)%3];
		}
	}
	
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INF 1000000
#define NIL -1
    
int n;
int d[MAX],w[MAX][MAX],pi[MAX];
    
void prime() {
   
  int o,v,i,j,color[MAX],min;
    
  for(o = 0;o < n; o++){
    d[o] = INF;
    pi[o] = NIL;
    color[o] = 0;
  }
    
  d[0] = 0;
    
  for(i = 0;i < n;i++) {
      
    min = INF;
    for (j = 0;j < n; j++){
      if(color[j] == 1)
    continue;
        
      if(d[j] <= min){
    o = j;
    min = d[j];
      }
    }
      
    for(v = 0;v < n; v++){
      if(w[o][v] == -1){
     continue;
      }
      if(color[v] == 1){
    continue;
      }
        
      if(w[o][v] < d[v]){
    pi[v] = o;
    d[v]=w[o][v];
      }
    }
    color[o]=1;
  }
}
  
main() {
  int i,j,sum=0;
  scanf("%d",&n);
    
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&w[i][j]);
    }
  }
    
  prime();
  for(i=0;i<n;i++)
    sum+=d[i];
    
  printf("%d\n",sum);
    
  return 0;
}

Measured memory_bytes: 640
N=int(input())
A=list(map(int,input().split()))
num_node=[1]*(N+1)
for i in range(1,N+1):
    tmp=2*(num_node[i-1]-A[i-1])
    if tmp<0:
        print(-1)
        exit()
    num_node[i]=tmp

tmp=2*(num_node[N]-A[N])
if tmp<0:
    print(-1)
    exit()

num_node[-1]=A[N]
for i in range(N-1,-1,-1):
    tmp=num_node[i+1]
    tmp+=A[i]
    if tmp<=num_node[i]:
        num_node[i]=tmp

print(sum(num_node))

Measured memory_bytes: 674396
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int r[N],c[N],dp[2 * N - 1],dn[2 * N - 1];

bool X[N][N];

void initialize() {
  int i;
  
  for(i = 0;i < N;i++) {
    r[i] = FREE;
    c[i] = FREE;
  }
  for(i = 0;i < 2 * N - 1;i++) {
    dp[i] = FREE;
    dn[i] = FREE;
  }
}

void printBoard() {
  int i,j;
  
  for(i = 0;i < N;i++) {
    for(j = 0;j < N;j++) {
      if(X[i][j]) {
	if(r[i] != j) return;
      }
    }
  }
  for(i = 0;i < N;i++) {
      for(j = 0;j < N;j++) {
	if(r[i] == j) printf("Q");
	else printf(".");
      }
      printf("\n");
    }
}

void recursive(int i) {
  int j;
  
  if(i == N) {
    printBoard();
    return;
  }

  for(j = 0;j < N;j++) {
    if(NOT_FREE == c[j] ||
       NOT_FREE == dp[i + j] ||
       NOT_FREE == dn[i - j + N - 1]) continue;

    r[i] = j;
    c[j] = dp[i + j] = dn[i - j + N - 1] = NOT_FREE;

    recursive(i + 1);

    r[i] = c[j] = dp[i + j] = dn[i - j + N - 1] = FREE;
  }
}

int main() {
  int i,j,k,r,c;

  initialize();

  for(i = 0;i < N;i++){
    for(j = 0;j < N;j++) {
      X[i][j] = false;
    }
  }
  
  scanf("%d",&k);

  for(i = 0;i < k;i++) {
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }

  recursive(0);

  return 0;
}


  



Measured memory_bytes: 2108
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define pb push_back
#define Never
#define To

using namespace std;

int N;
int X[16][16];

int dfs(int x, const int pAns[]){

	int Ans[N];

	for(int i = 0; i < N; i++){
		Ans[i] = pAns[i];
	}

	if(x == N) {
		int sum = 0;
		for(int i = 0; i < N; i++){
			sum += Ans[i];
		}
		return sum;
	}

	if(Ans[x] == 0){
		return dfs(x+1, Ans);
	}

	int ans = 0;
	if(Ans[x] == -1){
		Ans[x] = 0;
		ans = dfs(x+1, Ans);
		Ans[x] = 1;
	}

	for(int j = 0; j < N; j++){
		if((X[x][j] == 0 && Ans[j] == 1) || (X[x][j] == 1 && Ans[j] == 0)) {
			return ans;
		}
	}

	for(int j = x; j < N; j++){
		if(X[x][j] != -1) Ans[j] = X[x][j];
	}
	return max(ans, dfs(x+1, Ans));
}

int main(){

	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	
	int Ans[N];

	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			X[i][j] = -1;
		}
	}

	for(int i = 0; i < N; i++){
		int M;
		cin >> M;
		for(int j =0; j < M; j++){
			int x; 
			cin >> x;
			cin >> X[i][x-1];
		}
	}

	for(int i = 0; i < N; i++){
		Ans[i] = -1;
	}

	cout << dfs(0, Ans) << endl;

	Never To return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Set;

public class Main {

  private static void solve() {
    int k = ni();
    Set<Long> set = new HashSet<>();

    long now = 7;

    for (int i = 1;; i++) {
      if (set.contains(now)) {
        break;
      }
      if (now % k == 0) {
        System.out.println(i);
        return;
      }
      set.add(now);
      now = (now * 10 + 7) % k;
    }
    System.out.println(-1);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 131104
N, A = map(int, input().split())
X = list(map(int, input().split()))
dp = [[0]*(A*N+2) for _ in range(N+2)]
dp[0][0] = 1
for i, x in enumerate(X,start=1):
    for n in reversed(range(i)):
        for k in range(A*N+1):
            if dp[n][k] == 0: continue
            dp[n+1][min(k+x,A*N+1)] += dp[n][k]
print(sum(dp[n][A*n] for n in range(1,N+1)))


Measured memory_bytes: 68740
def dot(a,b):return a[0]*b[0]+a[1]*b[1]
def projection(a,b):return [x*dot(a,b)/dot(a,a) for x in a]

x1,y1,x2,y2 = [int(i) for i in input().split()]
a = [x2-x1,y2-y1]
q = int(input())
for i in range(q):
 x,y = [int(i) for i in input().split()]
 b = [x-x1,y-y1]
 c = projection(a,b)
 print(c[0]+x1,c[1]+y1)

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

typedef long long ll;

int main() {
    vector<int> A(3);
    rep(i, 3) cin >> A[i];
    sort(A.begin(), A.end());
    int B = A[2] * 2 - A[0] - A[1];
    if (B % 2) B += 3;
    cout << B / 2 << "\n";
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(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 Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n >> m;
	vd a(n);
	rep(i,n) cin >> a[i];
	sort(rall(a));
	bool b=true;
	rep(i,m){
		if(a[i]<sumvec(a)*(1.0/(4.0*(double)m))) b=false;
	}
	Yes(b);
	return 0;
}


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

using namespace std;

int main(){
	string s;
	string word[500];
	int a[500]={};
	int i,j,k,l;
	int n,m,len;
	i=0;
	while(cin>>s){
		if(i==0){	//????????????????????????
			word[0]=s;
			a[0]++;
			i++;
			len=s.size();
			n=0;
		}
		else {
			if(len<s.size()){	//?????????????????????????????°??´??°
				len=s.size();
				n=i;
			}
			for(j=0; j<i; j++){
				if(s==word[j]){	//?????§????????????????????????
					a[j]++;
					break;
				}
				if(j==i-1){			//??°?????????????????????
					word[i]=s;
					a[i]++;
					i++;
					break;
				}
			}
		}
	}
	m=0;
	for(j=0; j<i; j++){		//????????????????????????????????????
		if(m<a[j]){
			m=a[j];
			l=j;
			//cout<<l<<" "<<a[j]<<endl;
		}
	}
	cout<<word[l]<<" "<<word[n]<<endl;
	// for(j=0; j<i; j++){
	// 	cout<<word[j]<<":"<<a[j]<<endl;
	// }
	//cout<<m<<endl;
	//cout<<"len:"<<len<<" "<<word[n]<<endl;
	return 0;
}

Measured memory_bytes: 1196
import numpy

n, m = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
sup_A = 10 ** 5
B = [0] * (2 * sup_A + 1)
for a in A:
    B[a] += 1
C = numpy.fft.fft(B)
D = numpy.fft.ifft(C * C)

ans = 0
cnt = 0
for i in range(2 * sup_A, -1, -1):
    d = int(D[i].real + 0.5)
    if cnt + d >= m:
        ans += (m - cnt) * i
        break
    cnt += d
    ans += i * d

print(ans)

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

int main(){
  long long n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (n == 1 && m > 1) {
    cout << m - 2 << endl;
    return 0;
  }
  if (n > 1 && m == 1) {
    cout << n - 2 << endl;
    return 0;
  }
  cout << (n - 2) * (m - 2) << endl;
}


Measured memory_bytes: 256
from collections import deque
n=int(input())
c=input()
r=deque()
lr=0
for i in range(n):
    if c[i]=="R":
        lr+=1
        r.append(i)
ans=0
for i in range(n):
    if lr==0:
        break
    if c[i]=="W":
        if i<r[-1]:
            ans+=1
            r.pop()
            lr-=1
        else:
            break

print(ans)

Measured memory_bytes: 68632
#include <iostream>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	if (A == B)
		cout << "Draw" << endl;
	else if (A == 1)
		cout << "Alice" << endl;
	else if (B == 1)
		cout << "Bob" << endl;
	else
		cout << ((A > B) ? "Alice" : "Bob") << endl;

	return 0;
}


Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # comb init
    # mod = 1000000007
    nmax = 2 * 10 ** 5 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    S = int(input())
    if S < 3:
        print(0)
        exit()

    ans = 0
    for N in range(1, S+1):
        K = S - N * 3
        if K < 0:
            break
        ans = (ans + comb(K+N-1, N-1))%mod
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	int ans;
	if (a <= b) {
		ans = a;
	}
	if (a > b) {
		ans = a - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int a[15];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=a[i];
	}
	ans-=a[n]>>1;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,(v))
#define MA(a,v) a = max(a,(v))
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
const int INF=1e9;

struct ij{int i,j;};

int n,m;

V<ij> adj(ij a) {
    V<ij> v;
    for (ij b : V<ij>{{a.i+1,a.j}, {a.i,a.j+1}, {a.i-1,a.j}, {a.i,a.j-1}})
        if (0 <= b.i && b.i < n && 0 <= b.j && b.j < m)
            v.pb(b);
    return v;
}

signed main() {
    int k; cin>>n>>m>>k;
    string grid[n];
    ij s;
    F(i,n) {
        cin>>grid[i];
        F(j,m) if (grid[i][j] == 'S')
            s = {i,j};
    }
    int d[n][m]; fill(d[0], d[n], INF);
    d[s.i][s.j] = 0;
    queue<ij> q; q.push(s);
    while (!q.empty()) {
        ij u = q.front(); q.pop();
        for (ij v : adj(u))
            if (grid[v.i][v.j] != '#' && d[v.i][v.j] == INF)
                d[v.i][v.j] = d[u.i][u.j] + 1, q.push(v);
    }
    int minD=INF;
    F(i,n) F(j,m) {
        if (d[i][j] <= k)
            MI(minD, min({i, n-1-i, j, m-1-j}));
    }
    P(1+(minD+k-1)/k);
}

Measured memory_bytes: 6144
"use strict"

let arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
arg_str = arg_str.split('\n')
const N = +arg_str[0]
const d_array = arg_str[1].split(' ').map(x=>+x)

let sum = 0
for(let i=0;i<N;i++){
    for(let j=i+1;j<N;j++){
        sum += (d_array[i] * d_array[j])
    }
}

console.log(sum)

Measured memory_bytes: 21064
#include<stdio.h>
int main(void){
    char s[5],tmp1,tmp2;
    int count1=0,count2=0;

    scanf("%s",s);

    tmp1=s[0];

    for(int i=0;i<5;i++){
        if(tmp1!=s[i]){
            tmp2=s[i]; 
            break;
        }  
    }

    for(int i=0;i<5;i++){
        if(tmp1==s[i])
            count1++;
        else if(tmp2==s[i])
            count2++;
     }
     if(count1==2 && count2==2)
        printf("Yes\n");
        else
            printf("No\n");

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <tuple>

void inspect(const std::vector<int>& v) {
  for (size_t i = 0; i < v.size(); ++i)
    fprintf(stderr, "%d%c", v[i], i+1<v.size()? ' ':'\n');
}

bool nyan(int H, int s,
          const std::vector<size_t>& S, const std::vector<size_t>& T) {

  size_t N = S.size();

  int sl = s;
  int sr = s;

  size_t m1 = -1;
  for (size_t i = 0; i < N; ++i) {
    if (S[i] == m1) {
      --sl;
    } else if (S[i] == 1) {
      ++sr;
    }
    if (sl < 0 || sr >= H) return true;

    if (T[i] == m1 && sr > 0) {
      --sr;
    } else if (T[i] == 1 && sl+1 < H) {
      ++sl;
    }
  }
  return false;
}

int main() {
  size_t H, W, N;
  scanf("%zu %zu %zu", &H, &W, &N);

  size_t sr, sc;
  scanf("%zu %zu", &sr, &sc);
  --sr;
  --sc;

  char buf[262144];
  scanf("%s", buf);
  std::string S = buf;
  scanf("%s", buf);
  std::string T = buf;

  std::vector<size_t> HS(N), HT(N), WS(N), WT(N);
  for (size_t i = 0; i < N; ++i) {
    if (S[i] == 'U') {
      HS[i] = -1;
    } else if (S[i] == 'D') {
      HS[i] = 1;
    } else if (S[i] == 'L') {
      WS[i] = -1;
    } else if (S[i] == 'R') {
      WS[i] = 1;
    }

    if (T[i] == 'U') {
      HT[i] = -1;
    } else if (T[i] == 'D') {
      HT[i] = 1;
    } else if (T[i] == 'L') {
      WT[i] = -1;
    } else if (T[i] == 'R') {
      WT[i] = 1;
    }
  }

  if (nyan(H, sr, HS, HT)) {
    puts("NO");
  } else if (nyan(W, sc, WS, WT)) {
    puts("NO");
  } else {
    puts("YES");
  }
}


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

using namespace std;

#define int long long

struct Point
{
	int x, y;
};

Point v[10];

bool vis[10];

long double sum = 0;

long double dist(Point x, Point y)
{
	return sqrt(1.0 * (x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));
}

int n;

int st[10];

void back(int niv)
{
	if(niv == n + 1)
	{
		for(int i = 1; i < n; i++)
			sum += dist(v[st[i]], v[st[i + 1]]);
		
		return ;
	}
	
	for(int i = 1; i <= n; i++)
		if(vis[i] == false)
		{
			vis[i] = true;
			st[niv] = i;
			back(niv + 1);
			vis[i] = false;
		}
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	
	int total = 1;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> v[i].x >> v[i].y;
		total *= i;
	}
	
	back(1);
	
	cout << fixed << setprecision(8) << sum * 1.0 / total;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
  	int A = sc.nextInt(); //2<=A<=20
	int B = sc.nextInt(); //1<=B<=20
  	int tap = 0;
/*
高橋くんの家には電源プラグの差込口が 1 口しかありません。
そこで、高橋くんは A 個口の電源タップをいくつか使って未使用の差込口を 
B 口以上に拡張したいと考えています。
A 個口の電源タップ 1 つと未使用の差込口 1 口を使って、新たに差込口を A 口増やすことができます。
最小でいくつの電源タップが必要でしょうか。
*/
  	int i=0;
  	while( (A-1) * tap + 1 < B ){
  		tap++;
    }
  
  	System.out.println(tap);                           
}
}

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

#define ll long long

signed main()
{
  string a,b,c;
  cin >> a >> b >> c;
  if(a.back() == b[0] && b.back() == c[0])
  {cout << "YES";}
  else{cout << "NO";}
}

Measured memory_bytes: 3624
n = int(input())
s = [0]*n
import collections
t = [0]*n
for i in range(n):
    s[i] = input()
    t[i] = collections.Counter(s[i])
m = [100]*26
ans = []
for A in t:
    for i in range(26):
        m[i] = min(m[i],A[chr(97+i)])
for i in range(26):
    if m[i] != 100 and m[i] != 0:
        ans.append([chr(97+i)]*m[i])
for A in ans:
    print("".join(A),end="")
print("")


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

const int div_num = 1000000007;
int N;
vector<int> A;

bool check_even(void) {
	for (int i = 0; i < N / 2; ++i) {
		if (A[2 * i] != 2 * i + 1)
			return false;
		if (A[2 * i + 1] != 2 * i + 1)
			return false;
	}
	return true;
}

bool check_odd(void) {
	if (A[0] != 0)
		return false;
	for (int i = 1; i <= N / 2; ++i) {
		if (A[2 * i - 1] != 2 * i)
			return false;
		if (A[2 * i] != 2 * i)
			return false;
	}
	return true;
}

int my_pow(int p) {
	int ans = 1;
	for (int i = 1; i <= p; ++i) {
		ans *= 2;
		if (ans >= div_num)
			ans = ans % div_num;
	}
	return ans;
}

int main(void) {
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];

	sort(A.begin(), A.end());
	bool check = false;
	if (N % 2 == 0)
		check = check_even();
	else
		check = check_odd();

	int ans = 0;
	if (check)
		ans = my_pow(N / 2);

	cout << ans << '\n';
	return 0;
}


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

using namespace std;

#define all(x) (x).begin(),(x).end()

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(void){

    int n;
    cin >> n;

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

    int ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            for(int k = j+1; k < n; ++k){
                if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[k] + a[j] > a[i] && a[i] != a[j] && a[j] != a[k] && a[i] != a[k]){
                    ans++;
                }
            }
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

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

int main(){
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);
    int total = 0;
    for (int i =1; i <=N ; ++i) {
        int sum = findSumOfDigits(i);
        if(sum>=A && sum <= B){
            total += i;
        }
    }
    printf("%d", total);
}

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

#define ll long long
#define endl "\n"

void solve() {
  ll n;
  cin >> n;
  ll x, y, ans = 0, mx = 0;
  vector<ll> v;
  for (ll i = 0; i < n; ++i) {
    cin >> x >> y;
    if (x == y)
      v.push_back(i + 1);
  }
  for(ll i=0; i<v.size(); ++i){
    if(v[i] + 1 == v[i+1] && v[i+1] + 1 == v[i+2]){
      cout  << "Yes\n";
      return;
    }
  }
  cout << "No\n";
  
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 3572
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    int n;
    ll ans = 0;
    cin >> n;
    vector<ll> a(n+1), b(n);
    rep(i, n+1)cin >> a[i];
    rep(i, n)cin >> b[i];
    
    rep(i, n){
        if(b[i] <= 0) continue;
 
        if(b[i] >= a[i]+a[i+1]){
            ans += a[i]+a[i+1];
            a[i+1] = 0;
            continue;
        }
 
        if(b[i] <= a[i]){
            ans += b[i];
            continue;
        }
 
        if(b[i] <= a[i]+a[i+1]){
            ans += b[i];
            b[i] -= a[i];
            a[i+1] -= b[i];
            continue;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
import copy
k=int(input())
l=[1,2,3,4,5,6,7,8,9]
h=1
s=0
s1=0
A=[]
C=[1]
D=[]
while len(l)<k:
    s1=len(l)
    for i in range(0,len(A)):
        l.append(A[i]+10**h)
        D.append(A[i]+10**h)
    A.extend(C)
    C=copy.deepcopy(D)
    D=[]
    for i in range(s,s1):
        j=str(l[i])
        an=int(j[0])
        if an==1:
            l.append((10**h)+l[i])
            l.append(2*(10**h)+l[i])
            C.append((10**h)+l[i])
        elif an==9:
            l.append(9*(10**h)+l[i])
            l.append(8*(10**h)+l[i])
        elif an==2:
            l.append((10**h)+l[i])
            l.append((2)*(10**h)+l[i])
            l.append((3)*(10**h)+l[i])
            C.append((10**h)+l[i])
        else:
            l.append(an*(10**h)+l[i])
            l.append((an+1)*(10**h)+l[i])
            l.append((an-1)*(10**h)+l[i])
    l.append(10**h)
    C.append(10**h)
    h=h+1
    s=s1
B=l[s:]
B.sort()
print(B[k-s-1])

Measured memory_bytes: 14784
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;

int main(){
  int n;
  int id[100];
  double p[100],w[100];
  bool use[100];
  long long int pas[101][101];
  
  for(int i=0;i<=100;i++){
    pas[i][0] = 1;
    pas[0][i] = 1;
  }

  for(int i=1;i<=100;i++){
    for(int j=1;j<=100;j++)pas[i][j] = (pas[i-1][j] + pas[i][j-1]) % 100000007;
  }
  
  for(;;){
    scanf("%d",&n);
    if(!n)break;

    for(int i=0;i<n;i++){
      scanf("%lf %d %lf",&p[i],&id[i],&w[i]);
      use[i] = false;
    }

    double ans = 0.0;
    int rem = n;
    long long int t = 1;
    for(int i=0;i<n;i++){
      if(!use[i]){
	use[i] = true;
	int tmp = i;
	vector<int> l;

	l.push_back(tmp);
	for(;;){
	  tmp = id[tmp];
	  if(tmp==i)break;
	  use[tmp] = true;
	  l.push_back(tmp);
	}

	int num = 1;
	double m = 1.0/p[l[0]] - 1.0/w[l[0]];
	ans += 1.0/w[l[0]];
	for(int j=1;j<(int)l.size();j++){
	  ans += 1.0/w[l[j]];
	  double tmp = 1.0/p[l[j]] - 1.0/w[l[j]];
	  if(abs(m-tmp)<1e-10){
	    num++;
	  }else if(m > tmp){
	    m = tmp;
	    num = 1;
	  }
	}
	ans += m;
	t = (t * num) % 100000007;
	rem -= l.size();
	t = (t * pas[rem][(int)l.size()]) % 100000007;
      }
    }
    printf("%.11lf %lld\n",ans,t);
  }
}

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

const int maxn = 1e5 + 100;

typedef long long ll;

const ll mod = 1e9 + 7;

ll dp[maxn][105][2];

char s[maxn];
int n;

int d;

ll solve(int pos, int m, int tight)
{
    if(pos == n)
    {
        return m == 0;
    }
    ll &ans = dp[pos][m][tight];
    if(ans != -1)
        return ans;
    ans = 0;
    int lim = 9;
    if(tight)
        lim = s[pos] - '0';
    for(int i = 0; i <= lim; i++)
    {
        ans = (ans + solve(pos+1, (m+i) % d, tight && (s[pos] - '0') == i) ) % mod;
    }
    return ans;
}

int main()
{
    scanf("%s",s);
    scanf("%d",&d);
    n = strlen(s);
    //reverse(s,s+n);

    memset(dp,-1,sizeof(dp));
    printf("%lld\n",(solve(0,0,1) - 1 + mod) % mod );
    return 0;
}

Measured memory_bytes: 165248