akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct edge {
  int a;
  int b;
  int weight;
};
int *ufp, *ufr;
struct edge *ed;

void downheap(int, int);
int UF_find(int);
void UF_union(int, int);
int Kruskal(int, int);

int main(void)
{
  int i, j, v, e, s, t, w, cost;
  scanf("%d %d", &v, &e);
  ufp = (int*)malloc(sizeof(int) * v);
  ufr = (int*)malloc(sizeof(int) * v);
  ed = (struct edge*)malloc(sizeof(struct edge) * e);
  for (i = 0; i < v; i++) {
    ufp[i] = i;
    ufr[i] = 0;
  }
  for (i = 0; i < e; i++) {
    scanf("%d %d %d", &s, &t, &w);
    ed[i].weight = w;
    ed[i].a = s;
    ed[i].b = t;
  }
  cost = Kruskal(v, e);
  printf("%d\n", cost);
  free(ufp);
  free(ufr);
  free(ed);
}

void downheap(int left, int right)
{
  int parent, child;
  struct edge root = ed[left];
  for (parent = left; parent < (right + 1) / 2; parent = child) {
    int l = 2 * parent + 1;
    if (ed[l].weight > ed[l + 1].weight && l + 1 <= right) child = l+1;
    else child = l;
    if (root.weight <= ed[child].weight) break;
    ed[parent] = ed[child];
  }
  ed[parent] = root;
}

int UF_find(int a)
{
  if (ufp[a] == a) return a;
  else {
    ufp[a] = UF_find(ufp[a]);
    return ufp[a];
  }
}

void UF_union(int a, int b)
{
  if (ufr[a] < ufr[b]) ufp[a] = b;
  else {
    ufp[b] = a;
    if (ufr[a] == ufr[b]) ufr[a]++;
  }
}

int Kruskal(int size, int esize)
{
  int i, selected = 0, cost = 0;
  for (i = esize / 2 - 1; i >= 0; i--) downheap(i, esize - 1);
  while (selected < size - 1) {
    int ea = UF_find(ed[0].a), eb = UF_find(ed[0].b);
    struct edge tmp = ed[0];
    if (ea != eb) {
      UF_union(ea, eb);
      cost += ed[0].weight;
      selected++;
    }
    ed[0] = ed[esize - 1];
    ed[esize - 1] = tmp;
    esize--;
    if (esize) downheap(0, esize - 1);
  }
  return cost;
}


Measured memory_bytes: 2932
N, A, B, C, D = map(int,input().split())
A = A - 1
B = B - 1
C = C - 1
D = D - 1
S = input()
if "##" in S[A:C+1] or "##" in S[B:D+1]:
    print("No")
    exit()

if  D < C and (S[D-1] == "#" or S[D+1] == "#"):
    if "..." in S[B-1:D+1]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Measured memory_bytes: 3572
import math
import time
from collections import defaultdict,deque,Counter
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
from queue import PriorityQueue 
import sys
n,d=map(int,stdin.readline().split())
d=d*d
ans=0
for _ in range(n):
    x,y=map(int,stdin.readline().split())
    if((x*x)+(y*y) <=d):
        ans+=1
print(ans)

Measured memory_bytes: 70504
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int data[100],cnt=0,n;
  cin >> n;
  for(int i=0;i<n;i++) cin >> data[i];
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(data[j]<data[j-1]){
	swap(data[j],data[j-1]);
	cnt++;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << (i!=0?" ":"") << data[i];
  }
  cout << endl << cnt << endl;
  return 0;
  }



Measured memory_bytes: 3112
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  int money;
  cin >> n >> money;

  //10000円と5000円の枚数を決め打ちすれば1000円の枚数は自動的に決まる
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n - i; j++){
      if(i * 10000 + j * 5000 + (n - i - j) * 1000 == money){
	printf("%d %d %d\n", i, j, n - i - j);
	return(0);
      }
    }
  }
  printf("-1 -1 -1\n");
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<string> S[11]; 
int main(){
	int N; cin >> N; 
	S[1].push_back("a"); 
	for(int i = 1; i < 10; i++){
		for(int j = 0; j < S[i].size(); j++){
			int mx = 0; 
			for(int k = 0; k < i; k++){
				mx = max(mx, S[i].at(j).at(k) - 'a'); 
			}
			for(int k = 0; k <= mx + 1; k++){
				string tmp = S[i].at(j); 
				tmp += (char) 'a' + k; 
				S[i+1].push_back(tmp); 
			}
		}
	}
	sort(S[N].begin(), S[N].end()); 
	for(int i = 0; i < S[N].size(); i++){
		cout << S[N].at(i) << "\n"; 
	}
}

Measured memory_bytes: 11380
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			long N = scan.nextLong();
			long M = scan.nextLong();
			
			if(N==1) {
				if(M==1)System.out.println(1);
				if(M==2)System.out.println(0);
				if(M>=3)System.out.println(M-2);
			}else if(N==2) {
				System.out.println(0);
			}else if(N>=3) {
				if(M==1)System.out.println(N-2);
				if(M==2)System.out.println(0);
				if(M>=3)System.out.println((M-2)*(N-2));
			}
			
		}
		
		
	}
		

}


Measured memory_bytes: 21844
S = input()
 
befM = False
aftM = False
 
for i in range(1, 13):
    num = str(i).zfill(2)
    if num == S[0:2]:
        befM = True
    if num == S[2:4]:
        aftM = True
 
ans = "NA"
if befM and aftM:                  
    ans = "AMBIGUOUS"
elif aftM:         
    ans = "YYMM"
elif befM:         
    ans = "MMYY"

print(ans)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define H_MAX 80
#define W_MAX 80
#define VAL_MAX 80

int A[H_MAX][W_MAX], B[H_MAX][W_MAX];
char table[H_MAX][W_MAX][(H_MAX+W_MAX)*VAL_MAX];

void solv()
{
	int H, W; scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			scanf("%d", A[i] + j);
		}
	}

	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			scanf("%d", B[i] + j);
		}
	}

	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			fill(table[i][j], table[i][j] + (H_MAX + W_MAX)*VAL_MAX, 0);
		}
	}
	table[0][0][abs(A[0][0] - B[0][0])] = 1;
	for (int h = 0; h < H; h++){
		for (int w = 0; w < W; w++){
			for (int i = 0; i < (H_MAX + W_MAX)*VAL_MAX; i++){
				int val = abs(A[h][w] - B[h][w]);
				if (h - 1 >= 0){
					if (abs(i - val) < (H_MAX + W_MAX)*VAL_MAX){
						if (1 == table[h - 1][w][abs(i - val)]){
							table[h][w][i] = 1;
						}
					}
					if (abs(i + val) < (H_MAX + W_MAX)*VAL_MAX){
						if (1 == table[h - 1][w][abs(i + val)]){
							table[h][w][i] = 1;
						}
					}
				}
				if (w - 1 >= 0){
					if (abs(i - val) < (H_MAX + W_MAX)*VAL_MAX){
						if (1 == table[h][w - 1][abs(i - val)]){
							table[h][w][i] = 1;
						}
					}
					if (abs(i + val) < (H_MAX + W_MAX)*VAL_MAX){
						if (1 == table[h][w - 1][abs(i + val)]){
							table[h][w][i] = 1;
						}
					}
				}
			}
		}
	}

	int ret = (H_MAX + W_MAX)*VAL_MAX;
	for (int i = 0; i < (H_MAX + W_MAX)*VAL_MAX; i++){
		if (1 == table[H - 1][W - 1][i]){
			ret = min(ret, i);
		}
	}

	printf("%d", ret);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

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

string s;

ll dp[2][2020]{};

int main()
{


    cin>>s;
    int n = s.length();

    dp[0][s[0]-'0'] = 1;
    ll ans = 0 ;
    for(int i = 1 ; i<n ; i++){

        for(int j = 0 ; j<=2018 ; j++){

            int nxt = j*10 + s[i]-'0'; nxt%=2019;
            dp[1][nxt] += dp[0][j];
        }
        ans += dp[1][0];
        memcpy(dp[0] , dp[1] , sizeof(dp[1]));
        dp[0][s[i]-'0']++;
        memset(dp[1] , 0 , sizeof(dp[1]));


    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3716
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string result = "AC";
            int count = 0;
            //条件1:頭文字が"A"
            if (S.Substring(0, 1) == "A" && S.Contains("C"))
            {
                for (int i = 1; i < S.Length; i++)
                {
                    char tmp = Convert.ToChar(S.Substring(i,1));
                    if (!char.IsLower(tmp))
                    {
                        if (tmp == 'C' && 2 <= i && i <= S.Length - 2)
                        {
                            count++;
                        }
                        else
                        {
                            Console.WriteLine("WA");
                            return;
                        }
                    }
                }
                if(count == 1)
                {
                    Console.WriteLine("AC");
                }
                else
                {
                    Console.WriteLine("WA");
                }
            }
            else
            {
                Console.WriteLine("WA");
            }
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


Measured memory_bytes: 25832
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x1: u32,
        x2: u32,
        x3: u32,
        x4: u32,
        x5: u32,
    };

    if x1 == 0 {
        println!(1);
    } else if x2 == 0 {
        println!(2);
    } else if x3 == 0 {
        println!(3);
    } else if x4 == 0 {
        println!(4);
    } else if x5 == 0 {
        println!(5);
    }
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;


int main(){
    int N,p[21000],t;
    cin>>N;

    for(int i=0;i<N;i++){
        cin>>t;
        t--;
        p[t]=i+1;
    } 
    /*for(int i=1;i<N;i++){
        p[i]+=p[0];
    }*/

    ll a[21000],b[21000];
    b[0]=1000000000; a[0]=p[0];

    for(int i=1;i<N;i++){
        ll x=1000000000+p[i];
        if(p[i]>p[i-1]){
            b[i]=b[i-1]-1;
            a[i]=a[i-1]+1+p[i]-p[i-1];
        }else{
            a[i]=a[i-1]+1;
            b[i]=b[i-1]-1-(p[i-1]-p[i]);
        }
    }
    for(int i=0;i<N;i++){
        if(i) cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    for(int i=0;i<N;i++){
        if(i) cout<<" ";
        cout<<b[i];
    }
    cout<<endl;
}


Measured memory_bytes: 1024
using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for(int i = r; i >= l; --i)
#define fr(i, l, r) for(int i = l; i < r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,k,d,fn;
    cin>>x>>k>>d;
    ll st=x/d;

    
    if(abs(st)>=k)
    {
        if(x<0)
        {
            fn=abs(x+k*d);
        }
        else
        {
            fn=x-k*d;
        }
    }
    else
    {
        if(x>0){
        ll st1=k-abs(st);

        if(st1%2==0)
        {
           fn=x-st*d;   
        }
        else
        {
            fn=abs(x-st*d-d);
        }
        }
        else
        {
            ll st1=k-abs(st);
            if(st1%2==0)
            {
                fn=abs(x+abs(st)*d);
            }
            else
            {
                fn=abs(x+abs(st)*d+d);
            }
        }
    }
    cout<<fn<<endl;
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int s = sc.nextInt();
		int w = sc.nextInt();
		
		if(s > w)
		{
			System.out.println("safe");
		}
		else
		{
			System.out.println("unsafe");
		}
		
		sc.close();

	}

}

Measured memory_bytes: 35788
#include<bits/stdc++.h>
using namespace std;
int n,m,b[100001],x,y;
bool a[100001];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		a[i]=true;
	}
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		if(b[x]<=b[y])
			a[x]=false;
		if(b[y]<=b[x])
			a[y]=false;
	}
	x=0;
	for(int i=1;i<=n;i++)
		if(a[i])
			x++;
	cout<<x;
	return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
int main(){
    cout << fixed << setprecision(20);
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double rad=abs((h+m/60)/12-m/60)*M_PI*2;
    double ans=sqrt(a*a+b*b-2*a*b*cos(rad));
    cout<<ans<<endl;
}

Measured memory_bytes: 4092
#include<stdio.h>

int main(void)
{
   int n, l, i, b;
   double a;

   scanf("%d%d",&n,&l);

   a=((double)n/2)*(n+1);
   b=a;
   if(l+n-1<0)
      printf("%d\n",(l*(n-1)+b-2*n+1));
   else if(l>0)
      printf("%d\n",(l*(n-1)+b-n));
   else
      printf("%d\n",(l*n+b-n));
   return 0;
}

Measured memory_bytes: 128
s = input()
m =0
count =0
for i in s:
    if i in 'A':
        count += 1
    elif i in'C':
        count += 1
    elif i in 'G':
        count += 1
    elif i in 'T':
        count += 1
    else:
        count = 0
    m =max(m,count)
print(m)

Measured memory_bytes: 3060
a, b = map(int, input().split())
import math
import fractions

g = fractions.gcd(a, b)
gs = [1]

f = 2
if g % 2 == 0:
  gs.append(2)
while g % 2 == 0:
  g = g // 2
f = 3
while f * f <= g:
  if g % f == 0:
    gs.append(f)
  while g % f == 0:
    g = g // f
  f += 2
if g != 1:
  gs.append(g)
print(len(gs))

Measured memory_bytes: 5048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
typedef pair<double, long long> pair_t;
bool comp(const pair_t& a, const pair_t& b) {
	if (a.first == b.first)return  a.second > b.second;
	else {
		return a.first > b.first;
	}
}

int main() {
	ll n,q,cnt=0;
	string s;
	cin >> n >> q;
	cin >> s;
	vector<ll>cntS(n+2,0);
	for (ll i = 1; i <= n;i++) {
		if (s[i-1] == 'A' && s[i] == 'C')cnt++;
		cntS[i+1] = cnt;
	}
	ll l, r;
	for (ll i = 0; i < q; i++) {
		cin >> l >> r;
		cout << cntS[r] - cntS[l] << endl;
	}
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = unsigned long long;
using namespace std;
 
int main(){
    ll x;cin>>x;
    ll a=100;
    ll i=0;
    while(a<x){
        a+=a/100;
        i++;
    }
    cout<<i<<endl;
}

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

int main() {
  char s;
  cin >> s;
  bool OK = false;
  char ch[30];
  rep(i,30) ch[i]='a'+ i;
  rep(i,30){
    if(s==ch[i]) OK = true;
  }
  if(OK) puts("a");
  else puts("A");
  return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int N; ll A[100001], cnt, sum, minA = 1e10;
int main() {
  scanf("%d", &N);
  for(int i = 1; i <= N; ++i) {
    scanf("%ld", &A[i]);
    if(A[i] < 0) A[i] *= -1, ++cnt;
    minA = min(minA, A[i]);
    sum += A[i];
  }
  printf("%ld\n", cnt%2==0?sum:sum-minA*2);
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal[] a = Console.ReadLine().Split(" ").Select(x => decimal.Parse(x)).ToArray();
            decimal res = 0;
            for (int i = 1; i < a.Length + 1; i++)
            {
                if (a[i-1] != i) { res = i; }
            }
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 28012
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

int h, w;
bool in(int y, int x) { return 0 < y && y < h - 1 && 0 < x && x < w - 1; }

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

    int n;
    cin >> h >> w >> n;
    set<P> st;
    map<P, int> cnt;
    vector<int> num(10, 0);
    num[0] = (h - 2) * (w - 2);
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        rep(j, 3) rep(k, 3)
        {
            int y = a + dy[j], x = b + dx[k];
            if (!in(y, x))
                continue;
            int now = cnt[P(y, x)];
            num[now]--;
            cnt[P(y, x)]++;
            num[now + 1]++;
        }
    }
    rep(i, 10) cout << num[i] << endl;
}

Measured memory_bytes: 56576
#include<stdio.h>
int main(void)
{
	int n, m,a[1002],i,j=1,temp;
	scanf("%d %d",&n,&m);
	for (i = 0; i < n; i++) {
		scanf("%d",&a[i]);
	}
	
	while (j != m+1) {
		i = 0;
		while (i != n-1) {
			if (a[i] % j > a[i + 1] % j) {
				temp = a[i];
				a[i] = a[i + 1];
				a[i + 1] = temp;
			}
			i++;
		}
		j++;
	}
	for (i = 0; i < n; i++)printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxd=1000000007,N=100000;
const double pi=acos(-1.0);
typedef long long ll;
int n,c[200200];
ll dp[200200],pre[200200];

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	n=read();int i;
	for (i=1;i<=n;i++) c[i]=read();
	dp[0]=1;
	for (i=1;i<=n;i++)
	{
		if (c[i]==c[i-1]) dp[i]=dp[i-1];
		else
		{
			dp[i]=dp[i-1];
			if (pre[c[i]]) dp[i]=(dp[i]+dp[pre[c[i]]])%maxd;
			pre[c[i]]=i;
		}
	}
	printf("%lld",dp[n]);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;cin>>N;
  vector<string> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  
  sort(vec.begin(),vec.end());
  
  int ans=N;
  
  for(int i=0;i<N;i++){
    if(vec[i]==vec[i+1]){
      ans--;
    }
  }
  
  cout<<ans<<endl;
}

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

char getgrade(int m, int f, int r){
  char grade;

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

  return grade;

}

int main(int argc, char const *argv[]) {
  int m, f, r;
  while (1) {
    cin >> m >> f >> r;
    if( m == -1 && f == -1 && r == -1) break;
    cout << getgrade(m, f, r) << endl;
  }
  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int main() {
	char c;
	while(1) {
		string str;
		long long a, b;
		getline(cin, str);
		if(str[0] == '-') {
			break;
		}
		a = b = 0;
		int i = 0;
		while(str[i] != '.' && i < str.size()) {
			a *= 10;
			a += str[i] - '0';
			i++;
		} i++;
		int d = 1000;
		while(i < str.size()) {
			b += d * (str[i] - '0');
			d /= 10;
			i++;
		}

		a *= 16; b *= 16;
		a += b / 10000;

		if((~(0xfff) & a) || (b % 10000))
			cout << "NA" << endl;
		else {
			for(int i = 0; i < 12; i++) {
				if(i == 8) cout << ".";
				cout << !!(a & (0x1 << (11-i)));
			}cout << endl;
		}
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f)
{
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void visit(const Graph & g, int v, int u, Edges& brdg, vector< vector<int> >& tecomp, stack<int>& roots, stack<int>& S, vector<bool>& inS, vector<int>& num, int& time)
{
  num[v] = ++time;
  S.push(v); inS[v] = true;
  roots.push(v);
  vrep(e, g[v]) {
    int w = e->dst;
    if (num[w] == 0)
      visit(g, w, v, brdg, tecomp, roots, S, inS, num, time);
    else if (u != w && inS[w])
      while (num[roots.top()] > num[w]) roots.pop();
  }
  if (v == roots.top()) {
    brdg.push_back(Edge(u, v, 1));
    tecomp.push_back(vector<int>());
    while (1) {
      int w = S.top(); S.pop(); inS[w] = false;
      tecomp.back().push_back(w);
      if (v == w) break;
    }
    roots.pop();
  }
}

void Bridge(const Graph& g, Edges& brdg, vector< vector<int> >& tecomp)
{
  const int n = g.size();
  vector<int> num(n);
  vector<bool> inS(n);
  stack<int> roots, S;
  int time = 0;
  rep(u, n) if (num[u] == 0) {
    visit(g, u, n, brdg, tecomp, roots, S, inS, num, time);
    brdg.pop_back();
  }
}

int V, E;
int s, t;

int main()
{
  cin >> V >> E;
  Graph g(V);
  Edges brdg;
  vector<vi> tecomp;
  rep(i, E){
    cin >> s >> t;
    g[s].pb(Edge(s, t, 1));
    g[t].pb(Edge(t, s, 1));
  }

  Bridge(g, brdg, tecomp);

  vrep(v, brdg) if(v->src > v->dst) swap(v->src, v->dst);
  sort(ALL(brdg));

  vrep(v, brdg) cout << v->src << " " << v->dst << endl;

  return 0;
}

Measured memory_bytes: 5100
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
m1 = {}
m2 = {}
n_same_or_less_than = [0 for _ in range(N*M + 1)]

unique_numbers = set()
numbers = {}
double_numbers = []

if len(set(A)) < len(A):
    print(0)
    exit(0)

if len(set(B)) < len(B):
    print(0)
    exit(0)

for i in range(N):
    unique_numbers.add(A[i])
    numbers[A[i]] = 0
for j in range(M):
    unique_numbers.add(B[j])
    numbers[B[j]] = 0

for i in range(N):
    numbers[A[i]] += 1
for j in range(M):
    numbers[B[j]] += 1

unique_numbers = list(unique_numbers)

unique_numbers = sorted(unique_numbers)

for number in unique_numbers:
    m1[number] = 0

for number in unique_numbers:
    if numbers[number] == 2:
        double_numbers.append(number)

grid = [[min(A[i], B[j]) for j in range(M)] for i in range(N)]

for i in range(N):
    for j in range(M):
        m1[grid[i][j]] += 1

# print(m1)

current_count = 0
idx = 0

for i in range(1, N*M+1):
    if i == unique_numbers[idx]:
        n_same_or_less_than[i] = current_count
        if idx < len(unique_numbers) - 1:
            idx += 1
    else:
        current_count += 1
        n_same_or_less_than[i] = current_count

# print(n_same_or_less_than)

ans = 1

MOD = 1000000007

rest = []

for number in unique_numbers:
    if number not in double_numbers:
        ans *= m1[number] % MOD
        ans %= MOD
    if m1[number] > 1:
        m2[number - 1] = m1[number] - 1
        rest.append(number-1)

# print(m1)
# print(m2)
# print(double_numbers)
# print(n_same_or_less_than)
# print(rest)

used = 0

def P(n, r):
    res = 1
    for d in range(r):
        res *= n - d
    return res

for number in rest:
    if n_same_or_less_than[number] - used < m2[number]:
        print(0)
        exit(0)
    else:
        # print(n_same_or_less_than[number] - used)
        ans *= P(n_same_or_less_than[number] - used, m2[number]) % MOD
        ans %= MOD
        used += m2[number]

print(ans)


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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll mod = 1e9+7;
    ll ans = 1;
    ll now = 1;
    for(int i=0;i<n;i++){
        if(i!=n-1 && a[i] < 2*now-1){
            ans *= now;
            ans %= mod;
        }
        else if(i!=n-1) now++;
    }
    
    for(int i=1;i<=now;i++){
        ans *= i;
        ans %= mod;
    }
    cout << ans << endl;;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
//cin.ignore();	// better to use 2 times getline(cin,s);
// g++ iterator.cpp -std=c++17
//cout << (A + B == C ? "YES" : "NO") << endl;
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){
   	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);}


int main(void)
{
	fast();
  int n,m;
  cin>>n>>m;
  cout<<((n<=8 && m<=8) ? "Yay!" : ":(")<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int b = 0;

		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
			b += a[i];
		}

		int mid = 0;
		if(b<0){
			mid = (int)((double)b/n - 0.5);
		}else{
			mid = (int)((double)b/n + 0.5);
		}
		int cost = 0;

		for(int i=0; i<n; i++){
			cost += Math.pow(a[i]-mid, 2);
		}

		System.out.println(cost);
	}
}

Measured memory_bytes: 9680
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

int n,m,a;

int main()
{
	n=read();
	m=read();
	for(int i=1;i<=m;++i)
		a+=read();
	if(a>n)
		printf("-1");
	else
		printf("%d",n-a);
	return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <climits>
#define MAX_N 50
using namespace std;
int n, k;
long long x[MAX_N], y[MAX_N];
long long min(long long a, long long b){
  return a < b ? a : b;
}
int main(void){
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
  long long ans = LONG_MAX;
  for(int xi = 0; xi < n; xi++){
    for(int xj = 0; xj < n; xj++){
      for(int yi = 0; yi < n; yi++){
        for(int yj = 0; yj < n; yj++){
          long long lx = x[xi];
          long long rx = x[xj];
          long long uy = y[yi];
          long long by = y[yj];
          int cnt = 0;
          for(int i = 0; i < n; i++){
            if(lx <= x[i] && x[i] <= rx && by <= y[i] && y[i] <= uy) cnt++;
          }
          if(cnt >= k) ans = min(ans, (rx-lx)*(uy-by));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>


int main() {
	int t; std::cin >> t;
	for (; t > 0; --t) {
		int n, m; std::cin >> n >> m;
		int human_start, cat_start; std::cin >> human_start >> cat_start;
		std::vector<std::vector<int>> rooms(n + 1), for_cat(n + 1);
		for (auto i = 0; i < m; ++i) {
			int a, b; std::string type; std::cin >> a >> b >> type;
			if (type == "N") {
				rooms[a].push_back(b);
				rooms[b].push_back(a);
			}
			else {
				for_cat[a].push_back(b);
				for_cat[b].push_back(a);
			}
		}
		std::queue<int> queue;
		std::vector<bool> can_move_from_start(n + 1, false), can_move_to_goal(n + 1, false);
		can_move_from_start[cat_start] = true; queue.push(cat_start);
		while (!queue.empty()) {
			const auto top = queue.front(); queue.pop();
			for (const auto next : for_cat[top]) if (!can_move_from_start[next]) {
				can_move_from_start[next] = true;
				queue.push(next);
			}
		}
		can_move_to_goal[0] = true; queue.push(0);
		while (!queue.empty()) {
			const auto top = queue.front(); queue.pop();
			for (const auto next : for_cat[top]) if (!can_move_to_goal[next]) {
				can_move_to_goal[next] = true;
				queue.push(next);
			}
		}
		std::vector<int> from_start(n + 1, INT_MAX), to_goal(n + 1, INT_MAX), from_cat(n + 1, INT_MAX);
		for (auto i = 0; i < can_move_to_goal.size(); ++i) if (can_move_to_goal[i]) {
			to_goal[i] = 0; queue.push(i);
		}
		while (!queue.empty()) {
			const auto top = queue.front(); queue.pop();
			for (const auto next : rooms[top]) if (to_goal[next] == INT_MAX) {
				to_goal[next] = to_goal[top] + 1;
				queue.push(next);
			}
		}
		from_start[human_start] = 0; queue.push(human_start);
		while (!queue.empty()) {
			const auto top = queue.front(); queue.pop();
			for (const auto next : rooms[top]) if (from_start[next] == INT_MAX) {
				from_start[next] = from_start[top] + 1;
				queue.push(next);
			}
		}
		for (auto i = 0; i < can_move_from_start.size(); ++i) if (can_move_from_start[i]) {
			from_cat[i] = 0; queue.push(i);
		}
		while (!queue.empty()) {
			const auto top = queue.front(); queue.pop();
			for (const auto next : rooms[top]) if (from_cat[next] == INT_MAX) {
				from_cat[next] = from_cat[top] + 1;
				queue.push(next);
			}
		}
		int min_open = INT_MAX;
		for (auto i = 0; i < n + 1; ++i) {
			if (from_start[i] == INT_MAX || to_goal[i] == INT_MAX || from_cat[i] == INT_MAX) continue;
			if (can_move_from_start[i] && can_move_to_goal[i]) {
				min_open = 0;
				break;
			}
			min_open = std::min(min_open, from_start[i] + to_goal[i] + from_cat[i]);
		}
		std::cout << min_open << '\n';
	}
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int keta(int n)
{
    int cnt = 0;
    while (n)
    {
        n /= 10;
        cnt++;
    }
    return cnt;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> vec(m);
    rep(i, m)
    {
        int k;
        cin >> k;
        vec[i].resize(k);
        rep(j, k)
        {
            cin >> vec[i][j];
            vec[i][j]--;
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];

    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        int all_swiches = 0;
        rep(i, m)
        {
            int cnt = 0;
            rep(j, vec[i].size())
            {
                if (bit & (1 << vec[i][j]))
                {
                    cnt++;
                }
            }
            if (cnt % 2 == p[i])
            {
                all_swiches++;
            }
        }
        if (all_swiches == m)
        {
            ans++;
        }
    }

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException{
        int[] arr;
        long count;

        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            arr = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            count = IntStream.rangeClosed(arr[0], arr[1]).filter(i -> arr[2] % i == 0).count();
        }

        System.out.println(count);
    }
}



Measured memory_bytes: 31152
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
		int s[] = new int[4];
		int ans = 0;

		s[0] = Integer.parseInt(S.substring(0,1));
		s[1] = Integer.parseInt(S.substring(1,2));
		s[2] = Integer.parseInt(S.substring(2,3));
		s[3] = Integer.parseInt(S.substring(3,4));
		
		for(int i = 0;i < 4;i++) {
			if(s[i] == 2) {
				ans++;
			}
			
		}
		
		
		
		System.out.println(ans);

	}

}

Measured memory_bytes: 22996
x = int(input())

def is_prime(x):
	if x<= 1:return False
	for i in range(2,1+int(x**(1/2))):
		if x%i == 0: return False
	return True


def main():
	global x
	while not is_prime(x):
		x += 1

	print(x)

main()

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

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

    vector<vector<int>> a(2,vector<int>(N));
    for (int i = 0; i < N; i++) {
        cin >> a.at(0).at(i);
    }
    for (int i = 0; i < N; i++) {
        cin >> a.at(1).at(i);
    }

    int max = 0;
    for (int i = 0; i < N; i++) {
        int candy = 0;
        for (int j = 0; j < N; j++) {
            if (j <= i) {
                candy += a.at(0).at(j);
            }
            if (j >= i) {
                candy += a.at(1).at(j);
            }
        }
        if (max < candy) {
            max = candy;
        }
    }

    cout << max << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include<climits>
# define ll long long
using namespace std;
int main() 
{
    int n,c;
    cin>>n>>c;
    ll wt[103],v[103];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>v[i];
        sum=sum+v[i];
    }
    ll dp[103][sum+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=sum;j++)
        {
            if(i==0 && j==0)
            {
                dp[i][j]=0;
            }
            else if(i==0)
            {
                dp[i][j]=INT_MAX;
            }
            else if(j==0)
            {
                dp[i][j]=0;
            }
            else if(v[i-1]<=j)
            {
                dp[i][j]=min( wt[i-1]+dp[i-1][j-v[i-1]],dp[i-1][j]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    int result=0;
    for(int j=0;j<=sum;j++)
    {
        if(dp[n][j]<=c)
        {
            result=j;
        }
    }
    cout<<result;
}


Measured memory_bytes: 81936
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        // initializing
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = scanner.nextInt();
        }
        int[] Table = new int[n];

        //base case building
        Table[0] = 0;
        Table[1] = Math.abs(h[0] - h[1]);
        if (n < k) {
            for (int i =2; i < n; i++){
                int c = -1;
                for (int j = i; j > 0; j--){
                    int z = Table[i - j] + Math.abs(h[i - j] - h[i]);
                    if (z < c || c == -1) {
                        c = z;
                    }
                }
                Table[i] = c;
            }
        } 
        else {
            for (int i = 2; i < k; i++) {
                int c = -1;
                for (int j = i; j > 0; j--) {
                    int z = Table[i - j] + Math.abs(h[i - j] - h[i]);
                    if (z < c || c == -1) {
                        c = z;
                    }
                }
                Table[i] = c;
            }


            // iterative case
            for (int i = k; i < n; i++) {
                int c = -1;
                for (int j = i - 1; j >= i - k; j--) {
                    int z = Table[j] + Math.abs(h[j] - h[i]);
                    if (z < c || c == -1) {
                        c = z;
                    }
                }
                Table[i] = c;
            }
        }

            System.out.println(Table[n - 1]);

//        Scanner scanner = new Scanner(System.in);
//        int n = scanner.nextInt();
//        int[] h = new int[n];
//        for (int i = 0; i< n; i++){
//            h[i] = scanner.nextInt();
//        }
//
//        int[] Table = new int[n];
//        Table[0] = 0;
//        Table[1] = Math.abs(h[0]-h[1]);
//
//        for (int i = 2; i < n; i++){
//            int a = Table[i-2] + Math.abs(h[i-2]-h[i]);
//            int b = Table[i-1] + Math.abs(h[i-1]-h[i]);
//
//            if (a < b){
//                Table[i] = a;
//            }
//            else {
//                Table[i] = b;
//            }
//        }
//        System.out.println(Table[n-1]);
        }
    }



Measured memory_bytes: 51640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, c;
  cin>>a>>b>>c;
  vector<int> res;
  res.push_back(a);
  res.push_back(b);
  res.push_back(c);
  sort(res.begin(), res.end());
  int ans=(res[0]*res[1])/2;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n , a[1000],b[1000];
	cin >> n;
	for (int i = 0; i < n - 1; ++i) cin >> b[i];
	a[0] = b[0];
	b[n - 1] = b[n - 2];
	int s = a[0];
	for (int i = 1; i < n; ++i) a[i] = min(b[i - 1], b[i]), s += a[i];
	cout << s;
	return 0;
}

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

int n;
long long cnt;
int a[1000001];
int l;
vector<int> g;

void insertion(int a[], int n, int g)
{
    for(int i=g;i<n;i++)
    {
        int v = a[i];
        int j = i - g;
        while(j>=0 && a[j]>v)
        {
            a[j+g] = a[j];
            j -= g;
            cnt++;
        }
        a[j+g] = v;
    }
}

void shell(int a[], int n)
{
    for(int i=1; ; )
    {
        if(i>n) break;
        g.push_back(i);
        i = i*3 + 1;
    }
    for(int i=g.size()-1;i>=0;i--)
    {
        insertion(a, n, g[i]);
    }
}


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

    shell(a, n);

    cout<<g.size()<<endl;
    for(int i=g.size()-1;i>=0;i--)
    {
        cout<<g[i];
        if(i) cout<<" ";
    }
    cout<<endl;
    cout<<cnt<<endl;
    for(int i=0;i<n;i++)
    {
        cout<<a[i]<<endl;
    }

    return 0;
}



Measured memory_bytes: 6956
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	ll A, B, T;

	cin >> A >> B >> T;
	
	cout << T / A*B;

	system("PAUSE");
}

Measured memory_bytes: 504
def main():
    n, a, b, k = map(int, raw_input().split())
    mod = 998244353
    f = [1] * 300010
    invf = [1] * 300010
    for i in xrange(300000):
        f[i+1] = f[i] * (i + 1) % mod
    invf[300000] = pow(f[300000], mod - 2, mod)
    for i in xrange(300000, 1, -1):
        invf[i-1] = invf[i] * i % mod
    ans = 0
    for i in xrange(n + 1):
        if k < a * i:
            break
        if (k - a * i) % b == 0:
            t = (k - a * i) / b
            if t > n:
                continue
            ans += f[n] * invf[i] * invf[n-i] % mod * f[n] * invf[t] * invf[n-t] % mod
            if ans >= mod:
                ans -= mod
    print ans
main()


Measured memory_bytes: 21764
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int h,n;
  cin>>h>>n;
  vector<pair<int,int>> vec(n);
  for(auto&& e: vec) 
  {
    cin>>e.first>>e.second;
  }
  vector<int> dp;
  dp.push_back(0);
  auto min_2=min_element(vec.begin(), vec.end(),[](auto a,auto b){return a.second<b.second;});
  auto max_1=max_element(vec.begin(), vec.end(),[](auto a,auto b){return a.first>a.second;});
  for (int i = 0; i < (*min_2).first; ++i)
  {
    dp.push_back((*min_2).second);
  }

  int i=dp.size();
  while(i<h+(*max_1).first)
  {
    vector<int> tmp;
    for(auto&& e: vec) 
    {
      if(i-e.first>=0)
      { 
        tmp.push_back(dp[i-e.first]+e.second);
      }
      else
      {
        tmp.push_back(e.second);
      }
    }
    dp.push_back(*min_element(tmp.begin(), tmp.end()));
    i++;
  }
  cout<<dp[h];
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<string>
#define qw() freopen("in.txt","r",stdin)
#define er() freopen("out.txt","w",stdout)
using namespace std;
int main(void)
{
    int a,b;
    while(cin>>a>>b)
      cout<<(a-1)*(b-1)<<endl;
    return 0;
}


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

using namespace std;

vector<int> G[100100];
int N;

int dfs(int v){
	if(G[v].size() == 0) return 0;
	vector<int> tmp;
	for(int i = 0; i < G[v].size(); ++i){
		int cur = dfs(G[v][i]);
		tmp.push_back(cur);
	}
	sort(tmp.begin(), tmp.end());
	int d = tmp.size();
	for(int i = 0; i < d; ++i){
		tmp[i] += (d - i);
	}
	int res = 0;
	for(int i = 0; i < d; ++i){
		if(res < tmp[i]) res = tmp[i];
	}
	return res;
}

int solve(){
	return dfs(0);
}

void input(){
	scanf("%d", &N);
	for(int i = 1; i < N; ++i){
		int v;
		scanf("%d", &v);
		v--;
		G[v].push_back(i);
	}
}

int main(){
	input();
	int ans = solve();
	printf("%d\n", ans);
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)

void solve(int n) {
    string s = "";
    string t;
    rep(i,n) {
        cin>>t;
        s += t;
    }

    set<string> S;
    for(int len=1; len<=n; len++) {
        for(int i=0; i<n-len+1; i++) {
            string ss = s.substr(i,len);
            S.insert(ss);
        }
    }

    for(int i=0; ; i++) {
        if(S.count(to_string(i)) == 0) {
            cout << i << "\n";
            S.clear();
            break;
        }
    }
    return ;
}

int main() {
    int n;
    while(cin>>n) solve(n);
    return 0;
}

Measured memory_bytes: 209588
N=gets.chomp.to_i
T,A=gets.chomp.split.map(&:to_i)
H=gets.chomp.split.map(&:to_i)

a=100000
s=0
N.times do |i|
  t=((T-H[i]*0.006)-A).abs
  if t < a then
    a=t
    s=i
  end
end
puts s+1

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n,a,b,c,d;
  string s;
  cin >>n>>a>>b>>c>>d>>s;
  bool sunuke = true, funuke = true;
  a--;b--;c--;d--;
  for (int i = a; i < c; i++) if (s[i] == '#' && s[i+1] == '#') sunuke = false;
  for (int i = b; i < d; i++) if (s[i] == '#' && s[i+1] == '#') funuke = false;
  
  bool can = sunuke && funuke;
  if (!can) {
    cout << "No" << endl;
    return 0;
  }
  
  if (c < d) {
    cout << "Yes" << endl;
  }
  else {
    can = false;
    for (int i = b; i <= d; i++)
    {
      if ((s[i]==s[i-1]&&s[i]==s[i+1]&&s[i]=='.')) {
        can = true;
      }
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3708
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
} P;

void initialize(void);
void enqueue(P);
P dequeue(void);
int min(int,int);

int head,tail,n;
P Q[LEN+1];

int main(){
  int elaps=0,c;
  int i,q;
  P u;
  scanf("%d %d", &n, &q);

  initialize();
  for(i = 1;i <= n;i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;

  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else printf("%s %d\n",u.name,elaps);
  }
  return 0;
}

void initialize(void){
  head = tail = 0;
}

void enqueue(P x){
  Q[tail] = x;
  tail = (tail+1)%LEN;
}

P dequeue(void){
  P x;
  x = Q[head];
  head = (head+1)%LEN;
  return x;
}

int min(int a,int b){
  return a < b ? a : b;
}

Measured memory_bytes: 10756
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict, deque
    n, m = map(int, readline().split())
    edge = defaultdict(set)

    for _ in range(m):
        a, b = map(int, readline().split())
        edge[a].add(b)
        edge[b].add(a)

    for u in edge[1]:
        if n in edge[u]:
            print("POSSIBLE")
            sys.exit()

    print("IMPOSSIBLE")

if __name__ == '__main__':
    main()


Measured memory_bytes: 118876
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		int my[]={1872000,144000,7200,360,20,1};
		int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
		while(true){
			String str=s.next();
			if(str.equals("#"))break;
			String[]num=str.split("\\.");
			int []n=new int[num.length];
			for(int i=0;i<n.length;i++)n[i]=Integer.parseInt(num[i]);
			if(num.length==3){
				if(n[0]==2012){
					System.out.println("0.0.0.0."+(n[2]-21));
				}else{
					long val=11;
					int Y=2013;
					n[1]--;n[2]--;
					while(Y+400<n[0]){
						Y+=400;
						val+=146097;
					}
					while(Y<n[0]){
						if(Y%4==0&&(Y%100!=0||Y%400==0))val++;
						val+=365;
						Y++;
					}
					int M=0;
					while(M<n[1]){
						if(M==1&&Y%4==0&&(Y%100!=0||Y%400==0))val++;
						val+=mon[M];
						M++;
					}
					val+=n[2];
					
					long ret[]=new long[5];
					for(int i=0;i<5;i++)ret[i]=val%my[i]/my[i+1];
					System.out.println(ret[0]+"."+ret[1]+"."+ret[2]+"."+ret[3]+"."+ret[4]);
				}
			}else{
				int day=0;
				for(int i=1;i<=num.length;i++)day+=n[i-1]*my[i];
				if(day<=10){
					System.out.println("2012.12."+(21+day));
				}else{
					day-=11;
					int Y=2013;
					int M=0;
					while(day>=146097){day-=146097;Y+=400;}
					while(day>=365+((Y%4==0&&(Y%100!=0||Y%400==0))?1:0)){
						day-=365+((Y%4==0&&(Y%100!=0||Y%400==0))?1:0);
						Y++;
					}
					while(day>=mon[M]+((M==1&&(Y%4==0&&(Y%100!=0||Y%400==0)))?1:0)){
						day-=mon[M]+((M==1&&(Y%4==0&&(Y%100!=0||Y%400==0)))?1:0);
						M++;
					}
					System.out.println(Y+"."+(M+1)+"."+(day+1));
				}
			}
		}
	}
}

Measured memory_bytes: 28772
n = int(input())
v = list(map(float, input().split()))

v.sort()

ans = 0.0
vk = 0.0

for i in range(n-1):
    vk = (v[i] + v[i+1])/2.0
    v[i+1] = vk
ans = v[n-1]

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x%y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size()/2; i++)
	{
		if (s[i] != s[s.size() - i - 1])  ans++;
	}



	cout << ans<< endl;




}


Measured memory_bytes: 256