akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

bool func(string str, int stp)
{
	int t = stp, u, d, l, r;
	u = d = l = r = 0;
	bool f = true;
	for(int i = 0; i < str.size(); i++){
		if(str[i] == 'U'){
			if(u == -t){
				f = false;
				break;
			}
			if(r == t){
				r = 0;
			} else if(l == t){
				l = 0;
			} else if(d == t){
				d = 0;
			}
			u = t;
		} else if(str[i] == 'D'){
			if(d == -t){
				f = false;
				break;
			}
			if(u == t){
				u = 0;
			} else if(l == t){
				l = 0;
			} else if(r == t){
				r = 0;
			}
			d = t;
		} else if(str[i] == 'L'){
			if(l == 1){
				f = false;
				break;
			}
			if(u == t){
				u = 0;
			} else if(d == t){
				d = 0;
			}
			l = t;
		} else {
			if(r == -1){
				f = false;
				break;
			}
			if(u == t){
				u = 0;
			} else if(d == t){
				d = 0;
			}
			r = t;
		}
		t = -t;
	}
	
	return f;
}

int main()
{
	int n;
	string str;
	cin >> n;
	while(n--){
		cin >> str;
		
		if(func(str, 1)){
			cout << "Yes" << endl;
			continue;
		}
		if(func(str, -1)){
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1140
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
	
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream outputStream = System.out;
    	PrintWriter out = new PrintWriter(outputStream);

        int i, n, m, c, k, j;

		int t = Integer.parseInt(br.readLine());    
        StringTokenizer st = new StringTokenizer(br.readLine());
    	int[] ar = new int[t];
     
		for(i=0;i<t;i++)
          ar[i]=Integer.parseInt(st.nextToken());
      
      Arrays.sort(ar);
         double sum=ar[0],max=0;
        for(i=1;i<t;i++)
        {
          sum=(sum+ar[i])/2;
        }
	out.print(sum);
	out.flush();
	out.close();
	
	}
}

Measured memory_bytes: 21204
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
long long mmin(long long &a,long long b) {
	a = min(a, b);
	return a;
}
long long mmax(long long &a,long long b) {
	a = max(a, b);
	return a;
}
int nibu(vector<int> &v, int tan) {
	int up = v.size()-1;
	int lo = 0;
	if (tan <= v[0]) {
		return 0;
	}
	while (up - lo > 1) {
		int mi = (up + lo) / 2;
		if (tan <= v[mi]) {
			up = mi;
		}
		if (v[mi] < tan) {
			lo = mi;
		}
	}
	return up;
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int k = 2; k <= m; k++) {
		for (int i = 0; i < n - 1; i++) {
			if (a[i]%k >a[i+1]%k) {
				int x = a[i];
				int y = a[i + 1];
				a[i] = y;
				a[i + 1] = x;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << a[i]<<endl;
	}
	cin >> m>> n;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+10;
string s;
ll a[N];
int main() {
	ll ans=0,i,t,c;
	cin>>s;
	a[0]=1;
	t=0;
	c=1;
	for (i=s.length()-1;i>=0;i--) {
		t=t+(s[i]-'0')*c;
		t%=2019;
		c=(c*10)%2019;
		a[t]++;
	}
	for (i=0;i<=2018;i++)
		ans+=a[i]*(a[i]-1)/2;
	cout<<ans<<endl;
	return 0; 
} 

Measured memory_bytes: 3744
#include<cstdio>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
	int A, B, Q;
	scanf("%d %d %d", &A, &B, &Q);
	ll s[A], t[B];
	for (int i = 0; i < A; ++i) scanf("%lld", s + i);
	for (int i = 0; i < B; ++i) scanf("%lld", t + i);
	for (int i = 0; i < Q; ++i){
		ll x;
		scanf("%lld", &x);
		int right_s = distance(s, upper_bound(s, s + A, x));
		int left_s = right_s - 1;
		int right_t = distance(t, upper_bound(t, t + B, x));
		int left_t = right_t - 1;
		if(left_s == -1 && left_t == -1) printf("%lld\n", max(s[0], t[0]) - x);
		else if(right_s == A && right_t == B) printf("%lld\n", x - min(s[A - 1], t[B - 1]));
		else if(left_s == -1){
			if(right_t == B) printf("%lld\n", min(x - t[left_t], s[0] - x) + s[0] - t[left_t]);
			else printf("%lld\n", min(max(t[right_t], s[0]) - x, min(x - t[left_t], s[0] - x) + s[0] - t[left_t]));
		}else if(left_t == -1){
			if(right_s == A) printf("%lld\n", min(x - s[left_s], t[0] - x) + t[0] - s[left_s]);
			else printf("%lld\n", min(max(s[right_s], t[0]) - x, min(x - s[left_s], t[0] - x) + t[0] - s[left_s]));			
		}else if(right_s == A) printf("%lld\n", min(x - min(s[left_s], t[left_t]), min(x - s[left_s], t[right_t] - x) + t[right_t] - s[left_s]));
		else if(right_t == B) printf("%lld\n", min(x - min(t[left_t], s[left_s]), min(x - t[left_t], s[right_s] - x) + s[right_s] - t[left_t]));
		else printf("%lld\n", min({x - min(s[left_s], t[left_t]), min(x - s[left_s], t[right_t] - x) + t[right_t] - s[left_s], min(x - t[left_t], s[right_s] - x) + s[right_s] - t[left_t], max(s[right_s], t[right_t]) - x}));
	}
	return 0;
}

Measured memory_bytes: 2816
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

bool solve(bitset<32> card, int myNum, int yourNum, int a, int b)
{
    if(yourNum == 0)
        return false;

    bool isSkip = true;
    bool ans = false;
    if(a > 1 && card[a-1]){
        ans |= !solve(~card, yourNum, myNum-1, a-1, b);
        isSkip = false;
    }
    if(b < 13 && card[b+1]){
        ans |= !solve(~card, yourNum, myNum-1, a, b+1);
        isSkip = false;
    }
    if(isSkip)
        ans |= !solve(~card, yourNum, myNum, a, b);

    return ans;
}

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

    for(int i=0; i<n; ++i){
        bitset<32> card;
        for(int j=0; j<6; ++j){
            int f;
            cin >> f;
            card[f] = true;
        }
        if(solve(card, 6, 6, 7, 7))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
double x_[50],y_[50],z_[50],r_[50];
double eps=1e-9;
ll score[50];
int main(){
	int N,Q;
	cin>>N>>Q;
	rep(i,N) cin>>x_[i]>>y_[i]>>z_[i]>>r_[i]>>score[i];
	rep(tt,Q){
		long long ans=0;
		double a,b,c,d,e,f;
		cin>>a>>b>>c>>d>>e>>f;
		d-=a,e-=b,f-=c;
		rep(i,N){
			double x=x_[i],y=y_[i],z=z_[i],r=r_[i];
			double A=d*d+e*e+f*f;
			double B=2*(d*(a-x)+e*(b-y)+f*(c-z));
			double C=(a-x)*(a-x)+(b-y)*(b-y)+(c-z)*(c-z);
			double mn=1e10;
			double xx=-B/A/2;
			if(0<=xx+eps&&xx<=1+eps) chmin(mn,A*xx*xx+B*xx+C);
			chmin(mn,C);
			chmin(mn,A+B+C);
			if(mn<r*r+eps) ans+=score[i];
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1228
#include<cstdio>

int main()
{
    int a[1000];
    int n;
    while(~scanf("%d",&n))
    {
        int i,j;
        int l = 0,m,t,count=0;
        while(n--) scanf("%d",&a[l++]);

        for(i=0;i<l;i++)
        {
            m=i;
            for(j=i;j<l;j++)
            {
                if(a[j]<a[m]) m=j;
            }
            if(m!=i)
            {t=a[m];
            a[m]=a[i];
            a[i]=t;count++;}
        }
        for(i=0;i<l;i++) printf("%d%c",a[i],(i==l-1)?'\n':' ');
        printf("%d\n",count);
    }
    return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long

using namespace std;

typedef pair<int, int> P;

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

int main(){
	ll n;
	cin >> n;
	vector<ll> odd_cnt(100000, 0);
	vector<ll> even_cnt(100000, 0);
	ll odd, even;
	REP(i, n/2){
		cin >> odd >> even;
		odd_cnt[odd] += 1;
		even_cnt[even] += 1;
	}
	if (max_element(odd_cnt.begin(), odd_cnt.end())-odd_cnt.begin()
		==  max_element(even_cnt.begin(), even_cnt.end())-even_cnt.begin()){
		sort(odd_cnt.begin(), odd_cnt.end(), greater<ll>());
		sort(even_cnt.begin(), even_cnt.end(), greater<ll>());
		cout << n- max(odd_cnt[0]+even_cnt[1], odd_cnt[1]+even_cnt[0]) << endl; 
	} else {
		cout << n - *max_element(odd_cnt.begin(), odd_cnt.end())
		- *max_element(even_cnt.begin(), even_cnt.end()) << endl;
	}
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int N, K;
int arr[505];
int rem[505];
vector <int> factors;

void findFactors(int tot){
    int p = (int) sqrt(tot)+1;
    for (int i=1; i<=p; i++) {
        if (tot % i == 0) {
            factors.push_back(i);
            factors.push_back(tot/i);
        }
    }
    sort(factors.begin(), factors.end(), greater<>());
}

int main() {
    cin >> N >> K;
    int tot = 0;
    for (int i=1; i<=N; i++){
        scanf("%d", &arr[i]);
        tot += arr[i];
    }
    findFactors(tot);
    int ans;
    for (int f: factors){
        for (int i=1; i<=N; i++){
            rem[i] = arr[i] % f;
        }
        sort(rem+1, rem+N+1);
        int sum = 0, req1 = 0, req2 = 0;
        int l = 0, r = N;
        while (l <= r){
            if (sum <= 0) {
                sum += rem[l];
                req1 += rem[l];
                l++;
            } else {
                sum -= (f-rem[r]);
                req2 += (f-rem[r]);
                r--;
            }
        }
        if (req1 <= K && req2 <= K) {
            ans = f;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


ll N_MAX=1e5+10;
vll a(N_MAX);
vll cum_e(N_MAX),cum(N_MAX);

bool check(ll mid, ll n, ll x){
  ll num=n-mid;
  ll l=mid;
  ll r=l+num/2;

  return abs(a[l]-x)<=abs(a[r]-x);
}

ll calc(ll l){
  if(l<0)
    return 0;
  return cum_e[l+1];
}

ll calc(ll n, ll r){
  return cum[n]-cum[r];
}

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

  ll n,q;
  cin>>n>>q;
  REP(i,n)cin>>a[i];


  //prep
  REP(i,n)cum[i+1]+=cum[i]+a[i];
  //ex...cum_e[3]=a[2]+a[0]
  REP(i,n)cum_e[i+1]=((i>=1)?cum_e[i-1]:0)+a[i];

  REP(i,q){
    ll x;
    cin>>x;

    ll ok=n-1;
    ll ng=-1;
    while(abs(ng-ok)>1){
      ll mid=(ok+ng)/2;
      if(check(mid,n,x))
        ok=mid;
      else
        ng=mid;
    }
    ll num=n-ok;
    ll l=ok;
    ll r=l+num/2;
    ll ans=calc(l-1-(num%2==1?1:0))+calc(n,r);

    cout<<ans<<endl;
  }

}



Measured memory_bytes: 5484
#include<bits/stdc++.h>   
using namespace std;    
int main(){
  int n;
  cin>>n;
  int a,b;
  cin>>a>>b;
  if(n==1){
    cout<<"Hello"<<" "<<"World"<<endl;
  }

  else{
    cout<<a+b<<endl;
  }
}



  
  

Measured memory_bytes: 256
#include<stdio.h>
#define SHIRO 0
#define NEZUMI 1
#define KURO 2
#define MAX 100
int n;
int AD[MAX][MAX];
int iro[MAX], d[MAX], f[MAX], t;


void DFS2(int);

void DFS(){
  int i;
  for(i = 0 ; i < n ; i++){
    iro[i] = SHIRO;
  }

  t = 0;

  for(i = 0 ; i < n ; i++){
    if(iro[i] == SHIRO) DFS2(i);
  }

  for(i = 0 ; i < n ; i++){
    printf("%d %d %d\n",i+1, d[i],f[i]);
  }
}





int main(){
  int i, j, s, t, u;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){

    for(j = 0 ; j < n ; j++){

      AD[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&s,&t);
    s--;
    for(j = 0 ; j < t ; j++){
      scanf("%d",&u);
      u--;
      AD[s][u] = 1;
    }
  }

  DFS();

  return 0;
}



void DFS2(int a){
  int i;

  iro[a] = NEZUMI;
  d[a] = ++t;
  for(i = 0 ; i < n ; i++){
    if(AD[a][i] ==  0) continue;
    if(iro[i] == SHIRO){
      DFS2(i);
    }
  }
  iro[a] = KURO;
  f[a] = ++t;
}



Measured memory_bytes: 2112
import math


a,b,x=map(int,input().split())

if 2*x<a*a*b:
    sit=math.atan((a*b*b)/(2*x))
    print(math.degrees(sit))
elif 2*x>a*a*b:
    p1=2*(a*a*b-x)
    p2=a*a*a
    sit=math.atan(p1/p2)
    print(math.degrees(sit))
else:
    print(45.00000)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

int main() {
	
	string s,t,res;
	cin>>s>>t;
	int si,ti;
	si = (int)s.size();
	ti = (int)t.size();
	vector < vector < pair < int, pair < int, int > > > > dp(si+1, vector < pair < int, pair < int, int > > > (ti+1)); 
	for(int i = 1; i <= si ; i++) {
		for(int j = 1 ; j <= ti ; j++) {
			if(s[i-1]==t[j-1] ) {
				dp[i][j].ff = dp[i-1][j-1].ff+1;
				dp[i][j].ss.ff = i-1;
				dp[i][j].ss.ss = j-1; 
			}
			else {
				if(dp[i-1][j] > dp[i][j-1]) {
					dp[i][j].ff = dp[i-1][j].ff;
					dp[i][j].ss.ff = i-1;
					dp[i][j].ss.ss = j;
				}
				else {
					dp[i][j].ff = dp[i][j-1].ff;
					dp[i][j].ss.ff = i;
					dp[i][j].ss.ss = j-1;
				}
			}
		}
	}
	int i = si, j = ti;
	while(i!=0 and j!=0) {
		if((abs(dp[i][j].ss.ff - i) + abs(dp[i][j].ss.ss - j)) == 2) {
			res.pb(s[i-1]);
			i=i-1;
			j=j-1;
		}
		else {
			if(dp[i][j].ff == dp[i-1][j].ff) {
				i = i-1;
			}
			else {
				j = j-1;
			}
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 105984
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int i,j=s.size()-1,sum=0;
	for(i=0;i<s.size()/2;i++)
	{
		if(s[i]!=s[j] && s[j]>s.size()/2)
		{
		sum++;
	}
	j--;
}
		cout<<sum<<endl;
		return 0;
}

Measured memory_bytes: 256
public class Main {

	public static void main(String[] args) {

		java.util.Scanner sc = new java.util.Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a < b && b < c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

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

  ll day;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> a;
  vector<ll> b(n);
  for (ll i = 0; i < n; i++) {
    cin >> day >> b[i];
    a.push(make_pair(day, i));
  }

  ll ans = 0;
  priority_queue<ll> q;
  for (ll i = 1; i <= m; i++) {
    while (!a.empty() && a.top().first <= i) {
      // cout << i << " " << a.top().first << endl;
      q.push(b[a.top().second]);
      a.pop();
    }
    if (q.empty()) continue;
    ans += q.top();
    q.pop();
  }

  cout << ans << endl;
}


Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int a, b;
    cin >> a >> b;
    cout << 6-a-b << endl;
    // printf("%d\n", N);
    return 0;
}

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

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int64_t> dp(n, LLONG_MAX);
	for (int i{}; i < n; i++)
	{
		int64_t a;
		scanf("%lld", &a);
		*std::lower_bound(dp.begin(), dp.end(), a) = a;
	}
	printf("%d\n", std::lower_bound(dp.begin(), dp.end(), LLONG_MAX) - dp.begin());
	return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, n, iv) for (int i = iv; i < n; i++)
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

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

    ll A;
    double B;
    cin >> A >> B;

    ll BB = (ll)round(B * 100);
    cout
        << (A * BB / 100) << endl;
}


Measured memory_bytes: 3220
object Main {
    val div_2 = Array.ofDim[Int](20001)
    val div_5 = Array.ofDim[Int](20001)
    for(i <- 2 to 20000) {
        div_2(i) = div_2(i - 1) + div_k(2, i)
        div_5(i) = div_5(i - 1) + div_k(5, i)
    }

    def div_k(k: Int, n: Int): Int = {
        var c = 0
        var i = n
        while(i % k == 0) {
            i /= k
            c += 1
        }
        c
    }
    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        var n = sc.nextInt
        while (n != 0) {
            println(div_2(n) min div_5(n))
            n = sc.nextInt
        }
    }
}

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

int main(int argc, const char * argv[]) {
    int even_patterns, odd_patterns;
    int num_even, num_odd;
    cin >> num_even >> num_odd;
    
    if (num_even <= 1) {
        even_patterns = 0;
    }else{
        even_patterns = (num_even * (num_even - 1)) / 2;
    }
    
    if (num_odd <= 1) {
        odd_patterns = 0;
    }else{
        odd_patterns = (num_odd * (num_odd - 1)) / 2;
    }
    
    cout << (even_patterns + odd_patterns) << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
    public class Main{ public static void main(String...args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String subString = br.readLine(); int len = subString.length();
        String r1 = new StringBuilder(subString).reverse().toString(); String s1 = subString.substring(0,(len-1)/2);
        String r2 = new StringBuffer(s1).reverse().toString(); String s2 = subString.substring(((len+3)/2)-1, len);
        String r3 = new StringBuffer(s2).reverse().toString();
        if(subString.equals(r1) && s1.equals(r2) && s2.equals(r3)) System.out.println("Yes");
      	else System.out.println("No");}
    }

Measured memory_bytes: 22484
#include <bits/stdc++.h>
 
using namespace std;
 
int n;
long long c;
long long h[1000010];
long long dp[1000010];
 
struct Line{
    long long m, c;
 
    long double getX(Line o){
        return (long double) (c - o.c) / (o.m - m);
    }
 
    long long getY(long long x){
        return m*x + c;
    }
};
 
vector<Line> ch;
 
bool good(Line a, Line b, Line c){
    return a.getX(b) > b.getX(c);
}
 
void insert(Line l){
    while(ch.size() > 1 && !good(ch[ch.size() - 2], ch.back(), l)) ch.pop_back();
    ch.emplace_back(l);
}
 
long long query(long long x){
    int l, r, m;
    l = 0, r = ch.size() - 2;
 
    while(l <= r){
        m = (l + r) >> 1;
 
        if(ch[m].getY(x) > ch[m + 1].getY(x)){
            l = m + 1;
        } else r = m - 1;
    }
 
    return ch[l].getY(x);
}
 
int main(){
    scanf("%d%lld", &n, &c);
 
    for(int i = 1; i <= n; i++) scanf("%lld", &h[i]);
 
    //Convex Hull Technique
    //dp[i] = min {dp[j] + (h[i] - h[j]) ^ 2 + c}
    //      = h[i]^2 + min {dp[j] + h[j]^2 + c - 2 * h[i] * h[j]}
    //Hence, m = h[i], x = - 2 * h[j], c = dp[j] + h[j]^2 + c
    for(int i = 2; i <= n; i++){
        insert(Line({h[i - 1], dp[i - 1] + h[i - 1] * h[i - 1] + c}));
        dp[i] = h[i] * h[i] + query(-2*h[i]);
    }
 
    cout << dp[n] << endl;
    
    return 0;
}

Measured memory_bytes: 11888
#include <cstdio>
#include <algorithm>
using namespace std;

struct E{ int a, b, c; };

int main(){
	int n;
	E edge[45];
	int fr, to, co;
	int d[10][10];
	int town;
	const int INF = 100000000;
	bool update;
	int res_town, res_cost, sub;
	
	while(true){
		scanf("%d", &n);
		
		if(n == 0) return 0;
		
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				d[i][j] = INF;
			}
		}
		for(int i = 0; i < 10; i++) d[i][i] = 0;
		
		town = 0;
		for(int i = 0; i < n; i++){
			scanf("%d%d%d", &fr, &to, &co);
			town = max(town, max(fr, to));
			d[fr][to] = co; d[to][fr] = co;
			edge[i].a = fr; edge[i].b = to; edge[i].c = co;
		}
		
		res_town = 0; res_cost = INF * 10;
		for(int i = 0; i <= town; i++){
			sub = 0;
			
			//dijkstra
			update = true;
			while(update){
				update = false;
				for(int j = 0; j < n; j++){
					if(d[i][edge[j].a] + edge[j].c < d[i][edge[j].b]){
						update = true;
						d[i][edge[j].b] = d[i][edge[j].a] + edge[j].c;
					}
					if(d[i][edge[j].b] + edge[j].c < d[i][edge[j].a]){
						update = true;
						d[i][edge[j].a] = d[i][edge[j].b] + edge[j].c;
					}
				}
			}
			
			for(int j = 0; j <= town; j++) sub += d[i][j];
			
			if(sub < res_cost){
				res_town = i;
				res_cost = sub;
			}
		}
		
		printf("%d %d\n", res_town, res_cost);
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n;
	
	cin >> n;
	
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			if(i * j == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
	
	return 0;
} 

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

#define ll long long

signed main() {
  int A,B,C;
  cin >> A >> B >> C;
  int cnt1=0,cnt2=0;
  if(A==5)
  {
    cnt1 += 1;
  }
  else if(A==7)
  {
    cnt2 += 1;
  }

  if(B==5)
  {
    cnt1 += 1;
  }
  else if(B==7)
  {
    cnt2 += 1;
  }

  if(C==5)
  {
    cnt1 += 1;
  }
  else if(C==7)
  {
    cnt2 += 1;
  }
  if(cnt1==2 && cnt2==1)
  {cout << "YES" << endl;}
  else{cout << "NO" << endl;}
}


Measured memory_bytes: 3604
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int trainTime[101][101];
int trainCost[101][101];

int main(){
	int n,m;
	while(~scanf("%d",&n)){
		if(n==0) break;
		map<string,int> items;
		for(int i=0;i<n;i++){
			string name;
			int cost;
			cin >> name >> cost;
			items[name] = cost;
		}
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			string name;
			cin >> name;
			int k;
			scanf("%d",&k);

			int sum = 0;
			string elem;
			for(int j=0;j<k;j++){
				string elem;
				cin >> elem;
				sum += items[elem];
			}

			items[name] = min(items[name],sum);
		}

		string target;
		cin >> target;

		cout << items[target] << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int n, t[109], m, p[109], x[109];
int main() {
	cin >> n;
	int sum = 0;
	for(int i = 0; i < n; i++) cin >> t[i], sum += t[i];
	cin >> m;
	for(int i = 0; i < m; i++) {
		cin >> p[i] >> x[i]; p[i]--;
		cout << sum - (t[p[i]] - x[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll n, m;
	cin >> n >> m;
	vector < pair < ll, ll>> data(n);
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		data[i] = make_pair(a, b);
	}
	sort(data.begin(), data.end());
	ll ans;
	ans = 0;
	for (int i = 0; i < n; i++) {
		if (m > data[i].second) {
			m -= data[i].second;
			ans += data[i].first * data[i].second;
		}
		else {
			ans += data[i].first * m;
			m = 0;
		}
		if (m == 0) {
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4836
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>

using namespace std;
int n, k, a[100], ans;

int main() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + 1 + n);
	reverse(a + 1, a + 1 + n);
	for(int i = 1; i <= k; i++) ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

map<pair<int, int>, bool> isConect;
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		isConect[mp(a, b)] = true;
		isConect[mp(b, a)] = true;
	}

	bool flg = false;
	for (int i = 0; i < N; i++) {
		if (isConect[mp(0, i)] && isConect[mp(i, N-1)]) flg = true;
	}

	if (flg) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 37760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string s, t;

int main() {
	cin >> s >> t;
	string ans = s;
	int pos = -1;
	rep(i, s.size()) {
		if (i + t.size() <= s.size()) {
			rep(j, t.size()) {
				if (s[i + j] == '?') {
					if (j == t.size() - 1)pos = i;
				}
				else {
					if (s[i + j] == t[j]) {
						if (j == t.size() - 1)pos = i;
					}
					else break;
				}
			}
		}
	}
	if (pos == -1)cout << "UNRESTORABLE" << endl;
	else {
		rep(i, t.size()) {
			s[i + pos] = t[i];
		}
		rep(i, s.size()) {
			if (s[i] == '?')s[i] = 'a';
		}
		cout << s << endl;
	}
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  int a, b;
  cin >> a >> b;
  if (b >= a) {
    cout << a << endl;
  } else {
    cout << a-1 << endl;
  }

  return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
#include <math.h>
#include <utility>
#include <list>
#include <functional>
using namespace std;

#define ll long long
#define vecint vector<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1

int main(){
  vector<int> v;
  rep(i,3){
    int x;
    cin>>x;
    v.push_back(x);
  }
  sort(v.begin(),v.end());
  string ans="YES";
  if(v[0]!=5) ans="NO";
  if(v[1]!=5) ans="NO";
  if(v[2]!=7) ans="NO";
  print(ans);
  return 0;
}


Measured memory_bytes: 256
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    vector<vector<int>> A(3,vector<int> (3));
    REP(i,3){
        REP(j,3){
            cin>>A[i][j];
        }
    }
    int N;
    cin>>N;
    vector<int> B(N);
    REP(i,N){
        cin>>B[i];
    }
    //inputend
    vector<vector<int>> CHECK(3,vector<int> (3,0));
    sort(ALL(B));
    REP(i,3){
        REP(j,3){
            REP(k,N){
                if(A[i][j]==B[k]){
                    CHECK[i][j]=1;
                }
            }
        }
    }
    //checkend
    bool flag=0;
    REP(i,3){
        bool tmp=1;
        REP(j,3){
            if(CHECK[i][j]==0){
                tmp=0;
            }
        }
        if(tmp==1){
            flag=1;
        }
    }
    REP(i,3){
        bool tmp=1;
        REP(j,3){
            if(CHECK[j][i]==0){
                tmp=0;
            }
        }
        if(tmp==1){
            flag=1;
        }
    }
    if(CHECK[1][1]==1&&((CHECK[0][0]==1&&CHECK[2][2]==1)||(CHECK[0][2]==1&&CHECK[2][0]==1))){
        flag=1;
    }
    if(flag==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */

 
int main() {
    int a,b;
    cin >> a >> b;
    cout << a*b << ' '<< a*2 + b*2 << endl;
}



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

using namespace std;

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

  vector<int> h(N);
  for(int i=0;i<N;i++) cin>>h[i];    
  sort(h.begin(),h.end());
  int ans=h[N-1]-h[0];
  for(int i=0;i<=(N-K);i++){
    ans=min(ans,(h[i+K-1]-h[i]));
  }

  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

const int INF = 100000000;
int dp[20000];

int main(void) {
    dp[0] = 0;
    for(int i = 1; i < 20000; i++) {
        dp[i] = INF;
    }

    int h, n;
    cin >> h >> n;

    int amax = 0;
    for(int j = 0; j < n; ++j) {
        int a, b;
        cin >> a >> b;
        amax = max(amax, a);

        for(int i = 0; i <= h; i++) {
            dp[i + a] = min(dp[i + a], dp[i] + b);
        }
    }

    int ans = INF;
    for(int i = h; i <= h + amax; i++) {
        ans = min(ans, dp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define debug(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
const LL INF64 = 1e18;

const int N = 1e5 + 5;

int arr[1005];

bool checker(int a) {
	string s = to_string(a);
	for (int i = 1; i < s.size(); i++) {
		if (s[i] - '0' != s[i - 1] - '0' + 1) return false;
	}
	return true;
}

int main() {
	int n;
	int ans = -1;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", arr + i);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (checker(arr[i] * arr[j]) && arr[i] * arr[j] > ans) {
				ans = arr[i] * arr[j];
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}
		


Measured memory_bytes: 3348
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
}

int main(void)
{
	int height[10] = {0};
	char line[8];
	int i;
	
	for (i = 0; i < 10; i++) {
		if (fgets(line, sizeof(line), stdin) == NULL) {
			break;
		}
		height[i] = atoi(line);
	}
	qsort(height, 10, sizeof(int), compare_int);
	
	printf("%d\n", height[0]);
	printf("%d\n", height[1]);
	printf("%d\n", height[2]);
	
	return 0;
}

Measured memory_bytes: 0
import sys

input = sys.stdin.readline


def main():
    A, B = map(int, input().split())
    if A == 1:
        A = 14
    if B == 1:
        B = 14

    if A == B:
        print("Draw")
    elif A > B:
        print("Alice")
    else:
        print("Bob")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;
	cin>>a>>b;
	if(a*b*1%2||a*b*2%2||a*b*3%2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		if(x % 11 == 0) {
			System.out.println(x / 11 * 2);
		} else if(x % 11 <= 6) {
			System.out.println(x / 11 * 2 + 1);
		} else {
			System.out.println(x / 11 * 2 + 2);
		}
	}
}


Measured memory_bytes: 22612
N = int(input())
XYH = [tuple(map(int, input().split())) for _ in range(N)]
sXYH = sorted(XYH, key=lambda x:x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x, y, h = sXYH[0]
        H = h + abs(x-cx) + abs(y-cy)
        res = []
        for x, y, h in sXYH[1:]:
            temp = (h == max(H-abs(x-cx)-abs(y-cy), 0))
            res.append(temp)
        if all(res):
            print(cx, cy, H)
            exit()


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

int main(){
  int mid,fin,re;
  int cm,cf,cr;
  int s[50][3];
  for(int i=0;i<50;i++){
    for(int j=0;j<3;j++){
      cin >> s[i][j];
    }
    cin.ignore();
  }
  for(int i=0;i < 50;i++){
    for(int j=0;j<3;j++){
      cin >> s[i][j];
    }
    cin.ignore();
  }
  int i = 0;
  while(1){
    cm = s[i][0];
    cf = s[i][1];
    cr = s[i][2];
    if((cm==-1)&&(cf==-1)&&(cr==-1)){
      break;
    }else {
      if((cm==-1)||(cf==-1)){
	cout << "F"<<endl;
      }else{
	if(cm + cf >=80){
	  cout << "A"<<endl;
	}else if((cm + cf) >=65){
	  cout << "B" << endl;
	}else if((cm +cf) >= 50){
	  cout << "C" << endl;
	}else if((cm + cf) >=30){
	  if(cr >=50){
	    cout << "C" << endl;
	  }else{
	    cout << "D" << endl;
	  }
	}else{
	  cout << "F" << endl;
	}
      }
    }
    i = i + 1;
  }
  return 0;
}



Measured memory_bytes: 2964
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);
    StringTokenizer st = new StringTokenizer(in.readLine());
    int N = Integer.parseInt(st.nextToken()), K = Integer.parseInt(st.nextToken());
    st = new StringTokenizer(in.readLine());
    int[] A = new int[N];
    for (int i = 0; i < N; ++i) {
      A[i] = Integer.parseInt(st.nextToken());
    }

    HashMap<Integer, Integer> psumCt = new HashMap<>();
    psumCt.put(0, 1);
    int[] psum = new int[N + 1];
    long ans = 0;
    for (int i = 0; i < N; ++i) {
      if (i + 1 >= K) {
        int x = psum[i + 1 - K];
        psumCt.put(x, psumCt.get(x) - 1);
      }
      psum[i + 1] = (psum[i] + A[i] - 1) % K;
      int ct = psumCt.getOrDefault(psum[i + 1], 0);
      ans += ct;
      psumCt.put(psum[i + 1], ct + 1);
    }
    out.println(ans);

    out.close();
  }
}


Measured memory_bytes: 63448
#include <bits/stdc++.h>
using namespace std;
typedef long long int lo;

int main(){
    lo n;
    cin >> n;
    lo arr[n+1];
    lo dp[n+1];
    memset(dp,0,sizeof dp);
    for(lo i = 1;i <=n;i++) cin >> arr[i];
    arr[0] = 0;
    dp[1] = 0;
    dp[0] = 1e9;
    for(lo i = 2;i <= n;i++){
        dp[i] = min(abs(arr[i] - arr[i-1]) + dp[i-1], abs(arr[i] - arr[i-2]) + dp[i-2]);
        cerr << dp[i] << " " << i << endl;
    }
    cout << dp[n];
}

Measured memory_bytes: 1792
S = input()
ans = "AC"
if S[0] != "A":
  ans = "WA"
else:
  count_c = 0
  for i in range(1,len(S)):
    if 2 <= i <= len(S)-2 and S[i] == "C":
      count_c += 1
      continue
    if not S[i].islower():
      ans = "WA"
  if count_c != 1:
    ans = "WA"
print(ans)


Measured memory_bytes: 3060
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections, TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Char
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


------------------
-- #   Read   # --
------------------

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    n <- readLn :: IO Int
    print $ ceiling (fromIntegral n / 1000)*1000 - n



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

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

  int val = 0;
  string ladd = "";
  rep(i, N) {
    if (S[i] == '(') {
      val++;
    } else {
      val--;
      if (val < 0) {
        ladd += '(';
        val++;
      }
    }
  }
  S = ladd + S;
  rep(i, val) S += ')';

  cout << S << endl;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */


int main(){
    int r; cin >> r;
    setpre(10); out(r*2*M_PI);
}


Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;


int main(){
  int N,M;
  cin >> N >> M;
  vector<pair<ll,ll>> AB(N);
  rep(i, N){
    cin >> AB[i].first >> AB[i].second;
  }
  sort(AB.begin(),AB.end());
  ll m=0; int itr=0;
  while(1){
    m += AB[itr].second;
    if(m>M){m-=AB[itr].second; break;}
    itr++;
  }
  ll ans=0;
  rep(i,itr){
    ans += AB[i].first * AB[i].second;
  }
  ans += AB[itr].first*(M-m);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
#define int long long int
#define mod 998244353
int power(int a,int b)
{
	if(b==0)
	  return 1;
    else
    {
		int r=power(a,b/2);
		r=r%mod;
		r=r*r;
		r=r%mod;
		if(b%2==0)
		   return r;
		else
		{
			r=r*a;
			r=r%mod;
			return r;
		}
	}
}
int32_t main()
{
     string str;
     cin>>str;
     if(str[2]==str[3]&&str[4]==str[5])
        cout<<"Yes"<<endl;
     else
       cout<<"No"<<endl;   
}


Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut x = s.trim().parse::<i64>().unwrap();
    let mut ans = x / 500 * 1000;
    x %= 500;
    x = x / 5 * 5;

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


Measured memory_bytes: 4352
// High above the clouds there is a rainbow...
 
#include<bits/stdc++.h>
 
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxn=2010,mod=1e9+7;
const ll inf=1e18;
 
string s;
vector<int>v[maxn];
int cnt[maxn];
ll dp[maxn],sig[maxn];
 
void dfs(int u,int par=-1){
    cnt[u]= s[u-1]=='1';
    sig[u]=0;
    for(int y:v[u]){
	if(y!=par){
	    dfs(y,u);
	    cnt[u]+=cnt[y];
	    sig[u]+=sig[y]+cnt[y];
	}
    }
}
 
void calc(int u,int par=-1){
    int mxy=-1;
    for(int y:v[u]){
	if(y!=par){
	    calc(y,u);
	    if(mxy==-1 || (mxy!=-1 && sig[y]+cnt[y]>sig[mxy]+cnt[mxy])) mxy=y;
	}
    }
    if(mxy==-1){
	dp[u]=0;
	return;
    }
    ll sm=sig[u]-sig[mxy]-cnt[mxy];////
    if(sm>=dp[mxy]+cnt[mxy]){
	dp[u]=sig[u] & 1;
    }
    else{
	dp[u]=dp[mxy]+cnt[mxy]-sm;
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n>>s;
    for(int i=0;i<n-1;i++){
	int a,b;cin>>a>>b;
	v[a].PB(b);
	v[b].PB(a);
    }
    ll ans=inf;
    for(int i=1;i<=n;i++){
	dfs(i);
	if(sig[i] & 1) continue;
	calc(i);
	if(dp[i]==0) ans=min(ans,sig[i]/2);
    }
    if(ans==inf) ans=-1;
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//







int main(void) {

    ll X, Y, Z; cin >> X >> Y >> Z;
    X -= 2 * Z;
    ll ans = X / (Y + Z);
    if (Y <= X - X / (Y + Z) * (Y + Z)) {
        ++ans;
    }
    out(ans);

    
    
    return 0;
}











Measured memory_bytes: 256