akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int h,w;
    cin>>h>>w;
    int dp[10][10];
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>dp[i][j];
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<h*w;i++){
        int a; cin>>a;
        if(a==-1)continue;
        ans+=dp[a][1];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <deque>

int64_t cross(std::tuple<int64_t, int64_t> p0, std::tuple<int64_t, int64_t> p1, std::tuple<int64_t, int64_t> p2) {
    auto vx1 = std::get<0>(p1) - std::get<0>(p0);
    auto vy1 = std::get<1>(p1) - std::get<1>(p0);

    auto vx2 = std::get<0>(p2) - std::get<0>(p0);
    auto vy2 = std::get<1>(p2) - std::get<1>(p0);

    return vx1 * vy2 - vx2 * vy1;
}

int main(){
    int64_t n;
    std::cin >> n;

    std::vector< std::tuple<int64_t, int64_t> > vs(n);
    for (auto i = 0; i < n; ++i) {
        std::cin >> std::get<0>(vs[i]) >> std::get<1>(vs[i]);
    }
    std::sort(vs.begin(), vs.end(), [](std::tuple<int64_t, int64_t>lhs, std::tuple<int64_t, int64_t>rhs) {
        return (std::get<1>(lhs) < std::get<1>(rhs))
            || ((std::get<1>(lhs) == std::get<1>(rhs)) && (std::get<0>(lhs) < std::get<0>(rhs)) );
    });

    std::deque< std::tuple<int64_t, int64_t> > rights {vs[0], vs[1]};
    for (auto itr = std::next(std::next(vs.begin())); itr != vs.end(); ++itr) {
        while(rights.size() >= 2 && cross(*std::next(rights.rbegin()), *rights.rbegin(), *itr) < 0) {
            rights.pop_back();
        }
        rights.push_back(*itr);
    }
    std::deque< std::tuple<int64_t, int64_t> > lefts {*std::rbegin(vs), *std::next(vs.rbegin())};
    for (auto itr = std::next(std::next(vs.rbegin())); itr != vs.rend(); ++itr) {
        while(lefts.size() >= 2 && cross(*std::next(lefts.rbegin()), *lefts.rbegin(), *itr) < 0) {
            lefts.pop_back();
        }
        lefts.push_back(*itr);
    }
    rights.pop_back();
    lefts.pop_back();
    
    std::cout << rights.size() + lefts.size() << std::endl;

    for (auto itr = rights.begin(); itr != rights.end(); ++itr) {
        std::cout << std::get<0>(*itr) << ' ' << std::get<1>(*itr) << std::endl;
    }
    for (auto itr = lefts.begin(); itr != lefts.end(); ++itr) {
        std::cout << std::get<0>(*itr) << ' ' << std::get<1>(*itr) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 5420
from collections import Counter

n=int(input())
a=Counter(list(map(int,input().split())))
q=int(input())
sm=0
for x in a:
    sm+=x*a[x]

for i in range(q):
    b,c=map(int,input().split())
    if b in a:
        a[c]+=a[b]
        sm+=(c-b)*a[b]
        a[b]=0
    print(sm)


Measured memory_bytes: 21300
(stdin => {

  const I     = v => v
  const K     = v => _ => v
  const join  = sep => array => array.join(sep)
  const split = sep => str => str.split(sep)
  const print = fun => (f, v) => fun(f(v))
  // Define Function
  const getArea = (m, n) => m * n
  const getPerimeter = (m, n) => (m + n) * 2

  // Declare Variable
  const inputs = stdin.toString().trim().split('\n')
  const [a, b] = Array.from(inputs[0].split(' '), Number)
  // Main
  const result = [getArea(a, b), getPerimeter(a, b)]

  // Display
  const display = print(console.log)
  display(join(' '), result)

})(require('fs').readFileSync('/dev/stdin', 'utf8'))


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


int main()
{
	int x, y;

	while (true)
	{
		cin >> x >> y;

		if (x == 0 && y == 0) {
			break;
		}

		if (x > y) {
			int tmp = x;
			x = y;
			y = tmp;
		}

		cout << x << " " << y << endl;
	}

    return 0;
}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);

	int a, b, c, d, k;
	cin >> a >> b >> c >> d >> k;
	int x = 60 * a + b;
	int y = 60 * c + d;
	cout << y - x - k << "\n";

    return 0;
}


Measured memory_bytes: 3652
from fractions import gcd
from math import factorial, ceil, sqrt, atan2, log, pi, e, asin,acos, cos, sin, floor, atan
from itertools import *
from fractions import Fraction
import string
import copy
import random
import bisect
from decimal import *
from collections import deque
from sys import *
digs = string.digits + string.ascii_letters

def id_generator(size=20, chars=string.digits):
    return ''.join(random.choice(chars) for _ in range(size))
 
def mp():
    return map(int,str(raw_input()).strip().split())

n=input()
l=list(mp())
dp=[0 for i in range(n)]
for i in range(1,n):
	if i==1:
		dp[i]=dp[i-1]+abs(l[i]-l[i-1])
	else:
		dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]), dp[i-2]+abs(l[i]-l[i-2]))
print dp[-1]


Measured memory_bytes: 13936
use std::io::*;
use std::str::*;

struct Scanner<R: BufRead> {
    handle: R,
    buffer: Option<String>,
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
    fn new(input: R) -> Self {
        Scanner {
            handle: input,
            buffer: Some(String::new()),
        }
    }
    fn next<T: FromStr>(&mut self) -> T {
        let mut s = self.buffer.take().unwrap();
        s.clear();
        self.handle
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold((), |_, c| s.push(c));
        self.buffer = Some(s);
        match self.buffer.as_ref().unwrap().parse::<T>() {
            Ok(v) => v,
            _ => panic!("Scanner Error"),
        }
    }
    fn next_chars(&mut self) -> Vec<char> {
        let s: String = self.next();
        s.chars().collect()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let sc = &mut Scanner::new(stdin.lock());
    run(sc);
}

fn run(sc: &mut Scanner<StdinLock>) {
    let n: usize = sc.next();
    let m: usize = sc.next();
    let mut a = vec![(false, false); n + 1];
    for _ in 0..m {
        let x: usize = sc.next();
        let y: usize = sc.next();
        if x == 1 {
            a[y].1 = true;
        }
        if y == n {
            a[x].0 = true;
        }
    }
    if a.iter().any(|p| p.0 && p.1) {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 4476
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
	int N,h[100000],dp[100000];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>h[i];
		dp[i]=1000000;
	}
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	for(int i=2;i<N;i++){
		dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
	}
	cout<<dp[N-1]<<endl;
}

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

typedef long long LL;

const int N=18,M=262144,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,a[M+9];

void into(){
  scanf("%d",&n);
  for (int i=1<<n-1;i<1<<n;++i){
	scanf("%d",&a[i]);
    a[i]+=(1<<n-1)-1;
  }
}

int now[M+9];

void Dfs_now0(int k,int v){
  if (k>=1<<n-1){
	for (smul(v,k=a[k]);k;smul(v,k>>=1)) sadd(now[k],v);
    return;
  }
  Dfs_now0(k<<1,mul(v,k<<1));
  Dfs_now0(k<<1|1,mul(v,k<<1|1));
}

int Dfs_ans(int k,int v){
  if (k>=1<<n-1){
	int res=0,t=0;
	for (k=a[k];k;smul(v,k),t=mul(now[k],k>>1),k>>=1) sadd(res,mul(v,sub(now[k],t)));
	return res;
  }
  return add(Dfs_ans(k<<1,mul(v,k<<1)),Dfs_ans(k<<1|1,mul(v,k<<1|1)));
}

void Dfs_now1(int k){
  if (k>=1<<n-1){
	for (k=a[k];k;k>>=1) now[k]=0;
    return;
  }
  Dfs_now1(k<<1);
  Dfs_now1(k<<1|1);
}

int ans;

void Get_ans(){
  for (int i=1;i<1<<n-1;++i){
	Dfs_now0(i<<1,mul(i,i<<1));
	sadd(ans,Dfs_ans(i<<1|1,i<<1|1));
	Dfs_now1(i<<1);
  }
}

void work(){
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 5372
import sys

input = sys.stdin.readline

def south(dice):
    f, u, d, b = [dice["front"], dice["up"], dice["down"], dice["back"]]
    dice["front"] = u
    dice["up"] = b
    dice["down"] = f
    dice["back"] = d
    return dice

def north(dice):
    f, u, d, b = [dice["front"], dice["up"], dice["down"], dice["back"]]
    dice["front"] = d
    dice["up"] = f
    dice["down"] = b
    dice["back"] = u
    return dice

def west(dice):
    d, l, r, u = [dice["down"], dice["left"], dice["right"], dice["up"]]
    dice["down"] = l
    dice["left"] = u
    dice["right"] = d
    dice["up"] = r
    return dice

def east(dice):
    d, l, r, u = [dice["down"], dice["left"], dice["right"], dice["up"]]
    dice["down"] = r
    dice["left"] = d
    dice["right"] = u
    dice["up"] = l
    return dice

def show(dice):
    print(" ", dice["up"], " ")
    print(dice["left"], dice["front"], dice["right"], dice["back"])
    print(" ", dice["down"], " ")
    print()

def init_dice(dice_data):
    return {
        "front": dice_data[1], "back": dice_data[4],
        "up": dice_data[0], "right": dice_data[2], "down": dice_data[5], "left": dice_data[3]
    }

def main():
    pos = list(map(int, input().split()))
    move = input().rstrip()
    dice = init_dice(pos)
    for i in move:
        if i == "W":
            dice = west(dice)
        elif i == "S":
            dice = south(dice)
        elif i == "N":
            dice = north(dice)
        elif i == "E":
            dice = east(dice)

    print(dice["up"])
    
if __name__ == "__main__":
    main()


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

int main(){
  int N, sum_a=0, sum_b=0;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  
  for(int i=0; i<N; i+=2){
    sum_a+=A.at(i);
  }
  for(int i=1; i<N; i+=2){
    sum_b+=A.at(i);
  }
  cout << sum_a-sum_b << endl;
}

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

namespace Aojx
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string s;
            while ((s = Console.ReadLine()) != null)
            {
                Console.WriteLine("3C{0:00}", (int.Parse(s) - 1) % 39 + 1);
            }
        }
    }
}

Measured memory_bytes: 5688
#include<stdio.h>
#define BOUNDARY 1
int main()
{
	char topping[4];
	scanf("%s", topping);
	int counter = 0;
	int i;
	for (i = 0; i < 3; i++)
		if (topping[i] == 'o')
			counter++;
	printf("%d", 700 + 100 * counter);
	return 0;
}

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

int main()
{
  int N, num;
  int same = 0;
  scanf("%d", &N);
  vector<int> d(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%d", &d.at(i));
  }
  sort(d.begin(), d.end());
  for (int i = 1; i < N; i++)
  {
    if (d.at(i-1)==d.at(i))
    {
      same++;
    }
  }
  printf("%d\n", N - same);
}


Measured memory_bytes: 256
N, A, B, K = map(int, input().split())
MOD = 998244353

fact = [1]*(N+1)
rev = [1]*(N+1)
for i in range(1, N+1):
    fact[i] = fact[i-1]*i % MOD
    rev[i] = pow(fact[i], MOD-2, MOD)

ans = 0
for a in range(N+1):
    if (K - a*A) >= 0 and (K - a*A) % B == 0:
        b = (K - a*A) // B
        if not 0 <= b <= N:
            continue
        ans += rev[a]*rev[N-a] * rev[b]*rev[N-b]
        ans %= MOD
ans *= fact[N]*fact[N]
ans %= MOD
print(ans)

Measured memory_bytes: 45676
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
//typedef pair<long long,long long> P;
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,C;
  cin>>n>>C;
  int d[C][C];
  REP(i,C){
    REP(j,C){
      cin>>d[i][j];
    }
  }
  int c[n][n];
  REP(i,n){
    REP(j,n){
      cin>>c[i][j];
      c[i][j]--;
    }
  }
  
  int costs[C][3]={};
  REP(k,3){
    REP(color,C){
      REP(i,n){
        REP(j,n){
          if((i+j)%3==k){
            costs[color][k] += d[c[i][j]][color];
          }
        }
      }
    }
  }
  
  int ans = INT_MAX;
  REP(i,C){
    REP(j,C){
      REP(k,C){
        if(i==j || j==k || k==i){
          continue;
        }
        ans = min(ans,costs[i][0]+costs[j][1]+costs[k][2]);
      }
    }
  }
  cout<<ans<<endl;  
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main() {
    int N, ans = INF;
    cin >> N;
    
    for (int i = 0; i <= N; i++) {
        int cnt = 0;
        int t = i;
        while (t > 0) { cnt += t%6; t /= 6; }
        t = N-i;
        while (t > 0) { cnt += t%9; t /= 9; }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc146/tasks/abc146_d


#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
 
using namespace std;
using INT = long long int;

void ret_f (vector<vector<INT>>& v, map< pair<INT,INT>, INT>& tab_a_b_idx, vector<INT>& colors, INT idx, INT idx_prev, INT no_use_color){
    INT c = 1;
    for( INT i = 0; i < v[idx].size(); i++){
        INT idx2 = v[idx][i];
        if( c == no_use_color ){ c++; }
        if( idx_prev == idx2 ) { continue; }

        INT color_idx = 0;
        if ( idx < idx2 ){
            color_idx = tab_a_b_idx[pair<INT,INT>(idx,idx2)];
        } else {
            color_idx = tab_a_b_idx[pair<INT,INT>(idx2,idx)];
        }
        colors[color_idx] = c;
        ret_f( v, tab_a_b_idx, colors, idx2, idx, c );
        c++;
    }
}

int main(void){
    INT N;
    vector<vector<INT>> v;
    vector<pair<INT, INT>> orig;
    map< pair<INT,INT>, INT> tab_a_b_idx;
    vector<INT> colors;


    cin >> N;
    v.resize(N);
    orig.resize(N-1);
    colors.resize(N-1);
    

    INT max_color = 0;
    INT max_point_idx = 0;

    for( INT i = 0; i < N-1; i++ ){
        INT a, b;
        cin >> a >> b;
        a--; b--; 
        v[a].push_back(b);
        v[b].push_back(a);
        
        if( a < b ){
            tab_a_b_idx.emplace( pair<INT,INT>(a,b), i);
        } else {
            tab_a_b_idx.emplace( pair<INT,INT>(b,a), i);
        }
        orig[i] =  pair<INT,INT>(a,b) ;
        
        if ( max_color < v[a].size()){
            max_color = v[a].size();
            max_point_idx = a;
        }
        if ( max_color < v[b].size()){
            max_color = v[b].size();
            max_point_idx = b;
        }
    }

    ret_f( v, tab_a_b_idx, colors, max_point_idx, -1, -1 );

    cout << max_color << endl;

    for( auto p : orig ){
        INT color_idx = tab_a_b_idx[p];
        INT color = colors[color_idx];
        //cout << p.first << " " << p.second << " " << color << endl;
        cout << color << endl;
    }

}

Measured memory_bytes: 17664
// https://atcoder.jp/contests/abc150/tasks/abc150_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  string S;
  cin >> N >> S;

  ll res = 0;

  rep(i, N - 2) {
    if (S.substr(i, 3) == "ABC") {
      res++;
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
using namespace std;
const int INF = 20001;
static int G[100][100];

int prim(int n){
    
    const int BLACK = 2,GRAY = 1,WHITE =  0;
    int color[n],d[n];
    for(int i = 0;i < n;++i){
        d[i] = INF;
        color[i] = WHITE;
    }
    d[0] = 0;
    int min = INF,u;
    while(1){
        int min = INF;
        for(int i=0;i < n;++i){
            if(color[i] != BLACK && d[i] < min){
                min = d[i];
                u = i;
            }
        }
        if(min == INF) break;
        color[u] = BLACK;
        for(int i=0;i < n;++i){
            if(color[i] != BLACK && G[u][i] != INF){
                if(d[i] > G[u][i]){
                    d[i] = G[u][i];
                    color[i] = GRAY;
                }
            }
        }
        //for(int i = 0;i < n;++i) printf("%d ",d[i]);
    }
    int sum = 0;
    for(int i = 0;i < n;i++) sum += d[i];
    return sum;
}

int main(void){
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            scanf("%d",&G[i][j]);
            G[i][j] = (G[i][j] == -1) ? INF:G[i][j];
        }
    }

    printf("%d\n",prim(n));
    
}





Measured memory_bytes: 3220
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  int q;
    cin>>q;
  vector<bool> A(100100,true);
  for(int i=2;i<=100010;i++){
    int up=sqrt(i)+1;
    for(int j=2;j<up;j++){
      if(i%j==0){
         A[i]=false;
        break;
      }
    }
  }

  vector<int> B(100100);
  for(int i=3;i<=100010;i+=2){
    B[i]=B[i-2];
    if(A[i]&&A[(i+1)/2]){
      B[i]++;
    }
  }
  for(int i=0;i<q;i++){
    int l,r;
      cin>>l>>r;
    if(l==1){
      l+=2;
    }
    cout<<B[r]-B[l-2]<<endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    double L;
    cin >> L;
    double x = L / 3;

    cout << setprecision(20) << x * x * x << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(N);
    rep(i,N)cin>>A[i];
    
    vector<int> v(N);    //v[i]: A[i]~A[i+M-1]?????§?????°????????????????????¨???????????°???????????????
    
    //v[i]????±?????????????( O(N M logM) )
    rep(i,N){
        vector<int> tmp;
        for(int j=i;j<i+M;j++) tmp.pb( A[j%N] );
        
        sort(all(tmp));
        int maxi = tmp[tmp.size()-1];
        int mini = tmp[0];
        
        v[i] = maxi - mini;
    }
    
    int ans = 0;
    int lcm = N*M/__gcd(N,M);
    
    rep(i,lcm/M){   //????\???? LCM(N,M)/M ???????????????LCM(N,M)/M????????°??????????????§??????
        int index = (i*M)%N;
        ans+=v[index];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3144
#include <iostream>
using namespace std;
int main() {
    long long s;
    cin >> s;
    int minDiff = 999;
    for (long long i=1; s/i>=100; i*=10) {
        int threeNumbers = s/i - (s/(i*1000))*1000;
        minDiff = min(minDiff, abs(753-threeNumbers));
    }
    cout << minDiff << endl;
}

Measured memory_bytes: 3560
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
typedef long long ll;
const int N=1000005;
char s[N];
int n,w;
using namespace std;

int main()
{
	#ifdef Kay
		freopen ("code.in","r",stdin);
		freopen ("code.out","w",stdout);
	#endif
	scanf ("\n%s",s+1),n=strlen(s+1);
	cin>>w;
	int i;
	for (i=1;i<=n;i+=w) putchar(s[i]);
	return 0;
}


Measured memory_bytes: 256
#include <atcoder/convolution>
#include <atcoder/dsu>
#include <atcoder/fenwicktree>
#include <atcoder/lazysegtree>
#include <atcoder/math>
#include <atcoder/maxflow>
#include <atcoder/mincostflow>
#include <atcoder/modint>
#include <atcoder/scc>
#include <atcoder/segtree>
#include <atcoder/string>
#include <atcoder/twosat>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using namespace internal;
#define rep(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
  long long int t, n, m, a, b;
  cin >> t;
  rep(i,t) {
    long long int ans = 0;
    cin >> n >> m >> a >> b;
    ans = floor_sum(n,m,a,b);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3640
#!/usr/bin/ruby
#encofing: utf-8

a,b = gets.split(" ")
ans = ""

if a == 'H'
  if b == 'H'
    ans = 'H'
  else
    ans = 'D'
  end
else
  if b == 'H'
    ans = 'D'
  else
    ans = 'H'
  end
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

ll arr[5005][205];
ll ak[N];
int seg[5005*6];
vector<pair<int,ll> > upds[N];
int combine(int x1,int x2,int id){
  if(x1==-1) return x2;
  if(x2==-1) return x1;
  if(arr[x1][id]>=arr[x2][id]) return x1;
  return x2;
}
int n,m; 
void make(int C,int S,int E,int id){
  if(S==E){
    seg[C]=S;
    return;
  }
  int m=(S+E)>>1;
  make(C*2,S,m,id);make(C*2+1,m+1,E,id);
  seg[C]=combine(seg[C*2],seg[C*2+1],id);
}
int qq(int C,int S,int E,int s,int e,int id){
  if(s>E||e<S) return -1;
  if(s<=S&&E<=e) return seg[C];
  int m=(S+E)>>1;
  return combine(qq(C*2,S,m,s,e,id),qq(C*2+1,m+1,E,s,e,id),id);
}
void solve(int st,int ed,int id){
  if(st>ed) return ;
  int md = qq(1,0,n-1,st,ed,id);
  //printf("gg%d %d %d %d %lld\n",st,ed,id,md,arr[md][id]);
  upds[st].pb(mp(md,arr[md][id]));
  upds[st].pb(mp(ed+1,-arr[md][id]));
  upds[md+1].pb(mp(md,-arr[md][id]));
  upds[md+1].pb(mp(ed+1,arr[md][id]));
  solve(st,md-1,id); solve(md+1,ed,id);
}
ll curr[5005];
int main(){
  scanf("%d%d",&n,&m);
  ak[0]=0;
  REPP(i,1,n){
    scanf("%lld",&ak[i]); ak[i]+=ak[i-1];
  }
  REP(i,n) REP(j,m) scanf("%lld",&arr[i][j]);
  REP(j,m){
    make(1,0,n-1,j);
    solve(0,n-1,j);
  }
  ll ans=0;
  REP(i,n){
    REP(j,upds[i].size()){
      curr[upds[i][j].X]+=upds[i][j].Y;
    }
    ll x=0;
    REP(j,n){
      x+=curr[j];
      if(j>=i) ans=max(ans,x-ak[j]+ak[i]);//,printf("%d %d %lld\n",i,j,x);

    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 118656
#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;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> S(n),T(m);
    rep(i,n) cin >> S[i];
    rep(i,m) cin >> T[i];

    vector<vector<ll>> dp(n+1,vector<ll>(m+1,1));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] + (S[i-1]==T[j-1]?(dp[i-1][j-1]):0) + MOD)%MOD;
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 31616
fun main(args: Array<String>) {
    val a = readLine()!!
    if (isLikeCoffee(a)) {
        println("Yes")
    } else {
        println("No")
    }
}

fun isLikeCoffee(str: String): Boolean {
    if (str.length < 6) return false

    return str[2] == str[3] && str[4] == str[5]
}


Measured memory_bytes: 31772
a,b,k=map(int, input().split())
for i in range(k):
  if i%2==0:
    if a%2==1:
      a-=1
    b+=a//2
    a-=a//2
  else:
    if b%2==1:
      b-=1
    a+=b//2
    b-=b//2
print(a,b)

Measured memory_bytes: 3060
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll x[100010];

int main(void){
	          int i;

	          ll N,A,B;
	          cin >> N >> A >> B;
	          for(i=1;i<=N;i++){
	        	  cin >> x[i];
	          }

	          ll ans=0;
	          for(i=2;i<=N;i++){
	        	  ll d=x[i]-x[i-1];
	        	  if(d*A>=B) ans+=B;
	        	  else ans+=A*d;
	          }

	          cout << ans << endl;

	          return 0;
}


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

using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> happy(n, vector<int>(3));
    rep(i, n) rep(j, 3) cin >> happy[i][j];
    const int inf = 1e9+7;
    vector<vector<int>> dp(n, vector<int>(3, 0));
    rep(i, 3) dp[0][i] = happy[0][i];
    rep(i, n-1) {
        rep(j, 3) {
            rep(k, 3) {
                if (k == j) continue;
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + happy[i+1][k]);
            }
        }
    }
    cout << *max_element(dp[n-1].begin(), dp[n-1].end()) << endl;
}

Measured memory_bytes: 14324
class UnionFind:
  def __init__(self, n):
    self.parent = [-1] * n
    self.rank = [1] * n
    self.count = [1] * n

  def get_root(self, i):
    if self.parent[i] < 0:
      return i
    else:
      self.parent[i] = self.get_root(self.parent[i])
      return self.parent[i]
    #while self.parent[i] != -1:
    #  i = self.parent[i]
    #return i

  def is_same_tree(self, i, j):
    return self.get_root(i) == self.get_root(j)

  def merge(self, i, j):
    i = self.get_root(i)
    j = self.get_root(j)
    if i == j:
      return

    if self.rank[i] > self.rank[j]:
      self.parent[j] = i
      self.rank[i] = max(self.rank[i], self.rank[j] + 1)
      self.count[i] += self.count[j]
    else:
      self.parent[i] = j
      self.rank[j] = max(self.rank[j], self.rank[i] + 1)
      self.count[j] += self.count[i]


n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
  a, b = [int(i) - 1 for i in input().split()]
  uf.merge(a, b)
print(max(uf.count))


Measured memory_bytes: 83924
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);

}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
struct edge { int to, cost; };
std::vector<edge>v[100];
bool used[210];

int main() {
	int n, a[100000], esum = 0, osum = 0;
	std::cin >> n;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
		if (a[i] % 2 == 0) {
			esum++;
		}
		else {
			osum++;
		}
	}
	esum += osum / 2;
	if (osum % 2 == 1) {
		std::cout << "NO" << std::endl;
		flag = false;
	}
	else if (esum == 1) {
		std::cout << "YES" << std::endl;
		flag = false;
	}
	if (flag) {
		while (true) {
			if (esum == 1) {
				std::cout << "YES" << std::endl;
				break;
			}
			ll b = esum / 2;
			if(esum % 2 == 1) {
				esum = b + 1;
			}
			else {
				esum = b;
			}
		}
	}
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
typedef long long ll;
ll m=1e9+7;
ll p(ll a, ll b){
if(b<0)return 0;
    if(b==0)return 1;
    if(b%2==0)return p((a*a)%m, b/2);
    return (a*p(a, b-1))%m;
}
int main() {
    int n;
    ll a[100001], c[100001], q[100001];
    string s;
    ll t=0;
    cin>>s;
    n=s.length();
    a[0]=c[0]=q[0]=0;
    for(int i=1;i<=n;i++){
        a[i]=a[i-1];
        c[i]=c[i-1];
        q[i]=q[i-1];
        if(s[i-1]=='A')a[i]++;
        else if(s[i-1]=='C')c[i]++;
        else if(s[i-1]=='?')q[i]++;
    }
    for(int i=1;i<=n;i++){
        if(s[i-1]=='B'){
            t+=(a[i]*(c[n]-c[i]))%m*p(3, q[n]);
            t%=m;
            t+=(a[i]*(q[n]-q[i]))%m*p(3, q[n]-1);
            t%=m;
            t+=(q[i]*(c[n]-c[i]))%m*p(3, q[n]-1);
            t%=m;
            t+=(q[i]*(q[n]-q[i]))%m*p(3, q[n]-2);
            t%=m;
        }else if(s[i-1]=='?'){
            t+=(a[i]*(c[n]-c[i]))%m*p(3, q[n]-1);
            t%=m;
            t+=(a[i]*(q[n]-q[i]))%m*p(3, q[n]-2);
            t%=m;
            t+=((q[i]-1)*(c[n]-c[i]))%m*p(3, q[n]-2);
            t%=m;
            t+=((q[i]-1)*(q[n]-q[i]))%m*p(3, q[n]-3);
            t%=m;
        }
    }
    cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
struct edge{
    int u;
    LL d;
    int c;
    bool operator < (const edge& o) const{
        if(d != o.d) return d > o.d;
        return c < o.c;
    }
};
vector<edge> g[55];
priority_queue<edge> dijk;
LL wait[55];
int coin[55];
LL dp[55][2555];
void add_edge(int a, int b, int c, int d){
    g[a].pb({b,d,c});
    g[b].pb({a,d,c});
}
int main(){
	int i,j,k,l,a,b,c,d;
    int s, n, m;
    scanf("%d%d%d",&n,&m,&s);
    FOR(i, 1, m){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        add_edge(a,b,c,d);
    }
    FOR(i, 1, n) scanf("%d%lld",&coin[i],&wait[i]);

    s = min(s, 2500);
    FOR(i, 1, n) FOR(j, 0, 2500) dp[i][j] = 1e14;
    dp[1][s] = 0; dijk.push({1, 0, s});
    while(!dijk.empty()){
        int u = dijk.top().u;
        LL dd = dijk.top().d;
        c = dijk.top().c;
        dijk.pop();
        int cc = min(c+coin[u], 2500);
        if(dp[u][cc] > dd+wait[u]) dp[u][cc] = dd+wait[u], dijk.push({u, dd+wait[u], cc});
        for(edge e : g[u]){
            cc = c-e.c;
            if(cc < 0) continue;
            if(dp[e.u][cc] > dd+e.d){
                dp[e.u][cc] = dd+e.d;
                dijk.push({e.u, dd+e.d, cc});
            }
        }
    }
    FOR(i, 2, n){
        LL ans = 1e14;
        FOR(j, 0, 2500) ans = min(ans, dp[i][j]);
        printf("%lld\n",ans);
    }
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 7472
N = int(input())

def powmod(x, y):
    num = 1
    for i in range(y):
        num = num * x % (10**9+7)
    return num

ans = powmod(10,N) - 2*powmod(9,N) + powmod(8,N)
ans %= 10**9+7
print(ans)

Measured memory_bytes: 8952
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main(){
	ll a,b; cin>>a>>b;
	if(a>=b/2){
		printf("%lld",b/2);
		return 0;
	}
	ll ans=a;
	b-=2*a;
	ans+=b/4;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 896
n,a,b=map(int, input().split())
 
def comb(n, r,MOD):
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % MOD
        q = q * (i+1) % MOD
    return p * pow(q, MOD-2, MOD) % MOD

mod=10**9+7

if n==2:
    print(0)
else:
    print((pow(2,n,mod)-1-comb(n,a,mod)-comb(n,b,mod))%mod)

Measured memory_bytes: 38640
#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;

//------------↓------------- 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() {

    int N, M; cin >> N >> M;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    vector<pair<ll,ll>> b(M);
    rep(i,M) cin >> b[i].second >> b[i].first;
    Sort(a);
    Sort(b);
    Reverse(b);
    ll ans = 0;
    rep(i,N) ans += a[i];
    int num = 0;
    int cnt = 1;
    rep(i,N) {
        if (a[i] < b[num].first) {
            ans += b[num].first - a[i];
            if (cnt == b[num].second) {
                ++num;
                cnt = 0;
            }
            ++cnt;
        }
        else break;
    }
    out(ans);
    
    return 0;
}










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



int main(){
  
  int N; cin >> N;
  vector<vector<int>> to(N);
  
  
  
  int u,v; cin >> u >> v; u--; v--;
  
  for(int i = 0; i < N-1; i++){ 
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
    
  }
  
  vector<int> points;
  
  for(int i = 0; i < N; i++){
    
    if( (int)to[i].size() == 1){ 
     
      points.push_back( to[i].front() );}
    
  }
  
  if( to[u].size() == 1 && to[u].front() == v){ //初っ端から逃げられない
    cout << 0 << endl; return 0;
  }
  
  
  queue<int> Q;
  
  
  vector<int> visited(N,-1);
  vector<int> used(N,-1);
  
  visited[u] = 0;
  used[v] = 0;
  
  Q.push(u);
  while(!Q.empty()){
    
    int p = Q.front(); Q.pop();
    
    for(auto ne : to[p]){
      
      if( visited[ne] == -1){ Q.push(ne); visited[ne] = visited[p]+1;}
      
    }
    
  }
  
  Q.push(v);
  while(!Q.empty()){
    
    int p = Q.front(); Q.pop();
    
    for(auto ne : to[p]){
      
      if( used[ne] == -1){ Q.push(ne); used[ne] = used[p]+1;}
      
    }
    
  }
  
  int ans = 0;
  
  for(auto ne : points){
    
    if( visited[ne] <= used[ne]){ ans = max(used[ne],ans);}
    
  }
  
  cout << ans << endl;
  
  return 0;
}
  
  

Measured memory_bytes: 6908
#include <stdio.h>

int main(void)
{
	int x, y;
	
	for (x = 1; x <= 9; x++){
		for (y = 1; y <= 9; y++){
			printf("%dx%d=%d\n", x, y, x * y);
		}
	}
	
	return (0);
}

Measured memory_bytes: 924
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}


int h;
int board[15][5];
int vanih[5];
int chain[10];


int main(int argc,char const* argv[])
{
  while(1)
    {
      memset(vanih,0,sizeof(vanih));
      int score=0;
      cin >> h;
      if(!h)break;
      bool end=false;
      for(int i=0;i<h;i++)
	{
	  for(int j=0;j<5;j++)
	    {
	      cin >> board[h-i-1][j];
	    }
	}
      while(!end)
	{
	  end=true;
	  memset(chain,0,sizeof(chain));
	  for(int i=0;i<h;i++)
	    {
	      for(int j=0;j<3;j++)
		{
		  if(board[i][j]!=-1 && board[i][j]==board[i][j+1] && board[i][j]==board[i][j+2])
		    {
		      end=false;
		      int d=board[i][j];
		      for(; board[i][j]==d && j<5;j++)
			{
			  board[i][j]=-1;
			  score+=d;
			}
		    }
		}
	    }

	  for(int j=0;j<5;j++)
	    {
	      for(int i=1;i<h;i++)
		{
		  if(board[i-1][j]==-1 && board[i][j]!=-1)
		    {
		      for(int row=i; row>0&&board[row-1][j]==-1;row--)
			{
			  swap(board[row-1][j],board[row][j]);
			}
		    }
		}
	    }
	}
      cout << score << endl;
    }
  return 0;
}
			       
	



Measured memory_bytes: 2964
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, v = na()
b, w = na()
t = ni()

if w-v>=0:
    print("NO")
else:
    diff = v-w
    if abs(a-b) <= diff*t:
        print("YES")
    else:
        print("NO")

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

using namespace std;

int dp[200002], n, k, v[102];

void nr (int x) {
  if (dp[x] != -1)
    return;
  for (int i = 1; i <= n; i++) {
    int y = x - v[i];
    if (y >= 0) {
      nr(y);
      if (dp[y] == 2) {
        dp[x] = 1;
        return ;
      }
    }
  }
  dp[x] = 2;
}


int main()
{
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];

  }
  for (int i = 0; i < 100002; i++)
    dp[i] = -1;
  for (int i = 1; i <= n; i++)
    dp[v[i]] = 1;
  nr(k);
  if (dp[k] == 1) {
    cout << "First";
  }
  else
    cout << "Second";
  return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <cstring>

using namespace std;
typedef long long ll;

ll sum;

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

int main() {
  int k;
  cin >> k;
  for(int i = 1; i <= k; i++) {
    for(int j = 1; j <= k; j++) {
      for(int l = 1; l <= k; l++) {
	sum += gcd(i,gcd(j,l));
      }
    }
  }

  cout << sum << endl;
}

  


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

int main(){

    int n,c;
    cin >> n >> c;

    vector<ll> a(n);
    vector<ll> d;

    rep(i,n){
        cin >> a[i];
    }

    ll t=0;
    ll mi=a[0];

    for(int i=1;i<n;i++){
        d.push_back(a[i]-mi);
        mi=min(mi,a[i]);
    }

    sort(d.begin(),d.end(),greater<ll>());

    for(int i=1;i<d.size();i++){
        if(d[i-1]!=d[i]){
            cout << i << endl;
            return 0;
        }
    }

    cout << d.size() << endl;

    return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,k,p;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>k>>p;
    if(k%p==0){
      cout<<p<<endl;
    }
    else{
      cout<<k%p<<endl;
    }
  }
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define M 1000000007
using namespace std;




int main()
{
	int t=1;
	//cin>>t;
	
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		
		int *a=new int[n];
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		
		int *dp=new int[k+1];
		for(int i=0;i<=k;i++)
		{
			dp[i]=0;
		}
		
		for(int i=1;i<=k;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(i-a[j]<0)
				{
					break;
				}
				
				if(dp[i-a[j]]==0)
				{
					dp[i]=1;
					break;
				}
			}
		}
		if(dp[k])
		{
			cout<<"First"<<endl;
		}else
		{
			cout<<"Second"<<endl;
		}
		
	}
	
	return 0;
}


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

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

    int Q;
    cin >> Q;

    int t, f;
    char c;
    int count = 0;
    string s[2] = {};
    for (int i = 0; i < Q; i++) {
        cin >> t;
        if (t == 1) {
            string tmp = s[0];
            s[0] = s[1];
            s[1] = tmp;
            count++;
        }
        else {
            cin >> f >> c;
            s[f - 1] += c;
        }
    }

    string ans = "";
    if (count % 2 == 0) {
        for (int i = s[0].length() - 1; i >= 0; i--) {
            ans += s[0][i];
        }
        ans += S + s[1];
    }
    else {
        for (int i = s[0].length() - 1; i >= 0; i--) {
            ans += s[0][i];
        }
        for (int i = S.length() - 1; i >= 0; i--) {
            ans += S[i];
        }
        ans += s[1];
    }

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

Measured memory_bytes: 1476
# rr..wwにする
# 8
# W R W W R W R R
# R R R R W W W W
# 10
# WRRRRWRRWR
# -> 2
# 12
# WWRRRRWRWRRR
n = int(input())
c = list(input())
w_count = c.count("W")
if w_count == 0 or w_count == n:
    print(0)
    exit()
ans1 = 0
for i in range(n - 1, n - w_count - 1, -1):
    if c[i] == "R":
        ans1 += 1

# いっそ色を変える場合 必要なだけWかRにする
# ans2 = 0
# flag = False
# for i in range(n):
#     if c[i] == "W" and flag == False:
#         flag = True
#     elif c[i] == "W" and flag:
#         ans2 += 1
# print(ans1, ans2, w_count, n - w_count)
print(min(ans1, w_count, n - w_count))


Measured memory_bytes: 10796
N=int(input())
from numba import*
@njit('i8(i8)',cache=1)
def f(N):
    d=[1]*N
    for i in range(2,N+1):
        for j in range(i-1,N,i):
            d[j]+=1
    r=0
    for i in range(N):
        r+=(i+1)*d[i]
    return r
print(f(N))

Measured memory_bytes: 188528
import java.util.Scanner;


class Main {

	public static void main(String[] args) {   

		Scanner scanner = new Scanner(System.in);

		int n=scanner.nextInt();
		int scoret=0;
		int scoreh=0;
		
		
		for(int i=0;i<n;i++){
			String taro=scanner.next();
			String hanako=scanner.next();
			
			int num=taro.compareTo(hanako);
			
			if(num<0){
				scoreh=scoreh+3;
			}
			else if(num>0){
				scoret=scoret+3;
			}
			else{
				scoreh=scoreh+1;
				scoret=scoret+1;
			}
			
		}
		
		System.out.println(scoret+" "+scoreh);	
	}
}




Measured memory_bytes: 29880