akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
ll inf=1e18;
int mod=1e9+7;
vector<int>G[200000];
int dp[100005][105][2];
int vis[200000];
int n,d;
vector<int>num;
void numm(string s)
{
    num.clear();
    int len=s.length();
    for(int i=0;i<len;i++){
        num.pb(s[i]-'0');
    }
    n=len;
}
int fun(int pos,int rem,int f)
{
    if(pos==n)
    {
        return rem==0;
    }
    if(dp[pos][rem][f]!=-1)
        return dp[pos][rem][f];
    int ans=0;
    if(!f)
    {
        for(int i=0;i<num[pos];i++)
        {
            ans+=fun(pos+1,(rem+i)%d,1);
            ans%=mod;
        }
        ans+=fun(pos+1,(rem+num[pos])%d,0);
        ans%=mod;
    }
    else
    {
        for(int i=0;i<10;i++)
        {
             ans+=fun(pos+1,(rem+i)%d,1);
             ans%=mod;
        }
    }
    return dp[pos][rem][f]=ans;
}

int main()
{
//    READ;
    string s;
    cin>>s;
    sf(d);
    numm(s);
    mem(dp,-1);
    cout<<(fun(0,0,0)-1+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 87936
#include<bits/stdc++.h>
using namespace std;
#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(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n,m;
  cin>>n>>m;
  typedef pair<int,int> pair;
  vector<pair> city;
  vector<int> yi;
  REP(i,m){
    int p,y;
    cin>>p>>y;
    yi.emplace_back(y);
    city.emplace_back(make_pair(p,y));
  }

  sort(ALL(city),[](const pair& x, const pair& y){return x.second < y.second;});
  map<int,int> mp;
  map<int,ll> num;
  REP(i,m){
    mp[city[i].first]++;
    num[city[i].second]=ll(city[i].first)*1000000+mp[city[i].first];
  }
  for(int i:yi){
    printf("%012lld\n",num[i]);
  }

  return 0;
}

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

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

  if(st[0]=='S') cout << "Cloudy" << endl;
  if(st[0]=='C') cout << "Rainy" << endl;
  if(st[0]=='R') cout << "Sunny" << endl;
  return 0;
}

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

class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<Double> ans = new ArrayList<Double>();
		
		while (true) {
			
			int x = Integer.parseInt(br.readLine());
			int h = Integer.parseInt(br.readLine());
			
			if (x == 0 && h == 0) break;
			ans.add(x * x + x * Math.sqrt(4.0 * h * h + x * x));
			
		}
		
		for (double d : ans) {
			System.out.printf("%.6f\n", d);
		}
		
	}
	
}

Measured memory_bytes: 11000
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef long long int lli;

int main(){
    //初期化
    int flag1;
    lli N, *M, *H,cnt, i, j;
    cnt = 0;

    //処理
    scanf("%lld", &N);
    M = (lli *)malloc(sizeof(lli) * (N+1));
    H = (lli *)malloc(sizeof(lli) * N);
    for(i=0; i<N+1; i++)scanf("%lld", &M[i]);
    for(i=0; i<N; i++)scanf("%lld", &H[i]);
    for(i=N-1; i>-1; i--)
    {
        for(j=1; j>-1; j--)
        {  
        	if(M[i+j] > H[i])
        	{
            	cnt += H[i];
            	M[i+j] -= H[i];
            	H[i] = 0;
        	}else{
            	cnt += M[i+j];
            	H[i] -= M[i+j];
            	M[i+j] = 0;
            }
        }
    }
    fprintf(stdout, "%lld\n", cnt);
    
    //事後処理
    free(M);
    free(H);
}

Measured memory_bytes: 1664
import qualified Data.Foldable as F
import qualified Data.List     as L
import           Data.Monoid

main :: IO ()
main = do
    n <- readLn :: IO Int
    xs <- map read.words <$> getLine
    case solve n xs of
        Just ys -> putStr . unlines $ map show ys
        Nothing -> print (-1)

solve :: Int -> [Int] -> Maybe [Int]
solve n xs = go [] xs
  where
    eq :: Int -> Int -> Maybe Int
    eq x y
        | x == y = Just x
        | otherwise = Nothing

    go acc [] = Just acc
    go acc xs = do
        x <- getLast . F.foldMap Last $ zipWith eq [1..] xs
        go (x:acc) $ L.delete x xs


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
 
  if(A == B && B == C){
    cout << "No";
  }
  else if(A == B || A == C || B == C){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

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

int main() {
    int n;
    cin >> n;
    int two = 0, four = 0;

    int ans = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        if (a % 4 == 0)
            four++;
        else if (a % 2 == 0)
            two++;
    }

    if (n == two || n / 2 <= four + two / 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3604
def calc_cost(i,j,c)
    return (i-j)**2+c
end

def f(a1,b1,a2,b2,a3,b3)
    return (b3-b2)*(a2-a1) >= (b2-b1)*(a3-a2)
end

n,c = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
dp = Array.new(n,0)
a = [0]
for i in 1..n-1
    while a.size > 1 && calc_cost(h[i],h[a[0]],dp[a[0]]) > calc_cost(h[i],h[a[1]],dp[a[1]])
        a.shift
    end
    dp[i] = calc_cost(h[i],h[a[0]],dp[a[0]])+c
    while a.size > 1 && f(-2*h[a[-2]],dp[a[-2]]+h[a[-2]]**2,-2*h[a[-1]],dp[a[-1]]+h[a[-1]]**2,-2*h[i],dp[i]+h[i]**2)
        a.pop
    end
    a.push(i)
end
p dp[-1]

Measured memory_bytes: 19092
def solve():
    n = int(input())
    a = list(map(int, input().split()))

    b = a[1::2]
    c = a[::2]
    
    if len(a)%2 == 0:
        return b[::-1] + c
    else:
        return c[::-1] + b
    

print(*solve())


Measured memory_bytes: 26180
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;
#define PI 3.141592653589793


int main(){
  int K; cin >> K;
  int N = (((K-1)/4)+1)*2;
  int ans[N][N];
  if(K<=500){
    cout << K << endl;
    rep(i, K){
      rep(j, K){
        cout << (i+j)%K+1; cout << " ";
      }
      cout << endl;
    }
    return 0;
  }
  rep(i, N){
    rep(j, N){
      if(i%2==0) ans[i][j] = (i+j)%N+1;
      else ans[i][j] = (i+j)%N+N+1;
      if(ans[i][j]>K) ans[i][j]-=N;
    }
  }
  cout << N << endl;
  rep(i, N){
    rep(j, N){
      cout << ans[i][j]; cout << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 2176
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int mod = 2019;
int main() {
	string S;
	cin >> S;
	int N = S.size();
	vector<int> pw(N + 1);
	pw[0] = 1;
	for (int i = 1; i <= N; ++i) {
		pw[i] = pw[i - 1] * 10 % mod;
	}
	vector<int> sum(N + 1);
	for (int i = 0; i < N; ++i) {
		sum[i + 1] = (sum[i] * 10 + int(S[i] - '0')) % mod;
	}
	for (int i = 0; i <= N; ++i) {
		sum[i] = (sum[i] * pw[N - i]) % mod;
	}
	vector<int> c(mod);
	for (int i = 0; i <= N; ++i) {
		++c[sum[i]];
	}
	long long ans = 0;
	for (int i = 0; i < mod; ++i) {
		ans += 1LL * c[i] * (c[i] - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5196
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> s = new ArrayList<>();
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            s.add(x);
            sum += x;
        }
        Collections.sort(s);
        boolean ok = true;
        for (int i = 0; i < n; i++) {
            if (s.get(i) % 10 != 0) {
                ok = false;
            }
        }
        for (int i = 0; i < n; i++) {
            if (sum % 10 != 0) {
                break;
            }
            if (s.get(i) % 10 == 0) {
                continue;
            }
            sum -= s.get(i);
        }
        if (ok) {
            System.out.println(0);
            return;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin >> n;
	long long arr[n];
	for(long long i = 0; i < n; i++){
		cin >> arr[i];
	}
//	for(int i = -10; i <= 10; i++){
//		int sum = 0;
//		for(int j = 0; j < n; j++){
//			sum += abs(arr[j]- (i+j+1));
//		}
//		cout << i <<" "<<sum << endl;
//	}
	long long lo = -1e12, hi = 1e12, le, ri, take;
	while(lo <= hi){
		le = lo + (hi-lo)/3;
		ri = hi -  (hi-lo)/3;
		long long sumle = 0, sumri = 0;
		for(long long i = 0; i < n; i++){
			sumle += abs(arr[i]-le-1-i);
			sumri += abs(arr[i]-ri-1-i);
		}
		if(sumle < sumri){
			take = sumle;
			hi = ri-1;
		}else{
			take = sumri;
			lo = le+1;
		}
	}
	cout << take << endl;
}

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

int main(){
    ll a, b, k;
    cin >> a >> b >> k;

    if(a>k){
        cout << a-k << " " << b << endl;
    }

    else{
        if(b+a-k >=0){
        cout << 0 << " " << b+a-k << endl;
        }
        else{
            cout << 0 << " " << 0 << endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define eb emplace_back
int main()
{
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    lli t,q,n,m,i,j,a,b,h;
    cin>>n;
    lli ar[100001],cost[100001];
    for(i=1;i<=n;i++)
        cin>>ar[i];
    cost[0]=0;
    cost[1]=0;
    cost[2]=abs(ar[1]-ar[2]);
    for(i=3;i<=n;i++)
        cost[i]=min(cost[i-1]+abs(ar[i-1]-ar[i]),cost[i-2]+abs(ar[i-2]-ar[i]));
    cout<<cost[n];
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#define N 10000
#define Q 500

int main(){
  int i,j,n,q;
  int S[N],T[Q],count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
    for(i=0;i<n;i++){
      if(S[i]==T[j]){
	count++;
	break;
      }
    }
  }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int k;
int main(void){
	ll ans=0;
	cin>>k;
	FORN(a,1,k+1){
		FORN(b,1,k+1){
			FORN(c,1,k+1){
				int x=__gcd(a,b);
				ans+=__gcd(x,c);
//				cout<<__gcd(x,c)<<' '<<a<<' '<<b<<' '<<c<<endl;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#define INT_MAX 100000000
using namespace std;
int index;
int mm[1000][1000];
int mine = INT_MAX;

void solve(int p[]){
  int n = index-1,j,q;
  for(int i=1;i<=n;i++)mm[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      j = i+l-1;
      mm[i][j] = INT_MAX;
      for(int k=i;k<=j-1;k++){
	q = mm[i][k] + mm[k+1][j] + p[i-1]*p[k]*p[j];
	if(q<mm[i][j]){
	  mm[i][j] = q;
       
	}

      }
    }
  }




}

int main(){
  int p[1000],a,b;
  scanf("%d",&index);
  //for(int i=0;i<=index;i++)for(int j=0;j<=n;j++)mm[i][j] = INT_MAX;
  for(int i=0;i<index;i++){
    scanf("%d %d",&a,&b);
    p[i] = a;
    if(i == index-1)p[i+1] = b;
  }

  index = index+1;
  solve(p);
 
  printf("%d\n",mm[1][index-1]);
  return 0;
}

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

int main() {
    string S;
    cin >> S;
    ll N= S.size();
    if(N==2){
        if(S[0] == S[1]){
            cout << 1 <<" "<< 2 << endl;
        }else{
            cout << -1 <<" "<<-1 << endl;
        }
        return 0;
    }
    for(int i=0;i<N-2;i++){
        set<char> s;
        for(int j=0;j<3;j++){
            s.insert(S[i+j]);
        }
        if(s.size() != 3){
            cout << i+1 <<" "<<i+3 << endl;
            return 0;
        }
    }
    cout << -1 <<" " <<-1 << endl;

    return 0;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;
const int inf = 1001001001;



int main(void) {
  int r,d,x;
  cin >> r >> d >> x;
  vi a(11);
  a[0] = x;
  rep(i,10){
    a[i+1] = a[i]*r-d;
    cout << a[i+1] << endl;
  }
  
    
}


Measured memory_bytes: 256
//In the name of Allah

#include <bits/stdc++.h>

using namespace std;

const int N = 105;

char s1[N], s2[N];

int main() {
  scanf("%s", s1);
  scanf("%s", s2);
  if (strlen(s1) > strlen(s2)) {
    puts("GREATER");
  }
  else if (strlen(s1) < strlen(s2)) {
    puts("LESS");
  }
  else {
    for (int i = 0; i < strlen(s1); i++)  {
      if (s1[i] > s2[i]) {
        puts("GREATER");
        return 0;
      }
      else if (s2[i] > s1[i]) {
        puts("LESS");
        return 0;
      }
    }
    puts("EQUAL");
  }
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<char, int> mp[n];
    string str;
    rep(i, n){
        cin >> str;
        rep(j, str.size()){
            mp[i][str[j]]++;
        }
    }
    for(auto ch : mp[0]){
        int mincnt = 51;
        rep(i, n){
            if(!mp[i].count(ch.first)){
                mincnt = 0;
                break;
            }
            mincnt = min(mincnt, mp[i][ch.first]);
        }
        rep(i, mincnt) cout << ch.first;
    }
    cout << endl;
    return 0;
}

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

int main() {
    double a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f) {
        double x = (c * e - b * f) / (a * e - b * d), y = (c * d - a * f) / (b * d - a * e);
        x *= 1000;
        if (x >= 0) x = (double)(int)(x + 0.5);
        else x = (double)(int)(x - 0.5);
        x /= 1000;
        y *= 1000;
        if (y >= 0) y = (double)(int)(y + 0.5);
        else y = (double)(int)(y - 0.5);
        y /= 1000;
        cout << fixed << setprecision(3) << x  << ' ' << y << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3284
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let r: f64 = read();
    println!("{}", r * 2.0 * 3.14);
}

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

int main()
{
	int n;
	cin >> n;
	int c[3][n];
	int dp[3][n];
	for (int i = 0; i < n; ++i)
	{
		cin >> c[0][i] >> c[1][i] >> c[2][i];
	}
	dp[0][0] = c[0][0];
	dp[1][0] = c[1][0];
	dp[2][0] = c[2][0];

	for (int i = 1; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			dp[j][i] = max(dp[(j+1)%3][i-1], dp[(j+2)%3][i-1]) + c[j][i];
		}
	}

	cout << max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1]));
}

Measured memory_bytes: 2688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;

public class Main {
	public static void main(String[] a) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> al = new ArrayList<String>();
		String str;

		// 1???????????\?????????????????????????????????
		while ((str = br.readLine()) != null) {
			if (str.length() == 0) {
				break;
			}
			al.add(str);
		}

		BigDecimal[][] ans = new BigDecimal[al.size()][2];

		// ??£???????¨????
		int len = al.size();
		for (int i = 0; i < len; i++) {
			String[] buf = al.get(i).split(" ");

			// ???????????????1??????????????????????????°??????????????????
			double ax = Double.parseDouble(buf[0]);
			double by = Double.parseDouble(buf[1]);
			double c = Double.parseDouble(buf[2]);
			double dx = Double.parseDouble(buf[3]);
			double ey = Double.parseDouble(buf[4]);
			double f = Double.parseDouble(buf[5]);

			// y????±?????????????
			double ansY = yOperation(ax, by, c, dx, ey, f);

			// x????±?????????????
			double ansX = xOperation(ax, by, c, ansY);

			// ?°???°?????\????¬¬??????????????¨?????\???????????????????´?
			BigDecimal bdx = new BigDecimal(ansX);
			bdx = bdx.setScale(3, BigDecimal.ROUND_HALF_UP);
			BigDecimal bdy = new BigDecimal(ansY);
			bdy = bdy.setScale(3, BigDecimal.ROUND_HALF_UP);
			
			ans[i][0] = bdx;
			ans[i][1] = bdy;

		}

		// ??????
		for (int i = 0; i < ans.length; i++) {
			System.out.printf("%4.3f" + " " + "%4.3f" + "\n", ans[i][0],
					ans[i][1]);
		}
	}

	//y????¨????
	private static double yOperation(double ax, double by, double c,
			double dx, double ey, double f) {
		double ansY;
		try {
			ansY = (f + -(dx * c / ax)) / ((dx * -by / ax) + ey);
		} catch (ArithmeticException ae) {
			ansY = 0;
		}
		return ansY;
	}

	//x????¨????
	private static double xOperation(double ax, double by, double c,
			double y) {
		double ansX;
		try {
			ansX = (c + -(by * y)) / ax;
		} catch (ArithmeticException ae) {
			ansX = 0;
		}
		return ansX;
	}

}

Measured memory_bytes: 24860
import sys


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


def main():
    D, G = map(int, input().split())
    problems = [[None] * 2 for _ in range(D)]
    ans = float('inf')

    for i in range(D):
        problems[i] = list(map(int, input().split()))

    for bit in range(1 << D):
        score = 0
        solved = 0
        unsolved = set(range(D))
        for j in range(D):
            if bit & (1 << j):
                score += problems[j][0] * (j+1) * 100 + problems[j][1]
                solved += problems[j][0]
                unsolved.discard(j)

        if score < G:
            use = max(unsolved)
            n = min(problems[use][0]-1, -(-(G - score) // ((use + 1) * 100)))
            score += n * (use + 1) * 100
            solved += n

        if score >= G:
            ans = min(ans, solved)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43244
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

s = deque(stdin.readline().rstrip())
n = int(stdin.readline().rstrip())

flag = 0

for i in range(n):
    q = [x for x in stdin.readline().rstrip().split()]

    if len(q) == 1:
        flag = 1 - flag
    else:
        if (q[1] == "1" and flag == 0) or (q[1] == "2" and flag == 1):
            s.appendleft(q[2])
        else:
            s.append(q[2])

if flag == 1:
    s = ''.join(s)[::-1]
else:
    s = ''.join(s)
print (s)


Measured memory_bytes: 14392
import numpy as np
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = [0] + list(map(int,input().split()))
B = np.cumsum(A)
C = collections.Counter(B)
ans = 0
for i in C:
    if C[i] >= 2:
        ans += combinations_count(C[i], 2)
print(ans)


Measured memory_bytes: 45900
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int W,H;
int x,y;
int main(){
	cin >> W >> H >> x >> y;
	cout << (double)W*(double)H/2.0 << ' ';
	if(2*x==W&&2*y==H)cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}

fn binary_power(x: u64, n: u64) -> u64 {
    if n == 0 {
      return 1;
    }
    if n % 2 == 0 {
      return (binary_power(x, n / 2) % MOD).pow(2) % MOD;
    } else {
      return binary_power(x, n - 1) % MOD * x % MOD;
    }
}
  
fn inverse_mod(n: u64) -> u64 {
    binary_power(n, MOD-2)
}  

fn combination(n: u64, mut m: u64) -> u64 {
    if n < m {
        return 0;
    }
    
    if m > n - m {
        m = n - m
    }

    let mut ret = 1u64;
    for i in 0..m {
        ret %= MOD;
        ret *= n - i;        
    }
    ret %= MOD;

    let mut div = 1u64;
    for i in 1..(m+1) {
        div %= MOD;
        div *= i;
    }
    div %= MOD;

    // println!("{}, {}", ret, div);
    ret * inverse_mod(div) % MOD
}



fn main() {
    let (n, a, b) = input_tuple();
    let ans = binary_power(2, n) + MOD - combination(n, a) + MOD - combination(n, b);

    println!("{}", (ans - 1) % MOD);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int n = 52;
int m = 22;
vector<vector<int>> tree(n,vector<int>());
map<P,int> edge;
vector<P> con(m);
vector<bitset<52>> bs(m);

void dfs(int i,int v,bitset<52> now=0,int before=-1){
    if(before!=-1){
        if(v<before) now[edge[P(v,before)]] = 1;
        else now[edge[P(before,v)]] = 1;
    }
    if(v==con[i].second) bs[i] = now;

    for(int e:tree[v]){
        if(e==before) continue;
        dfs(i,e,now,v);
    }

    if(before!=-1){
        if(v<before) now[edge[P(v,before)]] = 0;
        else now[edge[P(before,v)]] = 0;
    }
}

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

int main(){
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
        if(a > b) swap(a,b);
        edge[P(a,b)] = i;
    }
    cin >> m;
    rep(i,m){
        cin >> con[i].first >> con[i].second;
        --con[i].first;--con[i].second;
    }

    rep(i,m) dfs(i,con[i].first);

    ll ans = 0;

    for(int bit=0;bit<(1<<m);bit++){
        bitset<52> now = 0;
        bool even = true;
        for(int k=0;k<m;k++){
            if(bit>>k & 1){
                now = now | bs[k];
                even = !even;
            }
        }
        int c = 0;
        rep(i,n-1) c += now[i];
        c = (n-1) - c;
        if(even) ans += modpow(2,c);
        else ans -= modpow(2,c);
    }

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


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int D;
  cin >> D;
  vector<int> c(26);
  for (auto &it : c)
    cin >> it;
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < D; i++)
  {
    for (int j = 0; j < 26; j++)
    {
      cin >> s[i][j];
    }
  }

  vector<ll> last(26, 0);
  vector<ll> t(D);

  ll score = 0;
  for (int i = 0; i < D; i++)
  {
    ll now = 0;
    ll best_contest = 0;
    for (int co = 0; co < 26; co++)
    {
      ll tmp = 0;
      vector<ll> this_last = last;
      this_last[co] = i + 1;
      tmp += s[i][co];
      for (int j = 0; j < 26; j++)
      {
        tmp -= c[j] * ((i + 1) - this_last[j]);
      }
      if (tmp > now)
      {
        now = max(now, tmp);
        best_contest = co;
      }
    }
    last[best_contest] = i + 1;
    score += now;
    cout << best_contest + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

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

    ll sum = 0;
    ll a = 1;
    while (sum < X) {
        sum += a;
        a++;
    }
    cout << (a - 1) << endl;
}

Measured memory_bytes: 3524
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <cmath>

using namespace std;

vector<int> price;
list<int> primes;

const int M = 1000000;
const int L = 30;
const int D = 10;
const int S = M/D;
pair<int,int> memo[S][L];

void mk_primes(int x)
{
	for( int i = 3; i <= x; i+=2 ) {
		for( int j = 3; j <= sqrt(i); j++ ) {
			if( i % j == 0 ) {
				goto NEXT;
			}
		}
		primes.push_front(i);
	NEXT:;		
	}
}

int solve(int x, int pos)
{
	pair<int,int>& pa = memo[x%S][pos];
	if( pa.first == x && -1 < pa.second )
		return pa.second;

	int result = 0;

	int p = price[pos++];
	int s = x / p;

	if( price.size() == pos ) {

		if( s*p == x ) {
			result = 1;
			// cout << "(" << p << "*" << s << ")";
		}
		
		
	} else {

		for( int i = 0; i <= s; i++ ) {

			int t = i * p;
			result = solve(x-t, pos);
			if( result ) {
				// cout << "(" << p << "*" << i << ")";
				break;
			}
		}
	}

	pa.first = x;
	pa.second = result;
	return result;
}

int main(int argc, char* argv[])
{
	mk_primes(M);
	
	while(1) {

		int n; cin >> n;
		int x; cin >> x;

		if( n == 0 && x == 0)
			break;
	
		for( int i = 0; i < n; i++ ) {
			int p; cin >> p;
			price.push_back(p);
		}

		for( int i = 0; i < S; i++ ) {
			for( int j = 0; j < L; j++ ) {			
				memo[i][j] = make_pair(-1,-1);
			}
		}

		for( auto p : primes ) {

			if( x < p )
				continue;
			
			if( solve(p, 0) ) {
				cout << p << endl;
				goto LAST;
			}
		}

		cout << "NA" << endl;

	LAST:;

		price.clear();

	}

    return 0;
}

Measured memory_bytes: 28960
N,M = map(int,input().split())
A = []
B = []
for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())

if N == M:
    for i in range(N):
        if A[i] != B[i]:
            print("No")
            exit()
    print("Yes")
    exit()

for i in range(N-M):
    for j in range(N-M):
        if B[0] == A[i][j:j+M]:
            if M == 1:
                print("Yes")
                exit()
            for k in range(1,M):
                if B[k] != A[i+k][j:j+M]:
                    break
                if k == M-1:
                    print("Yes")
                    exit()
print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    long long n,r;
    while(~scanf("%lld",&n))
    {
        r=sqrt(n);
        if(r*r==n)
            printf("%lld\n",n);
        else
            printf("%lld\n",r*r);
    }
}


Measured memory_bytes: 128
N = int(input())
a = [int(input()) - 1 for _ in range(N)]
seen = [0] * N
seen[0] = 1
i = 0
ans = 1
while a[i] != 1:
    i = a[i]
    if not seen[i]:
        ans += 1
        seen[i] = 1
    else:
        break
else:
    print(ans)
    exit()
print(-1)


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

int main (void){
  int x[5];
  int y[5];

  cin >> x[0] >> y[0] >> x[1] >> y[1];

  double l = 0,g = 0,j = 0,h = 0;
  int a = 0,b = 0;
  a = x[0] - x[1];
  b = y[0] - y[1];
  x[2] = b + x[1];
  y[2] = -a + y[1];
  a = x[1] - x[0];
  b = y[1] - y[0];
  x[3] = -b + x[0];
  y[3] = a + y[0];

  cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;

  return 0;


}

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

int main()
{
    int w, h, n;
    int x, y, a;
    cin >> w >> h >> n;
    int minx = 0, miny = 0, maxx = w, maxy = h;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y >> a;
        if (a == 1 && minx < x)
            minx = x;
        if (a == 2 && maxx > x)
            maxx = x;
        if (a == 3 && miny < y)
            miny = y;
        if (a == 4 && maxy > y)
            maxy = y;
    }
    int ans = (maxx - minx) * (maxy - miny);
    if ((maxx - minx) < 0 || (maxy - miny) < 0)
        ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int c[55][55],v[55];
int n,A,B;
long long int sum, num, val;
int main(){
	cin>>n>>A>>B;
	for(int i=0; i<=n; i++)
		for(int j=0; j<=i; j++)
			c[i][j] = j==0||j==i?1:c[i-1][j]+c[i-1][j-1];
	for(int i=0; i<n; i++)
		cin>>v[i];
	sort(v,v+n);
	reverse(v,v+n);
	sum = 0;
	num = 1;
	val = 0;
	for(int i=A; i<=B; i++){
		long long int tot = 0;
		long long int AA = 0, BB = 0;
		for(int j=0; j<n; j++)
			if(v[j] == v[i-1])AA++;
		for(int j=0; j<i; j++){
			tot += v[j];
			if(v[j] == v[i-1])BB++;
		}
		long long int qq = c[AA][BB];
		if(tot * num > sum * i){
			sum = tot;
			num = i;
			val = qq;
		}else
		if(tot * num == sum * i){
			val += qq;
		}
	}
	printf("%lf\n", (double)(sum) / num);
	fflush(stdout);
	cout<<val<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n, m int
	fmt.Sscan(getNextLine(scanner), &n, &m)
	wars := make(Wars, m)
	for i := 0; i < m; i++ {
		ab := getIntList(scanner)
		wars[i].a = ab[0]
		wars[i].b = ab[1]
	}
	sort.Sort(wars)
	min := -1
	count := 0
	for i := 0; i < m; i++ {
		if min <= wars[i].a {
			count++
			min = wars[i].b
			continue
		}
		if min > wars[i].b {
			min = wars[i].b
		}
	}
	fmt.Println(count)
}

type War struct {
	a int
	b int
}
type Wars []War

func (a Wars) Len() int      { return len(a) }
func (a Wars) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Wars) Less(i, j int) bool {
	if a[i].a == a[j].a {
		return a[i].b < a[j].b
	}
	return a[i].a < a[j].a
}


Measured memory_bytes: 4992
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().rstrip()

    R = []
    G = []
    B = []
    for i in range(N):
        if S[i] == "R":
            R.append(i)
        elif S[i] == "G":
            G.append(i)
        else:
            B.append(i)

    n_R = len(R)
    n_G = len(G)
    n_B = len(B)
    ans = n_R * n_G * n_B
    if ans == 0:
        print(ans)
        exit()

    for r in R:
        for g in G:
            rg = sorted([r, g])
            dist = rg[1] - rg[0]
            if 0 <= rg[0] - dist:
                if S[rg[0] - dist] == "B":
                    ans -= 1
            if rg[1] + dist <= N - 1:
                if S[rg[1] + dist] == "B":
                    ans -= 1
            if dist % 2 == 0:
                if S[rg[0] + (dist // 2)] == "B":
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9296
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int x;
    cin >> x;

    int ans = -1;
    if(x>=1800) ans = 1;
    else if(x>=1600) ans = 2;
    else if(x>=1400) ans = 3;
    else if(x>=1200) ans = 4;
    else if(x>=1000) ans = 5;
    else if(x>=800) ans = 6;
    else if(x>=600) ans = 7;
    else if(x>=400) ans = 8;

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

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

Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char B[1 << 15], *S = B, *T = B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 110
struct Edge
{
	Edge *next;
	int to;
}*last[maxn], e[1100000], *ecnt = e;
inline void link(R int a, R int b)
{
	*++ecnt = (Edge) {last[a], b}; last[a] = ecnt;
	*++ecnt = (Edge) {last[b], a}; last[b] = ecnt;
}
int f[1024][10];
bool inq[1024][10];
struct Queue
{
	int now, st;
};
std::queue<Queue> q;
int main()
{
//	setfile();
	R int n = F(), m = F();
	for (R int i = 1; i <= m; ++i) link(F(), F());
	f[1][1] = 1; q.push((Queue) {1, 1});
	int ans = 0;
	while (!q.empty())
	{
		R Queue now = q.front(); q.pop(); inq[now.st][now.now] = 0;
		if (now.st == (1 << n) - 1) {++ans; continue;}
		for (R Edge *iter = last[now.now]; iter; iter = iter -> next)
			if ((now.st & (1 << (iter -> to - 1))) == 0)
			{
				int ns = now.st | (1 << (iter -> to - 1));
				q.push((Queue) {iter -> to, ns});
			}
	}
	printf("%d\n", ans );
	return 0;
}


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


int main(){
	ll d, goal;
	cin >> d >>goal;
	vector<ll> namber(d);
	vector<ll> bonus(d);
	ll min_problem = 9999999;
	for (int i = 0;i < d;i++){
		cin >> namber.at(i) >> bonus.at(i);
	}
	for (int i= 0;i < (1 << d);i++){
		ll counter = 0;
		ll summing = 0;
		for (int j = 0;j < d;j++){
			int nam_p = namber.at(j);
			if (i & (1<<j)){
				counter += nam_p;
				summing += (100 * (j+1) * nam_p + bonus.at(j));
			}
		}
		if (summing >= goal){
			min_problem = min(min_problem, counter);
		} else {
			for (int j = d-1; j >= 0; --j) {
				if (i & (1<<j)) continue;
				for (int k = 0; k < namber.at(j); ++k) {
					if (summing >= goal) break;
					summing += 100 * (j+1);
					counter++;
				}
			}
			min_problem = min(min_problem, counter);
		}
	}
	cout << min_problem << endl;
}

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

bool ask(int64_t a){;
	cout << "? " << a << endl;
	char c;
	cin >> c;
	return c == 'Y';
}

void ans(int64_t a){
	cout << "! " << a << endl;
}

int main(){
	if(ask(1e9)){
		int64_t a = 2;
		while(!ask(a)) a *= 10;
		ans(a / 2);
	}else{
		int64_t a = 1e8;
		while(!ask(a)) a /= 10;
		int64_t l = a, r = a * 10 - 1;
		while(1 < r - l){
			int64_t mid = (l + r) / 2;
			(ask(mid * 10) ? r : l) = mid;
		}
		ans(r);
	}
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    int n;cin>>n;
    vii a(n);
    FOR(i,n) {cin>>a[i].first;a[i].second=i;}
    sort(a.begin(),a.end());
    FOR(i,n) cout << a[i].second+1 << " ";

    return 0;
}



Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

P convert(int x) {
  P res;
  res.second = x % 10;
  while (x > 0) {
    res.first = x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  vector<vector<int>> cnt(10, vector<int>(10));
  for (int i = 1; i <= n; ++i) {
    P p = convert(i);
    cnt[p.first][p.second]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    P p = convert(i);
    ans += cnt[p.second][p.first];
  }
  cout << ans << endl;
}

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

long long int factorial(long long int n) {
    return (n==1 || n==0) ? 1: n * factorial(n - 1);  
} 

int main(){
	int t;
	// cin>>t;
	t =1;
	for (int z = 0; z < t; ++z)
	{	
		int n;
		cin>>n;
		int arr[n][2];
		for (int i = 0; i < n; ++i)
		{
			cin>>arr[i][0]>>arr[i][1];
		}
		int flag = 0;
		for (int i = 2; i < n; ++i)
		{	
			// cout<<arr[i][0]<<arr[i][1]<<endl;
			if ((arr[i][0] == arr[i][1]) && (arr[i-1][0] == arr[i-1][1]) && (arr[i-2][0] == arr[i-2][1]))
			{
				flag = 1;
				break;
			}
		}
		// cout<<n<<endl;
		if (flag == 1)
		{
			cout<<"Yes";
		}
		else cout<<"No";
	}
}


Measured memory_bytes: 3628
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\n';

void solve() {
    int x, y;
    cin >> x >> y;
    if((x == 1 and y == 2) or (x == 1 and y == 4)){
        cout << "Yes" << nl;
        return;
    }
    for(int i = x * 2; i <= x * 4; i += 2){
        if(i == y) {
            cout << "Yes" << nl;
            return;
        }
    }
    cout << "No" << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://beta.atcoder.jp/contests/agc026/tasks/agc026_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    for(int i = 0; i < N-1;){
        if(a[i] == a[i+1]){
            res++;
            i+=2;
        }else{
            i++;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
using namespace std;
int main()
{
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	int b=tx-sx,a=ty-sy;
	int x=0,y=0,flag=2;
	while(flag){
		while(x<a){cout<<'U';x++;}
		while(y<b){cout<<'R';y++;}
		cout<<(flag==2?"":"RDRD");
		while(x>0){cout<<'D';x--;}
		while(y>0){cout<<'L';y--;}
		cout<<"LU";
		flag--;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class E
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NK = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (N, K) = (NK[0], NK[1]);
            var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var l = 0;
            var r = (int)1e9;
            while (r - l > 1)
            {
                var m = (l + r) / 2;
                var sum = A.Sum(x => (x - 1) / m);
                if (sum <= K) r = m;
                else l = m;
            }

            Console.WriteLine(r);
        }
    }
}


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

struct pro{
	int p;
	int WA;
	bool AC;
};

int main(){
	int N,M;
	cin >> N >> M;
	vector<pro> P(N);
	for(int i=0;i<N;i++){
		P[i].p=1;
		P[i].WA=0;
		P[i].AC=false;
	}
	
	int ac=0,wa=0;
	
	for(int i=0;i<M;i++){
		int x;
		string S;
		cin >> x >> S;
		x--;
		if(P[x].AC)continue;
		if(S=="WA")P[x].WA++;
		else{
			ac++;
			wa+=P[x].WA;
			P[x].AC=true;
		}
	}
	cout << ac << " " << wa << endl;
	return 0;
}

Measured memory_bytes: 1408
N,C=gets.chomp.split(" ").map { |e| e.to_i }
record = Array.new(C+1).map { Array.new(2*(10**5)+2,0)}
b = Array.new(2*(10**5)+2,0)


N.times do |i|
  s,t,c=gets.chomp.split(" ").map { |e| e.to_i }

  for j in 2*s-1..2*t do
    record[c][j] = 1
  end
end


for i in 1..C do
  for j in 0..2*(10**5)+1 do
    b[j] += record[i][j]
  end
end

max = -10**9

for i in 0..2*(10**5)+1 do
  max = max > b[i] ? max : b[i]
end

puts max

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

template <typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;
    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while (sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) { seg[k + sz] = x; }

    void build() {
        for (int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while (k >>= 1) {
            seg[k] = f(seg[2 * k], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, seg[a++]);
            if (b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const { return seg[k + sz]; }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    SegmentTree<int> seg(N, [](int a, int b) { return min(a, b); }, INT_MAX);
    for (int i = 0; i < Q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            seg.update(x, y);
        } else {
            cout << seg.query(x, y + 1) << endl;
        }
    }
}


Measured memory_bytes: 3856
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

X = INT()

if 400 <= X < 600:
    print(8)
elif 600 <= X < 800:
    print(7)
elif 800 <= X < 1000:
    print(6)
elif 1000 <= X < 1200:
    print(5)
elif 1200 <= X < 1400:
    print(4)
elif 1400 <= X < 1600:
    print(3)
elif 1600 <= X < 1800:
    print(2)
else:
    print(1)


Measured memory_bytes: 9528