akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

// 314159
// 9*9*5C2 = 810
// 1*(1+9+9+9+9) = 37
// 2*(9+9+9+9+9) = 90
// 100
//       0 1 2 3
// dp0 0 1 0 0 0
//     1 0 0 9 18
//     2 0 0 9
//       0 1 2 3
// dp1 0 0
//     1 0 1 1 1
//     2 0 1 2 2
func solve(n string, k int) int {
	//var dp [102][4][2]int
	l := len(n)
	dp := make([][][]int, l+1)
	for i := range dp {
		dp[i] = make([][]int, 4)
		for j := range dp[i] {
			dp[i][j] = make([]int, 2)
		}
	}
	dp[0][0][0] = 1
	for i := 0; i < l; i++ {
		for j := 0; j < 4; j++ {
			for p := 0; p < 2; p++ {
				f := int(n[i] - '0')
				for d := 0; d < 10; d++ {
					ni, nj, np := i+1, j, p
					if d > 0 {
						nj++
					}
					if nj > k {
						continue
					}
					if p == 0 {
						switch {
						case d < f:
							np = 1
						case d > f:
							continue
						}
					}
					dp[ni][nj][np] += dp[i][j][p]
				}
			}
		}
	}
	debugf("%v\n", dp)

	return dp[l][k][0] + dp[l][k][1]
}

func solve2(n string, k int) int {
	for n[0] == '0' {
		if len(n) == 1 {
			return -1
		}
		n = n[1:]
	}
	ans := 0
	if k > len(n) {
		return -1
	}
	f := int(n[0] - '0')
	switch k {
	case 1:
		ans += f + (len(n)-1)*9
	case 2:
		if f > 0 {
			ans += 9 * 9 * (len(n) - 1) * (len(n) - 2) / 2
		}
		if f > 1 {
			ans += (f - 1) * (9 * (len(n) - 1))
		}
	case 3:
		if f > 0 {
			ans += 9 * 9 * 9 * (len(n) - 1) * (len(n) - 2) * (len(n) - 3) / 6
		}
		if f > 1 {
			ans += (f - 1) * (9 * 9 * (len(n) - 1) * (len(n) - 2) / 2)
		}
	}
	if k > 1 {
		ret := solve(n[1:], k-1)
		if ret == -1 {
			return -1
		}
		ans += ret
	}
	return ans
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextString()
	k := nextInt()

	ans := solve(n, k)
	//if ans == -1 {
	//		ans = 0
	//	}
	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


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

int main() {
    int w, n;
    cin >> w >> n;

    int *progression = new int[w + 1];
    for (int i = 1; i <= w; ++i) {
        progression[i] = i;
    }

    for (int i = 0; i < n; ++i) {
        int a, b;
        char comma;
        cin >> a >> comma >> b;

        int tmp = progression[a];
        progression[a] = progression[b];
        progression[b] = tmp;
    }

    for (int i = 1; i <= w; ++i) {
        cout << progression[i] << endl;
    }

    delete[] progression;
}

Measured memory_bytes: 1196
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;

int ans=0x3f3f3f3f;
string s,t;
int go(string s,string t)
{
	int ret=0;
	REP(i,s.size())
		if(s[i]!=t[i])ret++;
	return ret;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>s>>t;
	REP(i,s.size()-t.size()+1)
		ans=min(ans,go(t,s.substr(i,t.size())));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  ll a, b;
  cin >> a >> b;
  if(a > b) swap(a, b);
  ll x = a + b;
  if(x % 2) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  cout << (x >> 1) << endl;
  return 0;
}

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

int main() {
	int a[4],b,c,d;
	cin >> a[0]>>a[1]>>a[2]>>a[3]>>b>>c;
	sort(a,a+4);
	reverse(a,a+4);
	if(b>c){
		d=b;
	}else{
		d=c;
	}
	cout << a[0]+a[1]+a[2]+d << endl;
	
	return 0;
}

Measured memory_bytes: 3128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    for(int i = 0; i < n; i++) a[i] = Integer.parseInt(sc.next());
    Arrays.sort(a);
    int ans = 0;
    int temp, count;
    for(int i = 0; i < n; i++) {
      temp = a[i];
      count = 0;
      while(i < n && temp == a[i]) {
        count++;
        i++;
      }
      i--;
      ans += (count % 2);
    }
    System.out.println(ans);
  }
}


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

int main(){
  long n, a, b;
  cin >> n >> a >> b;
  if(a>b)cout << 0;
  else if(n==1 && a!=b)cout << 0;
  else if(n==1)cout << 1;
  else cout << (n-2)*(b-a)+1;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int a[n],b[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
cin>>b[i];
}
vector<int> ans;
int x=0,y=0;
for(int i=1;i<=n;i++)
{
ans.push_back(i);
}
int k=1;
do
{
bool ok=true;
for(int i=0;i<n;i++)
{
if(ans[i]!=a[i])
{
ok=false;
break;
}
}
if(ok)
{
x=k;
}
ok=true;
for(int i=0;i<n;i++)
{
if(ans[i]!=b[i])
{
ok=false;
break;
}
}
if(ok)
{
y=k;
}
k++;
}while(next_permutation(ans.begin(),ans.end()));
cout<<abs(x-y);
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
int main(void)
{
  int n,a,b;
  string s;
  cin >> n >> a >> b >> s;
  for(char c:s){
    if(c=='a' && a+b){
      cout << "Yes" << endl;
      --a;
    }else if(c=='b' && a+b && b){
      cout << "Yes" << endl;
      --b;
    }else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 896
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int a, b, c;
		for(int i=0; i<n; i++){
			a = input.nextInt();
			b = input.nextInt();
			c = input.nextInt();
			if( a*a + b*b == c*c ||  a*a + c*c == b*b || b*b + c*c == a*a)
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}
}

Measured memory_bytes: 32432
from collections import deque
H, W = map(int, input().split())
maze = [input()for _ in range(H)]


def bfs(startx: int, starty: int) -> set:
    dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    queue = deque()
    queue.appendleft((startx, starty, 0))
    reached = set()
    while queue:
        d = queue.pop()
        if d[0] == W - 1 and d[1] == H - 1:
            return d[2]
        for a in dxdy:
            x = d[0] + a[0]
            y = d[1] + a[1]
            if (x, y) not in reached and 0 <= x < W and 0 <= y < H and maze[y][x] != '#':
                reached.add((x, y))
                queue.appendleft((x, y, d[2] + 1))
    return -1


d = bfs(0, 0)
if d == -1:
    print(-1)
    exit()
cnt = 0
for c in maze:
    cnt += c.count('#')
print(H * W - cnt - d - 1)

Measured memory_bytes: 3572
#include <stdio.h>
int main(void){
    // Your code here!
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a <= b && b <= c && c >= a) printf("%d %d %d\n", a, b, c);
    else if(a <= c && c <= b && b >= a) printf("%d %d %d\n", a, c, b);
    else if(b <= a && a <= c && c >= b) printf("%d %d %d\n", b, a, c);
    else if(b <= c && c <= a && a >= b) printf("%d %d %d\n", b, c, a);
    else if(c <= a && a <= b && b >= c) printf("%d %d %d\n", c, a, b);
    else if(c <= b && b <= a && a >= c) printf("%d %d %d\n", c, b, a);
    return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int n, i, a, kinngaku, seisuu;
	double zissuu;
	
	
	cin >> n;
	
	kinngaku = 100000;
	for(i = 0; i < n; i++)
	{
		kinngaku = kinngaku * 1.05;
		
		seisuu = kinngaku / 1000;
		
		zissuu = (double)kinngaku / 1000;
		
		if(zissuu > seisuu)
		{
			seisuu = seisuu + 1;
		}
		kinngaku = seisuu * 1000;
	}
	
	cout << kinngaku << endl;
	
	return 0;	
}

Measured memory_bytes: 1160
import sys
N = int(input())
L = [i for i in map(int,input().split())]
U = L[0::2]
V = L[1::2]
L = len(U) + len(V)
res = 0
from collections import Counter
oc_E2 = 0
oc_F2 = 0
A = Counter(U)
E1 = A.most_common(1)[0][0]
oc_E1 = A.most_common(1)[0][1]
C = Counter(V)
F1 = C.most_common(1)[0][0]
oc_F1 = C.most_common(1)[0][1]
if E1 != F1:
  print(L - oc_E1 - oc_F1)
  sys.exit(0)
else:
  L2 = [el for el in U if el != E1]
  oc_E2 = 0
  if L2 != []: 
    B = Counter(L2)
    E2 = B.most_common(1)[0][0]
    oc_E2 = B.most_common(1)[0][1]
  L3 = [el for el in V if el != F1]
  oc_F2 = 0
  if L3 != []:
    D = Counter(L3)
    F2 = D.most_common(1)[0][0]
    oc_F2 = D.most_common(1)[0][1]
print(min(L-oc_E1-oc_F2,L-oc_F1-oc_E2))

Measured memory_bytes: 23736
import sys
input = sys.stdin.readline
from operator import itemgetter


def main():
    N = int(input())
    xyh = []
    for _ in range(N):
        xyh.append([int(x) for x in input().split()])

    xyh = sorted(xyh, key=itemgetter(2), reverse=True)

    for cx in range(101):
        for cy in range(101):
            x, y, h = xyh[0]
            H = h + abs(x - cx) + abs(y - cy)
            for x, y, h in xyh:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                print(cx, cy, H)
                return


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
//Contest ---Atcoder

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){

int n,k;
cin>>n>>k;
int count=0;
int arr[n];
for(int i=0;i<n;i++){
   cin>>arr[i];
    if(arr[i]>=k)
     count++;
}
cout<<count;

}

Measured memory_bytes: 640
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int dfs(vector<vector<int>>&g, vector<bool>used, int x) {
	//cout << x<<endl;
	int n = g.size();
	bool all = true;
	rep(i, n)if (used[i] == false) {
		all = false;
		break;
	}
	if (all) {
		//cout << endl;
		return 1;
	}

	int cnt = 0;
	rep(i, n) {
		if (g[x][i] == 1 && !used[i]) {
			used[i] = true;
			cnt += dfs(g, used, i);
			used[i] = false;
			
		}
	}
	//cout << "/" << x << endl;
	return cnt;


}
int main() {
	int n, m;
	cin >> n >> m;
	auto g = mat(int, n, n, -1);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		g[a - 1][b - 1] = g[b - 1][a - 1] = 1;
	}
	int cnt = 0;
	vector<bool>used(n, 0);
	used[0] = 1;
	cout << dfs(g, used, 0);



	return 0;
}





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

using Graph = vector<vector<int>>;
int N,Q;
Graph G;

void dfs(int v, int p, vector<long long> &res){
  if(p != -1)res[v] += res[p];
  for(auto e:G[v]){
    if(e == p)continue;
    dfs(e,v,res);
  }
}


int main(){
  cin >> N >> Q;
  G.assign(N,vector<int>());
  for(int i = 0; i < N-1; i++){
    int a,b; cin >> a >> b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<long long> val(N,0);
  for(int i = 0; i < Q;i++){
    int p,x; cin >> p >> x; p--;
    val[p] += x;
  }
  dfs(0,-1,val);
  for(auto v:val)cout << v << " ";
  cout << endl;

}






Measured memory_bytes: 25052
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define forr(i,k,n) for(int i=k; i<n; i++)
#define iforr(i,k,n) for(int i=n-1; i>=k; i--)
#define rep(i,n) forr(i,0,n)
#define irep(i,n) iforr(i,0,n)
#define aut(i,arr) for(auto& i:arr)
#define all(arr) arr.begin(), arr.end()
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pii>
#define f first
#define db double
#define s second
#define ll long long 
#define ull unsigned long long
#define E '\n'
#define lmax 9223372036854775807;
#define MOD 1000000007
using namespace std;
vi v;
vvi ed;
void dfs(int i)
{
	v[i]=1;
	aut(j,ed[i])
		if(!v[j])
			dfs(j);
}
void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("code.in","r",stdin);
    freopen("code.out","w",stdout);
    #endif
}

int main()
{
	//Fast_IO();
	int t;
	//cin>>t;
	t=1;
	while(t--)
	{
		int n;
		cin>>n;
		int k;
		cin>>k;
		vi arr(n);
		vi ar(n);
		rep(i,n){
			cin>>arr[i];
			cin>>ar[i];
		}
		vector<vector<ll>> dp(2,vector<ll>(k+1,-1));
		dp[0][0]=0;
		int flg=1;
		forr(i,1,n+1){
			dp[flg][0]=0;
			forr(j,1,k+1)
			{
				dp[flg][j]=dp[flg^1][j];
				if(arr[i-1]<=j)
					if(dp[flg^1][j-arr[i-1]]>=0)
						dp[flg][j]=max(dp[flg][j],ar[i-1]+dp[flg^1][j-arr[i-1]]);
			}
			flg^=1;
		}
		ll ans=-1;
		rep(i,k+1)
			ans=max(ans,dp[flg^1][i]);
		cout<<ans;
		cout<<E;
	}
	return 0;
}

Measured memory_bytes: 2560
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n-1):
    x,y = map(int,input().split())
    G[x-1].append(y-1)
    G[y-1].append(x-1)

depth = [-1]*n
prv = [-1]*n
depth[0] = 0
prv[0] = 0
stack = [[-1,0]]
while stack:
    pre,now = stack.pop()
    for nex in G[now]:
        if nex==pre:continue
        depth[nex] = depth[now] + 1
        prv[nex] = now
        stack.append([now,nex])


d_to_i = [[] for _ in range(n)]
for i in range(n):
    d_to_i[depth[i]].append(i)


dp = [[1,1] for _ in range(n)]
mod = 10**9 + 7
for d in range(n-1,-1,-1):
    for now in d_to_i[d]:
        for nex in G[now]:
            if depth[nex] < depth[now]:continue
            dp[now][0] *= (dp[nex][0] + dp[nex][1])%mod
            dp[now][1] *= dp[nex][0]%mod

print((dp[0][0]+dp[0][1])%mod)

Measured memory_bytes: 92576
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,d,cnt=0;
	cin>>a>>b;
	b=b*b;
	for (int i=0;i<a;i++)
	{
		cin>>c>>d;
		if (c*c+d*d<=b)
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int main() {
    int n;
    vector<int> a, b, c;
    ll ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        a.pb(t);
    }
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        b.pb(t);
    }
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        c.pb(t);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    for (int i = 0; i < n; i++) {
        int ta, tc;
        tc = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ta = a.end() - lower_bound(a.begin(), a.end(), b[i]);
        ans += (ll)(n-ta)*tc;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int nums[3];
  rep(i, 3) {
      cin >> nums[i];
  }
  sort(nums, nums+3);
  rep(i, 3) {
    cout << nums[i] << flush;
    if (i != 2) {
        cout << " " << flush;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3148
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
vector <pair<pair<string,int>,int> > v;
int main(){
	int n;
	cin>>n;
	for (int i=1;i<=n;i++){
		string s;
		int x;
		cin>>s>>x;
		v.push_back(make_pair(make_pair(s,-x),i)); 
	}
	sort (v.begin(),v.end());
	for (int i=0;i<n;i++) cout<<v[i].second<<"\n";
}


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

int main()
{
    int n;
    cin >> n;
    double ans = 0;
    while(n--){
        int x;
        cin >> x;
        ans += (1/(double)x);
    }

    printf("%f\n",1/ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long cub(int x) {
    return 1ll * x * x * x;
}

int main() {
    int n, k;
    cin >> n >> k;
    
    if (k & 1) {
        cout << cub(n/k) << endl;
    } else {
        cout << cub((n+k/2)/k) + cub(n/k) << endl;
    }

    return 0;
}


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

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	ll sum = 0;
	ll minusNum = 0;
	ll minV = 9223372036854775807LL;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 0) minusNum++;
		sum += abs(a[i]);		
		if (abs(a[i]) <= minV) {
			minV = abs(a[i]);
		}
	}
	if (minusNum % 2 == 0) {
		cout << sum << endl;
	}
	else {
		sum -= 2 * minV;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

const int Maxn = 100010;
const int INF = (int) 1e6;

int n;
int c1, c2, c4;

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

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a % 4 == 0) c4++;
        else if (a % 2 == 0) c2 = 1;
        else c1++;
    }

    if (c1 + c2 <= c4 + 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

typedef long long ll;
const int N = 2e5;
const ll mod = 1e9+7;
ll fact[N+100],inv[N+100];

ll bigmod(ll a,ll b)
{
	if(b==0){
		return 1;
	}
	ll x =  bigmod(a,b/2);
	x = (x*x)%mod;
	if(b%2){
		x = (x*a)%mod;
	}
	return x;
}
int main()
{
	fact[0] = inv[0] = 1;
	for(int i=1;i<=N;i++){
		fact[i] = (fact[i-1]*i)%mod;
		inv[i] = bigmod(fact[i],mod-2);
	}
	int n,k;
	scanf("%d%d",&n,&k);
	ll ans = 0;
	for(int i=0;i<=min(n-1,k);i++){
		ll t1 = (fact[n]*inv[i])%mod;
		t1 = (t1*inv[n-i])%mod;
		int m = n-i;
		ll t2 = (fact[n-1]*inv[m-1])%mod;
		t2 = (t2*inv[n-m])%mod;
		ll t3 = (t1*t2)%mod;
		ans = (ans+t3)%mod;
	}
	printf("%lld\n",ans);
}


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

using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1), pena(n+1);
    int pen = 0;
    int score = 0;

    for (int i = 0; i < m;i++){
        int x;
        string p;
        cin >> x >> p;
        x--;
        if (a[x] == 1)
            continue;
        
        if (p == "AC"){
            a[x] = 1;
            
        }else
            pena[x]++;
    }
    for (int i = 0; i < n;i++){
        score += a[i];
        if (a[i] == 1)
            pen += pena[i];
    }
        cout << score << " " << pen << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    int N, M, C;
    cin >> N >> M >> C;
    vector<long long> B(M);
    rep(i, M) cin >> B[i];
    vector<vector<ll>> A(N, vector<ll>(M));
    rep(i, N)
    {
        rep(j, M)
        {
            cin >> A[i][j];
        }
    }
    int ans = 0;
    rep(i, N)
    {
        int sum = 0;
        rep(j, M)
        {
            sum += A[i][j] * B[j];
        }
        if (sum + C > 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
    int ret = 0, sgn = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        ret = ret * 10 + ch - '0';
        ch = getchar();
    }
    return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
    if (a > 9)
        Out(a / 10);
    putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
    if (n == 0)
        return 1;
    ll res = qpow((x * x) % mod, n / 2, mod) % mod;
    if (n & 1)
        res = (res * x) % mod;
    return res % mod;
}
// 快速幂求逆元
int Fermat(int a, int p) //费马求a关于b的逆元
{
    return qpow(a, p - 2, p);
}

///扩展欧几里得
ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll g = exgcd(b, a % b, x, y);
    ll t = x;
    x = y;
    y = t - a / b * y;
    return g;
}

int m, p;
int ans, res, x;
int n, a, b;

int main()
{
    ans = 0;
    sdd(a, b);
    rep(i, 1, 10000)
    {
        if (i / 10 == b && (i * 2) / 25 == a)
        {
            ans = i;
            break;
        }
    }
    if(ans==0)
    ans=-1;
    pd(ans);
    return 0;
}


Measured memory_bytes: 256
def is_unique(seq):
    return len(seq) == len(set(seq))

N = int(input())
word_list = []
flag = True
word = input()
word_list.append(word)
for i in range(1,N):
    word = input()
    check = word_list[i-1]
    if check[-1] == word[0]:
        word_list.append(word)
        if is_unique(word_list) == False:
            flag = False
            break
    else:
        flag = False
        break
if flag == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b ? "true" : "false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vector<bool> v) {
	string res;
	for(int i = 0; i < (int) v.size(); i++)
		res += char('0' + v[i]);
	return res;
}
 
template<size_t S> string to_string(bitset<S> b) {
	string res;
	for(int i = 0; i < S; i++)
		res += char('0' + b[i]);
	return res;
}

template<class T> string to_string(T v) {
    bool f = 1;
    string res;
    for(auto& x : v) {
		if(!f)
			res += ' ';
		f = 0;
		res += to_string(x);
	}
    return res;
}
 
void DBG() {
	cerr << "]" << endl;
}

template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}

#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};

void solve() {
	string s;
	cin >> s;
	int n = s.size();
	if(s[n - 1] == 's')
		s += "es";
	else s += "s";
	cout << s;	
}	
 
int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
 	
	int t = 1;
	//cin >> t;
	for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 3624
#include<iostream> //cinなど
#include<string> //文字列
#include<algorithm> //sort など
#include<math.h> //paw(冪乗など)
#include<set> // 集合
#include<map> //写像
#include<stdio.h> //printf
#include<stack>

using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c;
if((a+b==c)||(a+c==b)||(b+c==a)){
  cout<<"Yes"<<endl;
}else{
  cout<<"No"<<endl;
}
return 0;
}


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

int main() {
  int N, x = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    x += r - l + 1;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=250;
    const ll oo=1e12;
    int n,m;
    ll a[N],tot;
    struct Dinic{
        ll G[N][N],dis[N];
        int S,T;
    	void build(){
            memset(G,0,sizeof G);
            cin>>n;for(int i=1;i<=n;++i)cin>>a[i],tot+=max(a[i],0ll);
    		S=n+1;T=n+2;
            for(int i=1;i<=n;++i)for(int j=i+1;j<=n;++j)if(j%i==0)G[i][j]=oo;
            for(int i=1;i<=n;++i){
    			if(a[i]<=0)G[S][i]=-a[i];
    			else G[i][T]=a[i];
    		}
    		n+=2;
        }
        bool BFS(){
            queue<int> Q;
            memset(dis,-1,sizeof dis);
            dis[S]=0;
            Q.push(S);
            while(!Q.empty()){
                int u=Q.front();Q.pop();
                if(u==T)return 1;
                for(int i=1;i<=n;++i){
                    if(~dis[i]||G[u][i]<=0)continue;
                    dis[i]=dis[u]+1;
                    Q.push(i);
                }
            }
            return 0;
        }
        ll dfs(int u,ll low){
            ll a=0;
            if(u==T)return low;
            for(int i=1;i<=n;++i)
                if(G[u][i]>0&&dis[i]==dis[u]+1){
                    a=dfs(i,min(low,G[u][i]));
                    G[u][i]-=a;
                    G[i][u]+=a;
                    if(a)return a;
                }
            return 0;
        }
    	ll dinic(){
            ll ans=0;
    		while(BFS())for(ll t;t=dfs(S,oo);ans+=t);
    		return ans;
        }
    }D;
    int main(){
        D.build();
        printf("%lld\n",tot-D.dinic());
        return 0;
    }

Measured memory_bytes: 768
package main

import (
	"fmt"
)

func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)

	sum := 0
	for a := 1; a <= n; a++ {
		for b := 1; b <= n; b++ {
			for c := 1; c <= n; c++ {
				sum += GCD(GCD(a, b), c)
			}
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 1776
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		if(4*a*b<(c-a-b)*(c-a-b)) {
			if(c-b-a<=0) {
				System.out.println("No");
			}else {
			System.out.println("Yes");}
		}else {
			System.out.println("No");
		}
}}


Measured memory_bytes: 22736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int num = 0;
  for (int i = 0; i < N; ++i){
    int l, r;
    cin >> l >> r;
    num += r - l + 1;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> field(H, vector<char>(W));
    rep(i, H) {
        rep(j, W)
            cin >> field[i][j];
    }

    vector<vector<int>> ans(H, vector<int>(W));
    int a = 0;
    vector<bool> is_all_dot_v(H, true);
    int first_not_dots_row = -1;
    rep(i, H) {
        bool is_all_dot = true;
        rep(j, W) {
            if (field[i][j] == '#') {
                if (first_not_dots_row == -1) first_not_dots_row = i;
                is_all_dot_v[i] = false;
            }
        }
    }

    rep(i, H) {
        if (is_all_dot_v[i] == true) continue;
        rep(j, W) {
            
            if (field[i][j] == '#') {
                a++;
            }
            ans[i][j] = a;
        }
    }
    rep(i, H) {
        rep(j, W) {
            if (field[i][j] == '#') break;
            ans[i][j]++;
        }
    }


    rep(i, first_not_dots_row) {
        rep(j, W) {
            ans[i][j] = ans[first_not_dots_row][j];
        }
    }

    REP(i, first_not_dots_row, H) {
        if (is_all_dot_v[i] == false) continue;
        rep(j, W) {
            ans[i][j] = ans[i - 1][j];
        }
    }

    rep(i, H) {
        rep(j, W) {
            printf("%d ", ans[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1280
#500円通貨1枚につき1000
#5円通貨1枚につき5
#高橋君はx円持ってる
#利用できる通貨は500円,100円,10円,5円,1円
#入力 1024

x=input()
x1=int(x) 

#まず入力を500で何回われるかを数えその回数で割り,残った値を変数に格納
r=int(x1/500)
x2=x1%500

#同じ操作を5でおこなう
r1=int(x2/5)
x3=x2%5

sam=(r*1000)+(r1*5)

print(sam)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll  long long int
#define fr(i,n) for(ll i=0; i<n; i++)
#define fre(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define pii pair<ll,ll>
#define ve vector
#define piii pair<pii, ll>
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

ll power(ll x, ll n, ll m)
{
    if(n==0)
        return 1;
    if(n==1)
        return x;
    x%=m;
    if(n%2)
        return (x*(power((x*x)%m, n/2, m)%m))%m;
    return power((x*x)%m, n/2, m)%m;
}

int main(){
  
    FAST;
    ll n;
    cin>>n;

    double p[n], dp[n][n+1], ans=0;
    for(int i=0; i<n; i++){
      cin>>p[i];
    }

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

    for(int i=1; i<n; i++){
      dp[i][0] = dp[i-1][0]*(1-p[i]);
      for(int j=1; j<=n; j++){
          dp[i][j] += dp[i-1][j]*(1-p[i]);
          dp[i][j] += dp[i-1][j-1]*p[i];
      }
    }

    for(int j=(n+1)/2; j<=n; j++)
      ans += dp[n-1][j];
    cout<<fixed<<setprecision(10)<<ans<<endl;

}

Measured memory_bytes: 74128
<?php
list($n, $k) = explode(" ", trim(fgets(STDIN)));
$sum = 0;
for($i = 1; $i <= $n; $i++){
    $ii = $i;
    $rate = 1 / $n;
    while($ii < $k){
        $rate /= 2;
        $ii *= 2;
    }
    $sum += $rate;
}
printf("%.16f", $sum);

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	int n; cin >> n;
	vector<int> v;
	vector<string> s(n);
	rep(i,0,n){
		cin >> s[i];
		rep(j,0,n) if(s[i][j]=='o') v.push_back(i+1);
	}

	random_device rd;
	mt19937 eng(rd());
	vector<int> cnt(n);
	rep(i,0,200){
		cout << v[eng()%v.size()] << endl;
		int in; cin >> in;
		++cnt[--in];
	}

	vector<pii> ps(n);
	rep(i,0,n){
		ps[i].first=cnt[i];
		ps[i].second=i;
	}
	sort(ps.rbegin(),ps.rend());
	vector<int> w;
	rep(i,0,n){
		rep(j,0,n){
			if(s[i][ps[j].second]=='o'){
				rep(k,0,ps[j].first*2) w.push_back(i+1);
			}else if(s[i][ps[j].second]=='-'){
				rep(k,0,ps[j].first/2) w.push_back(i+1);
			}
		}
	}

	rep(i,0,800){
		cout << w[eng()%w.size()] << endl;
		int in; cin >> in;
	}
}

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

Measured memory_bytes: 1328
fun main(args : Array<String>){

    var array1 = readLine()?.split(" ")?.map(String::toInt)
    var array2 = readLine()?.split(" ")?.map(String::toInt)

    var ret = 0
    if( array1 != null && array2 != null ){
        if( array1[0] != array2[0] ){
            ret = 1
        }
    }

    print(ret)


}

Measured memory_bytes: 37876
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int main() {
	ll N;
	cin >> N;

	ll cnt = N;

	for (ll i = 0; i <= N; i++)
	{
		ll t = i;
		ll c = 0;
		while (t > 0)
		{
			c += t % 6;
			t /= 6;
		}
		t = N - i;
		while (t > 0)
		{
			c += t % 9;
			t /= 9;
		}
		if (c < cnt)cnt = c;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
def solve():
    N, M = map(int, input().split())
    height = [int(i) for i in input().split()]
    neighbor = [[-1] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        neighbor[A - 1].append(height[B - 1])
        neighbor[B - 1].append(height[A - 1])

    func = lambda i: 1 if height[i] > max(neighbor[i]) else 0
    count = sum([func(i) for i in range(N)])
    print(count)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 26880
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();
		sc = null;
		if((a<c && c<b) || (b<c && c<a)) System.out.println("Yes"); 
		else System.out.println("No");
	}
}


Measured memory_bytes: 22612
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  width := nextInt()
  height := nextInt()
  area := width * height
  perimeter := width * 2 + height * 2 
  fmt.Println(strconv.Itoa(area) + " " + strconv.Itoa(perimeter))
}


func nextInt() (int) {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}


Measured memory_bytes: 1124
// Grading.cc
// あなたの課題は、あるクラスの数学の成績を付けるプログラムを作成することです。
// プログラムは複数の学生のテストの点数を読み込みます。
// テストの点数は、中間試験の点数 m、期末試験の点数 f、再試験の点数 r で構成されています。
// 中間試験と期末試験は 50 点満点（m, f ≤ 50）、再試験は 100 点満点 （r ≤ 100）です。
// 試験を受けていない場合は点数を -1 とします。
// 以下の手順で成績が付けられます：
//
// ・中間試験、期末試験のいずれかを欠席した場合成績は F。
// ・中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
// ・中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。
// ・中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。
// ・中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 
//   ただし、再試験の点数が 50 以上ならば成績は C。
// ・中間試験と期末試験の合計点数が 30 未満ならば成績は F。
// 【入力】
// 複数のデータセットが入力として与えられます。各データセットでは、
// 空白で区切られた m、f、r が 1 行に与えられます。
// m、f、r がすべて -1 のとき入力の終わりとします。
// データセットの数（生徒の数）は 50 を超えません。
// 【出力】
// 各データセットについて、成績（A、B、C、D、または F）を１行に出力して下さい。
// 【例】
// 入力：
// 40 42 -1
// 20 30 -1
// 0 2 -1
// -1 -1 -1
// 出力：
// A
// C
// F
#include<iostream>
using namespace std;

int main( void) {
  int m, f, r;
  int sum;
  char grade;

  while( true) {
    cin >> m >> f >> r;

    if ( m == -1 && f == -1 && r == -1) break;

    sum = m + f;

    if ( m == -1 || f == -1) grade = 'F';
    else if ( sum >= 80) grade = 'A';
    else if ( 65 <= sum && sum < 80) grade = 'B';
    else if ( 50 <= sum && sum < 65) grade = 'C';
    else if ( ( 30 <= sum && sum < 50) && r >= 50) grade = 'C';
    else if ( ( 30 <= sum && sum < 50) && r < 50) grade = 'D';
    else if ( sum < 30) grade = 'F';

    cout << grade << endl;
  }

  return 0;
}


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

using namespace std;

int n, a[100007];

int main(){
	scanf("%d", &n);
	int mx = 0;
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		mx = max(mx, a[i]);
	}
	int nx = INT_MAX, b = 0;
	for(int i = 1; i <= n; ++i){
		int A = mx / 2;
		int B = mx / 2;
		if(mx % 2 == 1) B = A + 1;
		if(a[i] <= A){
			if(A - a[i] <= nx){
				nx = A - a[i];
				b = a[i];
			}
		}
		else{
			if(a[i] - B <= nx){
				nx = a[i] - B;
				b = a[i];
			}
		}
	}
	cout << mx << ' ' << b << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define mp map<int,int>
#define pp make_pair
#define endl "\n"
#define vi vector<int>
#define vbl vector<bool>
#define ll long long 
#define clock high_resolution_clock::now()

// auto duration = duration_cast<microseconds>(stop - start);  cout<<duration.count();

const int INF = 1e9+5;
const int mod = 1e9 + 7;

using namespace std;
using namespace std::chrono;

const int mx = 3005;

double dp[mx][mx];
double p[mx];

int main(){
    int n;
    cin>>n;
    
    for(int i=0; i<n; i++)cin>>p[i];
    dp[0][0] = 1.0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=i; j++){
            if(j)dp[i][j]+=p[i-1]*dp[i-1][j-1];
            dp[i][j]+=(1-p[i-1])*(dp[i-1][j]);
            // cout<<dp[i][j]<<" ";
        }
    }
    double ans = 0;
    for(int i=0; i<=n; i++)if(i>n-i)ans+=dp[n][i];
    printf("%.12f\n", ans);
    
    
    

	return 0;
}
	
	
 

Measured memory_bytes: 49908
/*
   Creator - Glitched
   Yeet!!
*/
#include "bits/stdc++.h"
using namespace std;

#define testcases ll T;cin>>T;while(T--)
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)

int main()
{
  ll n = 5;
  loop(i,0,n){
    ll x;
    cin>>x;
    if(x == 0)
      cout<<i+1;
  }
}

Measured memory_bytes: 3636
import java.io.*;
import java.math.BigDecimal;
import java.util.*;
public class Main {
	static BufferedReader br;
	static PrintWriter pw;
	static StringTokenizer st;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		solve();
		exitImmediately();
	}

	public static void solve() throws IOException {
		int n = Integer.parseInt(br.readLine());
		HashMap<State, Integer> dp = new HashMap<State, Integer>();
		while(n-- > 0) {
			long x = new BigDecimal(readToken()).multiply(BigDecimal.TEN.pow(9)).longValueExact();
			int t = -9;
			int f = -9;
			while(x%2==0) {
				x /= 2;
				t++;
			}
			while(x%5==0) {
				x /= 5;
				f++;
			}
			State key = new State(t, f);
			dp.put(key, dp.getOrDefault(key, 0) + 1);
		}
		long ret = 0;
		for(State a: dp.keySet()) {
			for(State b: dp.keySet()) {
				if(a.equals(b)) {
					if(a.a >= 0 && a.b >= 0) {
						long inc = dp.get(a);
						ret += inc*(inc-1)/2;
					}
					break;
				}
				else {
					if(a.a+b.a >= 0 && a.b+b.b >= 0) {
						ret += dp.get(a) * (long) dp.get(b);
					}
				}
			}
		}
		pw.println(ret);
	}

	static class State {
		public int a, b;

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + a;
			result = prime * result + b;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			State other = (State) obj;
			if (a != other.a)
				return false;
			if (b != other.b)
				return false;
			return true;
		}

		public State(int a, int b) {
			super();
			this.a = a;
			this.b = b;
		}
		
	}
	
	public static void exitImmediately() {
		pw.close();
		System.exit(0);
	}
	public static int readInt() throws IOException {
		return Integer.parseInt(readToken());
	}
	public static long readLong() throws IOException {
		return Long.parseLong(readToken());
	}
	public static double readDouble() throws IOException {
		return Double.parseDouble(readToken());
	}
	public static String readLine() throws IOException {
		String s = br.readLine();
		if(s == null) exitImmediately();
		st = null;
		return s;
	}
	public static String readToken() throws IOException {
		while(st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(readLine().trim());
		}
		return st.nextToken();
	}
}


Measured memory_bytes: 66564
from itertools import permutations as perm
from copy import deepcopy as copy


def inpl():
    return tuple(map(int, input().split()))


def dfs(XY, flag):
    # print(len(XY), XY, sum(f.count(True) for f in flag))
    if len(XY) == 8:
        # print("here")
        return XY

    for i in range(8*8):
        x = i // 8
        y = i % 8
        if flag[x][y] is False:
            continue
        f, new_f = toFalse(x, y, flag, XY)
        if f is False:
            continue
        tmp = copy(XY)
        tmp.add((x, y))
        # print(tmp)
        ret = dfs(tmp, new_f)
        if ret is None:
            continue
        else:
            return ret
    return None


def toFalse(x, y, f, XY):
    flag = copy(f)
    ddd = [[1, 1], [-1, -1], [1, -1], [-1, 1]]
    for i in range(8):
        # print(x, y, i, flag)
        if (i, y) in XY or (x, i) in XY:
            return False, flag
        else:
            flag[i][y] = False
            flag[x][i] = False

        if i == 0:
            continue
        for dx, dy in ddd:
            if not(0 <= x + i*dx < 8 and 0 <= y + i*dy < 8):
                continue
            elif (x+i*dx, y+i*dy) in XY:
                return False, flag
            else:
                flag[x+i*dx][y+i*dy] = False
    return True, flag


N = int(input())
XY = [inpl() for _ in range(N)]


flag = [[True for _ in range(8)] for i in range(8)]
# print(flag)
for x, y in XY:
    f, flag = toFalse(x, y, flag, set())

ans = dfs(set(XY), flag)

# print(ans)
chess = [["."]*8 for i in range(8)]
for x, y in ans:
    chess[x][y] = "Q"
for c in chess:
    print("".join(c))



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

using ld = long double;
using point = complex<ld>;

int main() {
    int n; cin >> n;
    vector<point> ps;
    for(int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        if(x == 0 && y == 0) continue;
        ps.emplace_back(x, y);
    }
    n = ps.size();
    sort(ps.begin(), ps.end(),
         [] (auto const& a, auto const& b) { return arg(a) < arg(b); });

    ld ans = 0;
    for(int i = 0; i < n; ++i) {
        point p = ps[i];
        ans = max(ans, abs(p));
        for(int j = 1; j < n; ++j) {
            auto const v = ps[(i + j) % n];
            if(arg(v / ps[i]) < 0) break;
            p += v;
            ans = max(ans, abs(p));
        }
    }

    cout << fixed << setprecision(12) << ans << endl;
}


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

int main(){
    set<long long> s;
    int n;
    cin >> n;
    long long a;
    for(int i=0;i<n;i++){
        cin >> a;
        auto it = s.find(a);
        if(it==s.end())s.insert(a);
        else s.erase(it);
    }
    cout << s.size() << endl;
}

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

#define int long long
#define ff first
#define ss second
#define loop(i,k,n) for(int i=k;i<n;++i)
#define rloop(i,n,k) for(int i=n;i>=k;i--)
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpii vector<pair<int,int> >
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mci map<char,int>  
#define pii pair<int,int>
#define pdd pair<double,double>
#define deb(x) cout<<#x<<" "<<x<<endl;
#define mp make_pair
#define pb push_back
#define mod 1000000007  
#define endl "\n"
#define inf 1e18
#define sp(x,y) fixed<<setprecision(y)<<x

void get_it_done(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
int gcd(int a, int b){ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void swap(int &a,int &b){
	a^=b;b^=a;a^=b;
}
const int N = 1e5+5;
int dp[N];
int n;
int height[N];

int solve(int i){
    if(dp[i]!=-1) return dp[i];
    if(i>=n){
        return inf;
    }
    if(i==(n-1)){
        return 0;
    }
    int ans = inf;
    ans = min(abs(height[i]-height[i+1])+solve(i+1),abs(height[i]-height[i+2])+solve(i+2));
    return dp[i] = ans;
}

int32_t main(){
	get_it_done();
    int t=1;
    // cin >> t;
    while (t--){
        cin>>n;
        loop(i,0,n) cin>>height[i];
        memset(dp,-1,sizeof(dp));
        cout<<solve(0)<<endl;

    }
}


Measured memory_bytes: 3328
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    a, b, n = map(int, input().split())

    def main(x):
        return (a * x) // b - a * (x // b)

    p, mod = divmod(n, b)
    if mod == 0:
        print(main(n - 1))
    else:
        if p==0:
            print(main(n))
        else:
            ans = main(p * b - 1)
            print(max(main(n), ans))


resolve()

Measured memory_bytes: 61900
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		long ans = 1;

		for(long k=M/N;k>=1;k--){
				if(M%k==0){
					ans = k;
					break;
				}
			
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 23124
n=int(input())
a=list(map(int,input().split()))
ans=0
def check_all():
    global a,n
    for i in range(n):
        if a[i]%2!=0:
            return False
    return True
while check_all():
    ans+=1
    for i in range(n):
        a[i]//=2
print(ans)


Measured memory_bytes: 38768