akhauriyash/Code-Regression huggingface dataset:
import random

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


def calc(T):
  L = [0 for i in range(26)]
  score=0
  for d in range(D):
    score += S[d][T[d]-1]

    L[T[d]-1] = d+1
    down = 0
    for i in range(26):
      down+=C[i] * ((d+1) - L[i])

    score -=down
  return score

max_score=0
bestT=[]

for i in range(1000):
  T = [random.randrange(1,26) for i in range(D)] 
  score = calc(T)

  if score > max_score:
    bestT = T
    max_score = score

for t in T:
  print(t)

Measured memory_bytes: 9900
#include <iostream>
#include <string>

using std::string;

int main() {
	string str;
	std::cin >> str;
	std::cout << str[0] << str[1] << str[2] << str[3] << " " << str[4] <<
																	   str[5]
			  << str[6] << str[7] << str[8] << str[9] <<str[10] << str[11] <<
																		   "\n";

	return 0;
}

Measured memory_bytes: 256
INF = 10000000000

def merge(A, left, mid, right):
    count = 0
    L = A[left:mid] + [INF]
    R = A[mid:right] + [INF]
    
    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return count
    
def mergesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        countL = mergesort(A, left, mid)
        countR = mergesort(A, mid, right)
        return merge(A, left, mid, right) + countL + countR
    return 0
    
n = int(input())
A = [int(i) for i in input().split()]
count = mergesort(A, 0, n)
for i in range(n):
    if i:
        print(" ", end = "")
    print(A[i], end = "")
print()
print(count)


Measured memory_bytes: 61652
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

class Spot {
public:
	int x;
	int y;
	int h;

	Spot(int xi, int yi, int hi) {
		x = xi;
		y = yi;
		h = hi;
	}
};

int n;
vector<Spot> spots;

void input() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int xi, yi, hi;
		cin >> xi >> yi >> hi;
		spots.push_back(Spot(xi, yi, hi));
	}
}

int culculateH(int x, int y) {
	for (int i = 0; i < n; i++) {
		int xi = spots.at(i).x;
		int yi = spots.at(i).y;
		int hi = spots.at(i).h;
		if (hi > 0) {
			return hi + abs(x - xi) + abs(y - yi);
		}
	}
	return 0;
}

bool checkSpots(int Cx, int Cy, int H) {
	for (int i = 0; i < n; i++) {
		int xi = spots.at(i).x;
		int yi = spots.at(i).y;
		int hi = spots.at(i).h;
		if (hi != max(H - abs(Cx - xi) - abs(Cy - yi), 0)) return false;
	}
	return true;
}

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

	input();
	int Cx, Cy, H;

	for (int x = 0; x <= 100; x++) {
		for (int y = 0; y <= 100; y++) {
			H = culculateH(x, y);
			if (checkSpots(x, y, H)) {
				Cx = x;
				Cy = y;
				cout << Cx << " " << Cy << " " << H << "\n";
				return 0;
			}
		}
	}

	return 0;
}

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

int main(){
  int ax,ay,ar;
  int bx,by,br;
  cin>>ax>>ay>>ar;
  cin>>bx>>by>>br;

  int dist = (ax-bx)*(ax-bx) + (ay-by)*(ay-by);
  // ar+br < sqrt(dist) 
  if( (ar+br)*(ar+br) < dist ){
    cout<<4<<endl;
  }else if( (ar+br)*(ar+br) == dist ){
    cout<<3<<endl;
    // |ar-br| < sqrt(dist)
  }else if( (ar-br)*(ar-br) < dist ){
    cout<<2<<endl;
  }else if( (ar-br)*(ar-br) == dist ){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
  return 0;
}



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

int N;
ll res,r,g,b;
string S;

int main(){
	cin>>N>>S;
	for(char c:S){
		if(c=='R')r++;
		if(c=='G')g++;
		if(c=='B')b++;
	}
	res=r*g*b;
	for(int i=0;i<N;i++){
		for(int j=1;i+j+j<N;j++){
			if((S[i]^S[i+j]^S[i+j+j])==('R'^'G'^'B'))res--;
		}
	}
	cout<<res<<endl;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> v(m);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    v[i].first = a;
    rep(j,b){
      int c;
      cin >> c;
      c --;
      v[i].second += (1 << c);
    }
  }
  vector<int> dp((1 << n),1001001001);
  dp[0] = 0;
  rep(i,(1 << n)){
    rep(j,m){
      int next = i | v[j].second;
      dp[next] = min(dp[next],dp[i]+v[j].first);
    }
  }
  if(dp[(1 << n) - 1] == 1001001001) cout << -1 << endl;
  else cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/


int main(){
    _cin;
    // cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;
    ll a[n][3], dp[n][3];
    fo(i,n) cin >> a[i][0] >> a[i][1] >> a[i][2];
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    repa(i,1,n){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i][0];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + a[i][1];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + a[i][2];
    }
    cout << max(dp[n-1][0], dp[n-1][1], dp[n-1][2]);
}
 return 0;      
}

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

int main() {
  double xa, ya, xb, yb, xc, yc, xd, yd;
  double vx1, vy1, vx2, vy2;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) == 8) {
    vx1 = ya-yc;
    vy1 = xc-xa;
    vx2 = yb-yd;
    vy2 = xd-xb;
    if ((vx1*(xb-xa)+vy1*(yb-ya))*(vx1*(xd-xa)+vy1*(yd-ya)) > 0 || (vx2*(xa-xb)+vy2*(ya-yb))*(vx2*(xc-xb)+vy2*(yc-yb)) > 0) printf("NO\n");
    else printf("YES\n");
  }

  return 0;
}

Measured memory_bytes: 1036
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node
{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
};

typedef struct Node Node;

Node *root,*NIL;

Node *treeMin(Node *x)
{
  while(x->left!=NIL)
    {
      x=x->left;
    }
  return x;
}

Node *find(Node *u,int k)
{
  while(u!=NIL&&k!=u->key)
    {
      if(k<u->key)
	{
	  u=u->left;
	}
      else
	{
	  u=u->right;
	}
    }
  return u;
}

Node *treeSuccessor(Node *x)
{
  if(x->right!=NIL)
    {
      return treeMin(x->right);
    }
  Node *y=x->parent;
  
  while(y!=NIL&&x==y->right)
    {
      x=y;
      y=y->parent;
    }
  
  return y;
}

void treeDelete(Node *z)
{
  Node *y;
  Node *x;

  if(z->left==NIL||z->right==NIL)
    {
      y=z;
    }
  else
    {
      y=treeSuccessor(z);
    }

  if(y->left!=NIL)
    {
      x=y->left;
    }
  else
    {
      x=y->right;
    }

  if(x!=NIL)
    {
      x->parent=y->parent;
    }

  if(y->parent==NIL)
    {
      root=x;
    }
  else
    {
      if(y==y->parent->left)
	{
	  y->parent->left=x;
	}
      else
	{
	  y->parent->right=x;
	}
    }

  if(y!=z)
    {
      z->key=y->key;
    }

  free(y);
}

void insert(int k)
{
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL)
    {
      y=x;

      if(z->key<x->key)
	{
	  x=x->left;
	}
      
      else
	{
	  x=x->right;
	}
    }

  z->parent=y;

  if(y==NIL)
    {
      root=z;
    }

  else
    {
      if(z->key<y->key)
	{
	  y->left=z;
	}

      else
	{
	  y->right=z;
	}
    }
}

void inorder(Node *u)
{
  if(u==NIL)
    {
      return;
    }
  
  inorder(u->left);
  
  printf(" %d",u->key);
  
  inorder(u->right);  
}

void preorder(Node *u)
{
  if(u==NIL)
    {
      return;
    }
  
  printf(" %d",u->key);
  
  preorder(u->left);
  
  preorder(u->right);
}

int main(void)
{
  int n,i,x;
  char com[20];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%s",com);

      if(com[0]=='f')
	{
	  scanf("%d",&x);
	  Node *t=find(root,x);
	  if(t!=NIL)
	    {
	      puts("yes");
	    }
	  else
	    {
	      puts("no");
	    }
	}
      else if(strcmp(com,"insert")==0)
	{
	  scanf("%d",&x);
	  insert(x);
	}
      else if(strcmp(com,"print")==0)
	{
	  inorder(root);
	  putchar('\n');
	  preorder(root);
	  putchar('\n');
	}
      else if(strcmp(com,"delete")==0)
	{
	  scanf("%d",&x);
	  treeDelete(find(root,x));
	}
    }

  return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  st s;
  cin >> s;
  bl check = false;
  rep(i, 0, 3) if(s.at(i) == s.at(i + 1)) check = true;
  cout << (check ? "Bad" : "Good" ) << endl;
}

Measured memory_bytes: 384
// https://atcoder.jp/contests/agc026/tasks/agc026_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn compute(a: Vec<char>) -> HashMap<(Vec<char>, Vec<char>), u64> {
    let mut map = HashMap::new();
    let n = a.len();
    for p in 0..(1<<n) {
        let mut red = vec![];
        let mut blue = vec![];
        for i in 0..n {
            if p & (1<<i) == 0 {
                red.push(a[i]);
            } else {
                blue.push(a[i]);
            }

        }
        let pair = (red, blue);
        let cnt = *(map.get(&pair).unwrap_or(&0)) + 1;
        map.insert(pair, cnt);
    }
    map
}

fn main() {
    input! {
        n: usize,
        s: chars
    };

    let mut left = vec!['-'; n];
    let mut right = vec!['-'; n];

    left.copy_from_slice(&s[0..n]);
    right.copy_from_slice(&s[n..2*n]);
    right.reverse();

    let leftMap = compute(left);
    let rightMap = compute(right);

    let mut ans = 0;
    for ((l, r), lways) in leftMap {
        let rways = *rightMap.get(&(r.to_vec(), l.to_vec())).unwrap_or(&0);
        ans += lways * rways;
    }

    // ABcd|DCba
    println!("{}", ans);
}


Measured memory_bytes: 135336
package main

import "fmt"

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

	var nums []int

NEXTLOOP:
	for i := 1; i < 32; i++ {
		for ii := 2; ii < 10; ii++ {
			x := pow(i, ii)
			if x > 1000 {
				continue NEXTLOOP
			}
			nums = append(nums, x)
		}
	}
	max := 0
	for i := 0; i < len(nums); i++ {
		if nums[i] > N {
			continue
		}
		if max < nums[i] {
			max = nums[i]
		}
	}

	fmt.Println(max)

}

func pow(p, q int) int {
	var ans int
	ans = 1
	for i := 0; i < q; i++ {
		ans *= p
	}
	return ans
}


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

int main() {
  string x; // charではだめ
  cin >> x;
  if( x == "a" || x == "e" || x == "i" || x == "o" || x == "u"){ // ""を忘れない
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM = *0...6

Direction = [
  [0, 1, 2, 3, 4, 5],
  [0, 2, 4, 1, 3, 5],
  [0, 4, 3, 2, 1, 5],
  [0, 3, 1, 4, 2, 5],
  [1, 5, 2, 3, 0, 4],
  [1, 3, 5, 0, 2, 4],
  [2, 5, 4, 1, 0, 3],
  [3, 4, 5, 0, 1, 2],
  [4, 0, 2, 3, 5, 1],
  [4, 2, 5, 0, 3, 1],
  [4, 5, 3, 2, 0, 1],
  [4, 3, 0, 5, 2, 1],
  [5, 4, 2, 3, 1, 0],
  [5, 2, 1, 4, 3, 0],
  [5, 1, 3, 2, 4, 0],
  [5, 3, 4, 1, 2, 0],
  [1, 2, 0, 5, 3, 4],
  [1, 0, 3, 2, 5, 4],
  [2, 1, 5, 0, 4, 3],
  [2, 4, 0, 5, 1, 3],
  [2, 0, 1, 4, 5, 3],
  [3, 1, 0, 5, 4, 2],
  [3, 0, 4, 1, 5, 2],
  [3, 5, 1, 4, 0, 2],
]

Connect = [
  [],
  [nil, nil, nil, [0, RIGHT], nil, nil],
  [nil, nil, nil, nil, [0, FRONT], nil],
  [nil, nil, nil, [2, RIGHT], [1, FRONT], nil],
  [[0, BOTTOM], nil, nil, nil, nil, nil],
  [[1, BOTTOM], nil, nil, [4, RIGHT], nil, nil],
  [[2, BOTTOM], nil, nil, nil, [4, FRONT], nil],
  [[3, BOTTOM], nil, nil, [6, RIGHT], [5, FRONT], nil],
]

def dfs(result, result_direction)
  return true if result.size == 8
  position = result.size
  8.times do |die|
    next if result.include?(die)
    Direction.each do |dir|
      ok = true
      6.times do |i|
        next unless Connect[position][i]
        id, face = Connect[position][i]
        a, b = @die[die][dir[i]], @die[result[id]][result_direction[id][face]]
        if a == b || a.downcase != b.downcase
          ok = false
          break
        end
      end
      if ok
        return true if dfs(result + [die], result_direction + [dir])
      end
    end
  end
  false
end

def check?
  Direction.each do |d|
    return true if dfs([0], [d])
  end
  false
end

until (list = [gets.chomp]) == ["0"]
  list += 7.times.map{gets.chomp}
  @die = list.map{|l| l.chars}
  puts check? ? "YES" : "NO"
end

Measured memory_bytes: 6088
var a,b,c,d,ll,lr,rl,rr,tmp:int64;
begin
readln(a,b,c,d);
ll:=a*c;
rl:=b*c;
lr:=a*d;
rr:=b*d;
tmp:=-1000000000 * 1000000000;
if(ll>=tmp)then tmp:=ll;
if(rl>=tmp)then tmp:=rl;
if(lr>=tmp)then tmp:=lr;
if(rr>=tmp)then tmp:=rr;
writeln(tmp);
end.

Measured memory_bytes: 1388
n,w = map(int,input().split())
items = sorted([list(map(int,input().split())) for i in range(n)])
dp = [[0]*(w+1) for _ in range(n+2)]
for i in range(n):
    wi, vi = items[i]
    for j in range(w+1):
        if j+wi<=w:
            dp[i+1][j+wi] = max(dp[i+1][j+wi], dp[i][j]+vi)
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
ans = 0
for i, (wi, vi) in enumerate(items):
    ans = max(ans, dp[i][w-1]+vi)
print(ans)


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

int main() {
  int a,b,c=0,d,e;
  cin>>a>>b;
  for(int i=0;i<a;i++)
    c+=b+i;
  if(b<0 && b+a-1<0)
    cout<<c-(b+a-1);
  else if(b>0)
    cout<<c-b;
  else
    cout<<c;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn distance(a: (f64, f64), b: (f64, f64)) -> f64 {
    ((a.0 - b.0).powf(2.) + (a.1 - b.1).powf(2.)).sqrt()
}

fn main() {
    let n = read::<usize>();

    let mut points: Vec<(f64, f64)> = vec![];
    for _ in 0..n {
        let point = read_vec::<f64>();
        points.push((point[0], point[1]));
    }

    let mut sum = 0.;
    for &i in points.iter() {
        for &j in points.iter() {
            sum += distance(i, j);
        }
    }
    
    println!("{}", sum / n as f64);
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    std::vector<int> color(9, 0);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        if(a[i] < 400) color[0]++;
        else if(a[i] < 800) color[1]++;
        else if(a[i] < 1200) color[2]++;
        else if(a[i] < 1600) color[3]++;
        else if(a[i] < 2000) color[4]++;
        else if(a[i] < 2400) color[5]++;
        else if(a[i] < 2800) color[6]++;
        else if(a[i] < 3200) color[7]++;
        else color[8]++;
    }

    int type = 0;
    for(int i = 0; i < 8; i++){
        type += (color[i] != 0);
    }

    std::cout << std::max(type, 1) << " " << type + color[8] << std::endl;
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  int mi = 1;
  int ma = n;
  rep(i, m) {
    int l, r; cin >> l >> r;
    chmax(mi, l);
    chmin(ma, r);
  }
  cout << max(ma-mi+1, 0) << endl;
}

Measured memory_bytes: 256
// Shift-JIS（シフトジス）

#include <iostream>
#include <algorithm>
using namespace std;

int maxtime(int x)
{
    return (x + 9) / 10 * 10;
}

int remtime(int x)
{
    return maxtime(x) - x;
}

int main()
{
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    int sum = maxtime(A) + maxtime(B) + maxtime(C) + maxtime(D) + maxtime(E);
    sum -= max({remtime(A), remtime(B), remtime(C), remtime(D), remtime(E)});
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
template <typename T>
class SegmentTree{
    public:
    ll n;
    T *data;
    T INF;  //comp(x, INF) == x
    T (*comp)(T, T);

    SegmentTree(ll size, T (*compArg)(T, T), T inf){
        ll newsize = 1;
        while(newsize < size) newsize = (newsize << 1);
        n = newsize;
        INF = inf;
        comp = compArg;
        data = new T[2 * n - 1];
        for(ll i = 0; i < 2 * n - 1; ++i) data[i] = inf;
    }

    void update(ll pos, T value){
        pos += n - 1;
        data[pos] += value;
        while(pos > 0){
            pos = (pos - 1) / 2;
            data[pos] = comp(data[2 * pos + 1], data[2 * pos + 2]);
        }
    }

    T query(ll a, ll b){
        if(b < 0 || n <= a) return 0;
        if(a < 0) a = 0;
        if(n <= b) b = n;
        return subQuery(a, b, 0, 0, n);
    }

    T subQuery(ll a, ll b, ll k, ll l, ll r){
        return (r <= a || b <= l ? INF : (a <= l && r <= b ? data[k] : comp(subQuery(a, b, k * 2 + 1, l, (l + r) / 2), subQuery(a, b, k * 2 + 2, (l + r) / 2, r))));
    }
};
int main(){
    ll N, K;
    cin >> N >> K;
    ll a[N];
    for(ll i = 0; i < N; i++) cin >> a[i];
    ll wa[N + 1] = {};
    vector<ll> v;
    v.push_back(0);
    for(ll i = 0; i < N; i++){
        wa[i + 1] = wa[i] + (a[i] - K);
        v.push_back(wa[i + 1]);
    }
    sort(v.begin(), v.end());
    ll id_num = 0;
    map<ll, ll> id;
    for(ll u : v) if(id.find(u) == id.end()) id[u] = id_num++;
    SegmentTree<ll> S(id.size(), [](ll a, ll b){return a + b;}, 0);
    ll ans = 0;
    for(ll i = N; 0 <= i; i--){
        ll tmp = ans;
        ans += S.query(id[wa[i]], id.size());
        S.update(id[wa[i]], 1);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
 int N;
  cin >> N;
  int i=0;
  int A=0;
  while(i<N){
    int l_i,r_i;
    cin >> l_i >> r_i;
    A +=r_i-l_i+1;
      i++;
  }
  cout << A << endl;
}

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

int main() {
  int N,x,y=0;
  cin>>N;
  for(x=0;x<N;x++){
  	string a;
    cin>>a;
    if(a=="Y"){
      y++;
      break;
    }
  }
  if(y==1){
  cout<<"Four";
  }else{
  cout<<"Three";
  }
}


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

string s;
int len;

int main()
{
	cin >> len >> s;
	int cnt = 0;
	for (int i = 0; i < len - 2; i++) if (s.substr(i, 3) == "ABC") cnt++; 
	cout << cnt << endl;
	return 0;
}


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

int main(){
  int n,x[302][302]={},y[302][302]={};
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];
  
  int ans=max(y[0][n-1],y[n-1][0]);
  for(int i=0;i<n;i++)
    for(int j=n-2;j>=0;j--) {
      x[i][j]+=x[i][j+1];
      y[j][i]+=y[j+1][i];
      ans=max(ans,max(y[j][i],x[i][j]));
    }

  int sum[302][302],K[2][302][302]={};
  for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++) sum[i][j]=-100000000;


  int t=0;
  while(1){
    t++;
    for(int i=0;i<n;i++) //yoko
      for(int j=i+1;j<n;j++) {//yoko
	int a=K[t%2][i][j];
	K[(t+1)%2][i][j]=a;
	sum[i][j]=-100000000;
	for(int k=a+1;k<n;k++) { //tate
	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);
	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);
	  if(sum[i][j]<=X+Y)sum[i][j]=X+Y,K[(t+1)%2][i][j]=k;
	  ans=max(ans,sum[i][j]);
	}
      }

    int f=1;
    for(int i=0;i<n;i++) //yoko
      for(int j=i+1;j<n;j++) //yoko
	for(int k=K[t%2][i][j]+1;k<K[(t+1)%2][i][j];k++){
	  f=0;
	  int X=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);
	  sum[i][j]+=X;
	  ans=max(ans,sum[i][j]);
	}
    if(f)break;
  }
  cout <<ans<<endl;
	  
  return 0; 
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[100005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair
void printar(vector< ll > ar, ll l, ll r){
	for(int i = l ; i < r ; i++)
		cout << ar[i] << " ";
	cout << endl;
}
	
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x, k, d;
    cin >> x >> k >> d;
    if( abs(x / d) >= k )
    	cout << abs(x) - k * d << endl;
    else{
    	k -= abs(x / d);
    	if( k % 2 )
	    	cout << abs(abs(x) - abs(x / d) * d - d) << endl;
	    else
	    	cout << abs(abs(x) - abs(x / d) * d) << endl;
    }
	return(0);
}

Measured memory_bytes: 6000
#include<iostream>
#include<cmath>

using namespace std ;


struct Node{
	int x ;
	int y ;
	int h ;
}f[101];

int main()
{
	int N ;
	cin >> N ;
	int i , j , k ;
	for (i=1 ; i<=N ; i++){
		cin >> f[i].x ;
		cin >> f[i].y ;
		cin >> f[i].h ;
	}
	int p = 0 ;
	while(f[p].h == 0) 
		p ++ ;
	
	
	for (i=0 ; i<=100 ; i++){
		for(j=0 ; j<=100 ; j++){
			
			int Het = f[p].h + abs(i-f[p].x) + abs(j-f[p].y) ;
			
			for(k=1 ; k<=N ; k++){
				
				int height = Het - abs(i-f[k].x) - abs(j-f[k].y) ;
				
				if ( height < 0 ){
					height = 0 ;
				}
				if ( height != f[k].h  ){
					break ;
				}
				if ( k==N ){
					cout << i <<" " << j << " " << Het ;
				}
			}
		}
	}
	return 0 ;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

void shiftUp(int i, vector<int>& as) {
    if (i == 0) return;
    if (as[(i - 1) / 2] < as[i]) {
        swap(as[(i - 1) / 2], as[i]);
        shiftUp((i - 1) / 2, as);
    }
}

void shiftDown(int i, vector<int>& as) {
    int H = as.size();
    int l = i * 2 + 1;
    if (l >= H) l = i;
    int r = i * 2 + 2;
    if (r >= H) r = i;

    int m = i;
    if (as[l] > as[m]) m = l;
    if (as[r] > as[m]) m = r;
    if (m != i) {
        swap(as[i], as[m]);
        shiftDown(m, as);
    }
}

int extract(vector<int>& as) {
    int res = as[0];
    swap(as[0], as[as.size() - 1]);
    as.pop_back();
    shiftDown(0, as);
    return res;
}

void insert(int n, vector<int>& as) {
    as.push_back(n);
    shiftUp(as.size() - 1, as);
}

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

    vector<int> as;
    string s;
    cin>>s;
    for (s; s != "end"; cin>>s) {
        if (s == "extract") {
            cout<<extract(as)<<endl;
            continue;
        }
        
        int n;
        cin>>n;
        insert(n, as);
    }
}


Measured memory_bytes: 6992
#define CIN_ONLY 1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
const int MOD = 1000000007;
const ld PI = acos(ld(-1));
int fix(ll n) { return (n % MOD + MOD) % MOD; }
int fix(ll n, int MOD) { return (n % MOD + MOD) % MOD; }

map<ll, char> mm;

int main()
{
  if (CIN_ONLY) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  ll n, m;
  string s, t;
  cin >> n >> m;
  cin >> s >> t;
  ll len = n * m / __gcd(n, m);
  for (int i = 0; i < n; ++i) {
    mm[i * len / n] = s[i];
  }
  for (int i = 0; i < m; ++i) {
    auto it = mm.find(i * len / m);
    if (it != mm.end()) {
      if (it->second != t[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << len << endl;
  return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

  if(a <= b*2){
    cout << 0 << "\n";
  }else{
    cout << a - b*2 << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  for (ll i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }

  vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j <= W; j++) {
      if (j - w[i] >= 0) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
      }
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    }
  }
  /*for (ll i = 0; i <= N; i++) {
    for (ll j = 0; j <= W; j++) {
      printf("%3d", dp[i][j]);
    }
    cout << endl;
  }*/
  cout << dp[N][W] << endl;
  return 0;
}

Measured memory_bytes: 83072
H = []
W = []
while(True):
    x,y = map(int,input().split())
    if x == 0 and y == 0:
        break
    else:
        H.append(x)
        W.append(y)
for i in range(len(H)):
    for j in range(H[i]):#行数
        if j+1 == H[i]:
            print(W[i]*"#"+"\n")#列数
        else:
            print(W[i]*"#")#列数


Measured memory_bytes: 5632
import math

def permutations(a,b):
    return math.factorial(a)//math.factorial(a-b)

n, m = map(int, input().split())
if abs(n-m)>=2:
    print(0)
elif abs(n-m)==1:
    print(permutations(n,n)*permutations(m,m)%(10**9+7))
else:
    print(permutations(n,n)*permutations(m,m)*2%(10**9+7))

Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
#define incant() cin.tie(0), ios::sync_with_stdio(false)
#define int long long
#define double long double
template <class T> using vec = vector<T>;
template <class T> using que = queue<T>;
template <class T> using pque = priority_queue<T>;
template <class... T> using tup = tuple<T...>;
using vint = vec<int>;
using vstr = vec<string>;
using pint = pair<int, int>;
using vp = vec<pint>;
using tint = tup<int, int, int>;
using vt = vec<tint>;
using mint = map<int, int>;
using dict = map<string, int>;
using qint = que<int>;
using qp = que<pint>;
using pqint = pque<int>;
using pqp = pque<pint>;
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload3(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
#define print(x) out(x), indent()
#define debug(x) cerr << __LINE__ << ": " << #x << ": " << (x) << '\n'
#define YN(x) print((x) ? "YES" : "NO")
#define Yn(x) print((x) ? "Yes" : "No")
#define yn(x) print((x) ? "yes" : "no")
#define POS(x) print((x) ? "POSSIBLE" : "IMPOSSIBLE")
#define Pos(x) print((x) ? "Possible" : "Impossible")
#define pos(x) print((x) ? "possible" : "impossible")
const int INF = LLONG_MAX - INT_MAX, MOD = 1e9 + 7, LIMIT = 100001;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
// const int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
int gcd(int a, int b){return b == 0 ? a : gcd(b, a%b);}
int lcm(int a, int b){return a / gcd(a, b)*b;}
int factorial(int a){return a < 2 ? 1 : factorial(a - 1)*a;}
int summation(int a){return a < 1 ? 0 : (a*a + a) / 2;}
int combination(int n, int r){int res = 1; rep(i, 1, r + 1) res *= n--, res /= i; return res;}
struct UF{
    vint data;
    UF(int size): data(size, -1){}
    int root(int x){return data[x] < 0 ? x : data[x] = root(data[x]);}
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x != y){
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y], data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y){return root(x) == root(y);}
    int size(int x){return -data[root(x)];}
};
int a, b, c, k, n, m, x, y, z, w, h, res = 0, cnt = 0, sum = 0, mx = -INF, mn = INF;
string s, t;

signed main(){
    incant();
    cin >> a >> b >> k;
    rev(i, min(a, b) + 1){
        if(a%i == 0 && b%i == 0){
            k--;
            if(k == 0){
                print(i);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
    using namespace std;
     
    bool isdivisor(int a, int b){
      return (a/b)*b==a;
    }

    int main(){
      int a,b,k;
      cin>>a>>b>>k;
      int ans=min(a,b);
      while(k>0){
        if(isdivisor(a,ans)&&isdivisor(b,ans)){ k--; }
        ans--;
      }
      cout<<ans+1<<endl;
      return 0;
    }

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

using namespace std;
typedef long long ll;
int N;
int A,B;
ll h[100001];

bool enough(ll x) {
  ll tmp = 0;
  for(int i = 0; i < N; i++) {
    ll s = h[i];
    s -= B * x;
    if(s > 0) {
      s % (A - B) == 0 ? tmp += s / (A - B) : tmp += s / (A - B) + 1;
    }
  }
  if(x < tmp) return false;
  else return true;
}
    
int main() {
  cin >> N >> A >> B;
  for(int i = 0; i < N; i++) cin >> h[i];

  sort(h,h+N,greater<ll>());

  ll l = 0;
  ll r = h[0] / B + 1;
  ll mid = (l + r) / 2;
  while(r - l > 1) {
    mid = (l + r) / 2;
    if(enough(mid)) r = mid;
    else l = mid;
  }

  cout << r << endl;
      
}
  


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string s;
string cs;
int main(){
	cin>>s;
	int slong=s.size();
	for(int i=slong-1;i>=0;i--)
		cs+=s[i];
	for(int i=0;i<slong;i++)
	{
		if(cs[i]=='b') cs[i]='d';
		else if(cs[i]=='d') cs[i]='b';
		else if(cs[i]=='p') cs[i]='q';
		else if(cs[i]=='q') cs[i]='p';
	}
	if(cs==s)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 640
let () = Scanf.scanf "%d %d %d" (fun a b c ->
  let x,y = min a (min b c), max a (max b c) in
  let z = a+b+c-x-y in
  1 + (if x<>z then 1 else 0) + (if z<y then 1 else 0))
|> Printf.printf "%d\n"


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

int main(void){
    using namespace std;
    int a[13][13],b[100001];
    long long int ans[13],c[13];
    int num=0;
    char s[100000];
    scanf("%s",s);
    for(int i=0;i<13;i++){
        for(int j=0;j<13;j++)a[i][j]=0;
        ans[i]=0;
        c[i]=0;
    }
    for(int i=0;i<130;i++)a[i/10][i%10]=i%13;
    for(int i=0;i<100001;i++){
        if((int)s[i]-(int)'0'>=0&&(int)s[i]-(int)'0'<=9)b[i]=(int)s[i]-(int)'0';
        else if(s[i]=='?')b[i]=10;
        else{
            num=i;
            break;
        }
    }
    for(int i=0;i<num;i++){
        if(i==0){
            if(b[i]==10){
                for(int j=0;j<10;j++){
                    ans[a[0][j]]++;
                }
            }
            else ans[a[0][b[i]]]++;
        }
        else{
            for(int j=0;j<13;j++){
                c[j]=ans[j];
                ans[j]=0;
            }
            for(int j=0;j<13;j++){
                if(j<=9||i>=2){
                    for(int k=0;k<10;k++){
                        if(b[i]==k||b[i]==10){
                            ans[a[j][k]]+=c[j];
                        }
                    }
                }
            }
        }
        for(int j=0;j<13;j++){
            ans[j]%=1000000007;
        }
    }
    cout<<ans[5]<<endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <strstream>
#include <string>
#include <deque>
#include <vector>
typedef unsigned int UINT;
using namespace std;

int main(void) {
    string S;
    cin >> S;
    for (char & a : S) {
        if (a == '1')
            a = '9';
        else if (a == '9')
            a = '1';
    }
    cout << S;
    return 0;
}

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

int main(void){

	int n,m=0;
    cin >> n;
    if(n % 2 == 0){
        m = n / 2;
        //cout << m << endl;
    }else{
        m = n / 2 + 1;
        //cout << m << endl;
    }
    float que;
    que = (float)m / (float)n;

    cout << que << endl; 



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s[0]=='S'&&s[1]=='U'&&s[2]=='N')cout<<7;
	if(s[0]=='M'&&s[1]=='O'&&s[2]=='N')cout<<6;
	if(s[0]=='T'&&s[1]=='U'&&s[2]=='E')cout<<5;
	if(s[0]=='W'&&s[1]=='E'&&s[2]=='D')cout<<4;
	if(s[0]=='T'&&s[1]=='H'&&s[2]=='U')cout<<3;
	if(s[0]=='F'&&s[1]=='R'&&s[2]=='I')cout<<2;
	if(s[0]=='S'&&s[1]=='A'&&s[2]=='T')cout<<1;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--) {
        
    // }
    int n;
    cin>>n;
    cout<<n*n*n<<endl;   
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,ans=1;
  string s;
  cin>>n>>s;
  map<char,ll> mp;
  rep(i,n){
    mp[s[i]]++;
  }
  for(auto tmp:mp){
    ans*=(tmp.second+1);
    ans%=MOD;
  }
  cout<<(ans-1)<<endl;
}

Measured memory_bytes: 512
N=int(input())
tra=[[0,0,0]]
for i in range(N):
  t, x, y=map(int, input().split())
  tra.append([t,x,y])

ans="Yes"
for i in range(N):
  t_now=tra[i][0]
  x_now=tra[i][1]
  y_now=tra[i][2]
  
  t_next=tra[i+1][0]
  x_next=tra[i+1][1]
  y_next=tra[i+1][2]
  
  mind=abs(x_now-x_next)+abs(y_now-y_next)
  tdis=t_next-t_now
  
  # 遠すぎて移動できないときと、時間差と距離の偶奇が不一致の時アウト
  if mind>tdis or (mind+tdis)%2==1:
    ans="No"
    break

print(ans)

Measured memory_bytes: 19544
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template <typename T>
struct edge {
    int from, to;
    T cost;

    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

    explicit operator int() const {return to;}
};

template <typename T>
vector<int> dijkstra(int s,vector<vector<edge<T>> > &G){
    int n=G.size();
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;
    vector<T> d(n, INF);
    vector<int> b(n,-1);
    priority_queue<P,vector<P>,greater<> > Q;
    d[s]=0;
    Q.emplace(d[s],s);
    while(!Q.empty()){
        T cost;
        int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int V, E, R;
    scanf("%d %d %d", &V, &E, &R);
    vector<vector<edge<int> > > g(V);
    for(int i = 0; i < E; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        g[a].emplace_back(b, c);
    }
    for(auto &dist : dijkstra(R, g)) {
        if(dist == numeric_limits< int >::max()) puts("INF");
        else printf("%d\n", dist);
    }
}



Measured memory_bytes: 15776
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

long long int nCr(int n, int r){
    if(n < r || r < 0) return 0;
    if (n >= f.size()){
        factorial_Initialize(n);
    }
    return f[n] * f_inverse[r] % MOD * f_inverse[n-r] % MOD;
}

int main(){
    int n, m;
    cin >> n >> m;
    factorial_Initialize(1e6);

    long long int ans = 0;
    int phase = 1;
    for(int i=0; i<=n; i++){
        long long int add  = nCr(n  , i);
        long long int same = nCr(m  , i)   * f[i];
        long long int diff = nCr(m-i, n-i) * f[n-i];

        same %= MOD;
        diff %= MOD;

        add *= (((same * diff) % MOD) * diff) % MOD;
        add %= MOD;

        //cout << add << " ";

        ans += phase * add;
        ans = (ans % MOD + MOD) % MOD;

        phase *= -1;
    }
    //cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34408
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

S = input()
succ = 0
ans = 0
for ch in S:
    if ch == 'R':
        succ += 1
        ans = max(ans, succ)
    else:
        succ = 0
ans = max(ans, succ)
print(ans)




Measured memory_bytes: 10800
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (S[S.length() - 1] == 's') {
		cout << S << "es" << endl;
	}
	else {
		cout << S << "s" << endl;
	}




	
}


Measured memory_bytes: 3596
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int w = saori.saori_hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		if(Math.abs(a-b) <= w){
			System.out.println(0);
		} else {
			System.out.println(Math.abs(a-b)-w);
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
#include <stdio.h>
#include <cstring>
#include <map>
#include <math.h>
#include <vector>

#define INF 100000000
#define ABS(a) (a<0?-(a):a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define REP(i,a) for(int i=0;i<a;i++) 

using namespace std;
int main(){
  int a,b;
  scanf("%d%d", &a, &b);
  a += b;
  if(a >= 10){
    printf("error\n");
  }else{
    printf("%d\n", a);
  }
}


Measured memory_bytes: 128
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,k,max_b=1,ans;
  cin >> n>>k;
  ll a[n],sum[n+1];
  vector<ll> v,tmp;
  sum[0]=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum[i+1] = sum[i]+a[i];
  }
  for(ll i=1;i<sum[n];i<<=1){
    max_b++;
  }
  max_b--;
  for(int i=0;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      v.push_back(sum[j]-sum[i]);
    }
  }
  for(ll i=((ll)1<<max_b);i>=1;i>>=1){
    for(auto j:v){
      if(j&i){
        tmp.push_back(j);
      }
    }
    if(tmp.size()>=k){
      v = move(tmp);
    }
    tmp.clear();
  }
  if(v.size()<k){
    ans = 0;
  }else{
    ans = v[0];
    for(ll i=1;i<v.size();i++){
      ans &= v[i];
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
   long int a,b;
  cin>> a >> b;
  
 if(((a+b)%2==0)){ 
 	cout<<(a+b)/2 <<endl;
 	
 }
 
 else{
  cout<<"IMPOSSIBLE" <<endl;
 }
 return 0;
 
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int ans = 0;
      ans = b%a==0 ? a+b:b-a;
      System.out.println(ans);
    }
  }

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll N, L;
  cin >> N >> L;
  ll sum{};
  if(L <= 0 && N + L - 1 >= 0);
  else if(N + L - 1 < 0) sum -= N + L - 1;
  else if(L > 0) sum -= L;
  rep(i, L, N + L) sum += i;
  cout << sum << rt;
}

Measured memory_bytes: 256