akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;

int main() {
  int N,D;
  cin>>N>>D;
  
  vector<vector<int>> v(N,vector<int>(D));	// ２次元配列を０で初期化
  
  for(int i=0;i<N;++i){
    for(int j=0;j<D;++j){
    	cin>>v[i][j];
    }
  }
  
  int count=0;
  
  for(int i=0;i<N-1;++i){
    for(int j=i+1;j<N;++j){
      
      int a=0;
      for(int k=0;k<D;++k){
        int diff=v[i][k]-v[j][k];
        a+=diff*diff;
      }
      
      // a=k^2となるkがあるか判定
      bool flag=false;	
      for(int k=0;k<=a;++k){			// k<=a
        if(a==k*k)
          flag=true;
      }
      
      if(flag)
        ++count;
    }
  }
  
  cout<<count<<endl;
}


Measured memory_bytes: 256
text = input()

targets = ['A','T','C','G']

exist = False
for i in targets:
    if i in list(text):
        exist = True
        break

max_len_answer = ''

if exist:
    answer = ''
    for i in range(len(text)):
        if text[i] in targets:
            answer += text[i]
        else:
            if len(answer) >= len(max_len_answer):
                max_len_answer = answer
            answer = ''
        if i == len(text) - 1:
            if len(answer) >= len(max_len_answer):
                max_len_answer = answer


print(len(max_len_answer))

Measured memory_bytes: 3064
#include <iostream>
 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
long long a[200005],b[200005];
int main(int argc, char** argv) {

int n;
cin>>n;
for(int i=1;i<=n;i++){

    cin>>a[i];
}
int l=1,r=n,flag=0;
for(int i=n;i>=1;--i){
	if(flag==0)b[l++]=a[i],flag=1;
	else b[r--]=a[i],flag=0;
}
for(int i=1;i<=n;++i)
printf("%lld ",b[i]);
return 0;
}

Measured memory_bytes: 5880
#include <bits/stdc++.h>
#define pb push_back
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define fastio() ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3c3c3c3c;
const ll infl = 0x3c3c3c3c3c3c3c3c;

int N, A, B;
int main(){
    fastio();
    cin >> N >> A >> B;
    if(abs(A - B) % 2) cout << "Borys";
    else cout << "Alice";
}


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

const int N = 205, P = 998244353;

int n, h[N], t;
bool v[N][N];

int qp (int a, int b) { int c = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) c = 1ll * c * a % P; return c; }

struct Vector {
	int x, y;
}p[N];

Vector operator - (const Vector &A, const Vector &B) { return Vector{A.x - B.x, A.y - B.y}; }
int operator * (const Vector &A, const Vector &B) { return A.x * B.y - A.y * B.x; }

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d%d", &p[i].x, &p[i].y);
	int ans = qp(2, n) - 1 - n;
	for (int i = 1; i <= n; ++i) {
		h[1] = i;
		for (int j = i + 1; j <= n; ++j) if (!v[i][j]) {
			h[t = 2] = j;
			for (int k = j + 1; k <= n; ++k) if ((p[k] - p[i]) * (p[j] - p[i]) == 0) h[++t] = k;
			ans = (ans - qp(2, t) + 1 + t) % P;
			for (int a = 1; a <= t; ++a) for (int b = 1; b <= t; ++b) v[h[a]][h[b]] = 1;
		}
	}
	printf("%d\n", (ans + P) % P);
	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 numA = sc.nextInt();
        int numB = sc.nextInt();
        int numC = sc.nextInt();
        int numD = sc.nextInt();
        
        int sumA = numA * numB;
        int sumB = numC * numD;
        
        int ans = 0;
        
        if(sumA >= sumB){
            ans = sumA;
        }else{
            ans = sumB;
        }
        
        System.out.println(ans);
	}
}

Measured memory_bytes: 20948
#最大公約数を求める
n = int(input())
a = list(map(int,input().split()))
gcd = a[0]
for i in range(1,n):
  b = gcd
  c = a[i]
  while c != 0:
    d = b % c
    b = c
    c = d
  gcd = b
print(gcd)

Measured memory_bytes: 15020
import java.util.*;
import java.util.Collections;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] x = new int[N];
        ArrayList<Integer> list = new ArrayList<Integer>();

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            list.add(A[i]);
            x[A[i]-1] = i+1;
        }

        Collections.sort(list);

        for(int i=0; i<N; i++){
            System.out.print(x[list.get(i)-1] + " ");
        }
    }
}

Measured memory_bytes: 65516
n,m=map(int,input().split())
a=0
p=0
L=[0 for _ in range(n)]
for _ in range(m):
  num,s = input().split()
  num=int(num)-1
  if not L[num] == -1:
    if s == "AC":
      a+=1
      p+=L[num]
      L[num]=-1
    else:
      L[num]+=1
print(a,p)

Measured memory_bytes: 9820
#include<bits/stdc++.h>
#define NMAX 100001

using namespace std;

long long N, W, v, w, maxx;
long long a[NMAX];

int main()
{
    cin>>N>>W;
    for(int i = 0 ; i < N ; i++){
        cin>>w>>v;
        for(int j = W - w ; j >= 0 ; j--){
            if(a[j] || !j){
				a[j + w] = max(a[j + w], a[j] + v);
				maxx = max(a[j + w], maxx);
            }
        }
    }
    cout<<maxx;
    return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
bool R(){return true;}
template<typename T, typename ... Args>
bool R(T & x, Args & ... args){return cin >> x && R(args...);}
void init_io(){ios::sync_with_stdio(false);cin.tie(0);}

#define PB push_back
#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define ALL(vec) (vec).begin(), (vec).end()
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF   1000000007
#define INFLL 4000000000000000007LL

int n, m, a[200014], b[200014];
ll k, prefa[200014], prefb[200014];

void solve ()
{
  R(n, m, k);
  FOR(i, 1, n + 1) R(a[i]);
  FOR(i, 1, m + 1) R(b[i]);
  prefa[0] = prefb[0] = 0;
  FOR(i, 1, n + 1) prefa[i] = prefa[i - 1] + a[i];
  FOR(i, 1, m + 1) prefb[i] = prefb[i - 1] + b[i];
  int pa, pb;
  pa = pb = 0;
  while (pb <= m && prefb[pb] <= k) ++pb;
  --pb;
  int res = 0;
  while (1)
  {
    if (prefa[pa] + prefb[pb] <= k) res = max(res, pa + pb);
    if (++pa > n) break;
    while (pb > 0 && prefb[pb] > k - prefa[pa]) --pb;
  }
  printf("%d\n", res);
}

int main ()
{
  init_io();
  int T = 1;
  //R(T);
  while (T--) solve();
  return 0;
}


Measured memory_bytes: 8408
from collections import deque
h,w=map(int,input().split())
field=[["#"]+list(input())+["#"] for i in range(h)]
field=[["#" for i in range((w+2))]]+field+[["#" for j in range(w+2)]]
def bfs(a,b):
  Q=deque([(a,b)])
  s=[[0 for i in range(w+2)] for j in range(h+2)]
  visited=[[False for i in range(w+2)] for j in range(h+2)]
  visited[a][b]=True
  while Q:
    v=Q.popleft()
    for i in [(1,0),(0,-1),(-1,0),(0,1)]:
      if visited[v[0]+i[0]][v[1]+i[1]]:continue
      if field[v[0]+i[0]][v[1]+i[1]]=="#":continue
      visited[v[0]+i[0]][v[1]+i[1]]=True
      s[v[0]+i[0]][v[1]+i[1]]=s[v[0]][v[1]]+1
      Q.append([v[0]+i[0],v[1]+i[1]])
  return max([max(s[i]) for i in range(h+2)])
ans=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if field[i][j]=="#":continue
    if bfs(i,j)>ans:ans=bfs(i,j)
print(ans)

Measured memory_bytes: 46428
class FenwickTree():
    def __init__(self, n):
        self.n = n
        self.data = [0] * n

    def add(self, p, x):
        #assert 0 <= p < self.n
        p += 1
        while p <= self.n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, r):
        s = 0
        while r:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def range_sum(self, l, r):
        #assert 0 <= l <= r <= self.n
        return self.sum(r) - self.sum(l)

import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
A = tuple(map(int, input().split()))

ft = FenwickTree(N)
res = []

for i, a in enumerate(A):
    ft.add(i, a)

for _ in range(Q):
    q, x, y = map(int, input().split())
    if q:
        res.append(str(ft.range_sum(x, y)))

    else:
        ft.add(x, y)

print('\n'.join(res))

Measured memory_bytes: 167232
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val H, W = in.next().toInt
  val S = new Array[String](H)
  for (i <- 0 until H)
    S(i) = in.next()


  //
  var ans = 0
  val q = new Queue[((Int, Int), Int)]
  val dp = Array.ofDim[Boolean](H, W)

  for (ny <- 0 until H)
    for (nx <- 0 until W) {
      for (y <- 0 until H; x <- 0 until W) {
        dp(y)(x) = false
      }

      q.enqueue(((nx, ny), 0))
      while (!q.isEmpty) {
        val ((x, y), d) = q.dequeue()
        if (!dp(y)(x) && S(y)(x) == '.') {
          dp(y)(x) = true
          ans = ans max d

          Seq((x-1, y), (x+1, y), (x, y-1), (x, y+1))
            .filter { case (x, y) => 0 <= x && x < W && 0 <= y && y < H }
            .foreach { p =>
              q.enqueue((p, d+1))
            }
        }
      }
    }

  println(ans)


}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 70864
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

l,r,d=invr()
ans=0

for i in range(l,r+1):
	if i%d==0:
		ans+=1

print(ans)

Measured memory_bytes: 62056
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
 
const int MAXN = 400100;
vector<PII> graph[MAXN];
 
void add_edge(int v, int u, int c) {
  graph[v].push_back(PII(u,c));
  graph[u].push_back(PII(v,c));
}
 
 
int main() {
  int N, D;
  cin >> N >> D;
  for(int i=0; i<N; i++) {
    LL p;
    cin >> p;
    add_edge(i, i+N, p);
  }
 
  for(int i=0; i<N-1; i++) {
    int v,u,c;
    //cin >> v >> u >> c;
    //v--;u--;
    add_edge(i, i+1, D);
  }
 
  priority_queue<pair<LL,PII> , vector<pair<LL,PII> >, greater<pair<LL,PII> > > pq;
  vector<int> used(2*N, 0), dist(2*N, 0);
  int cnt = 1;
  LL ans = 0;
  for(int i=0; i<N; i++) {
    pq.push(make_pair(0, PII(i+N, -1)));
  }
  while(!pq.empty()) {
    auto cur = pq.top(); pq.pop();
    LL v = cur.second.first;
    if(used[v]) {
      LL u = cur.second.second;
      if(used[v] > used[u])
	ans += dist[v] + cur.first;
      continue;
    }
    used[v] = cnt;
    cnt++;
    dist[v] = cur.first;
    for(auto uc: graph[v]) {
      LL u = uc.first;
      LL c = uc.second;
      pq.push(make_pair(dist[v] + c, PII(u, v)));
    }
    
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 55276
N = gets.to_i
N.times do
    row = Array.new(N, 0)
    line = gets.chomp.split(" ").map(&:to_i)
    k = line[1]
    if k > 0
        line[2..(k+1)].each do |i|
            row[i-1] = 1
        end
    end
    puts row.join(" ")
end



Measured memory_bytes: 6944
S = input()
N = len(S)

l, r = -2, -2
if S[0] == S[1]:
    l, r = 0, 1
else:
    for i in range(2, N):
        if S[i-1] == S[i]:
            l, r = i-1, i
            break
        elif S[i-2] == S[i]:
            l, r = i-2, i
            break
print(l+1, r+1)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
using namespace std;
int solve(int num,int sum,int x){
	if(num == 0 && sum == 0) return 1;
	if(x == 10) return 0;
	return solve(num-1,sum-x,x+1) + solve(num,sum,x+1);
}
int main(){
	while(1){
		int n,s;
		scanf("%d%d",&n,&s);
		if(n == 0 && s == 0) break;
		cout << solve(n,s,0) << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let X = read::<i32>();
    let t = read::<i32>();

    if (X-t) > 0 {
        println!("{}", X-t);
    }else {
        println!("0");
    }
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	
	int zr=0;
	for(auto x: s) if(x=='0') zr++;
	int mn = min(zr, sz(s)-zr);
	cout << 2 * mn <<"\n";
	return 0;
}


Measured memory_bytes: 512
use std::cmp::min;
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(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:i32 = read();
    let an:Vec<i64> = read_vec();
    let s:i64 = an.iter().sum();
    let mut x = 0;
    let mut ans = 1000000000000000000 ;
    for i in 0..(n-1){ 
        x += an[i as usize];
        if i+ 1 < n {
            ans = min(ans,(s- 2 *x).abs());
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 10492
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
#include <assert.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

#define HIT(a,b) ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)<(a.r+b.r)*(a.r+b.r))

struct DISK{
	int x,y,r,c,o;
	DISK():o(0){}
};
int n;

char visited[1<<24];

int main(){
	ios::sync_with_stdio(false);
	for(int T=1;cin >> n, n;T++){
		vector<DISK> D(n);
		REP(i, n) cin>>D[i].x>>D[i].y>>D[i].r>>D[i].c;
		REP(j, n)REP(i, j)if(HIT(D[i],D[j])) D[j].o |= 1<<i;
		int ans = 0;
		queue<int> dp;
		dp.push(0);
		while(!dp.empty()){
			const int b = dp.front(); dp.pop();
			REP(j, n)REP(i, j)if(!((b >> i) & 1)){
				if(visited[b|1<<i|1<<j]==T || (b >> i) & 1 || (b>>j) & 1 || D[i].c != D[j].c || ~b & D[i].o || ~b & D[j].o) continue;
				dp.push(b|1<<i|1<<j);
				visited[b|1<<i|1<<j]=T;
			}
			ans = max(ans, __builtin_popcount(b));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 19072
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True
#for i in range(n):

ans=0
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

a,b=LI()

ans=[]


print(a*b//gcd(a,b))




Measured memory_bytes: 39276
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int r = int.Parse(ReadLine());
            WriteLine(r * r);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL
string arr[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  string s;cin >> s;
  for(int i=0;i<7;i++){
    if(arr[i]==s){
      cout << 7-i << endl;
      return 0;
    }
  }
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  vector<int> ss[m];
  rep(i, m){
    int k;cin>>k;
    rep(j, k){
      int t; cin>>t;
      t--;
      ss[i].push_back(t);
    }
  }

  vector<int> p(m);
  rep(i, m)cin>>p[i];

  int result=0;
  rep(bits, pow(2, n)){
//cout<<bits<<endl;
    vector<int> cp(m);
    rep(s, n){
      if( !((bits>>s)&1) )continue;
      rep(lamp, m)for(auto ts: ss[lamp]){
        if(ts==s)cp[lamp]++;
      }
    }

    bool f=true;
    rep(i, m)if(cp[i]%2!=p[i])f=false;
    if(f)result++;
//    if(f){rep(i, m)cout<<cp[i]%2<<' ';cout<<endl;}

  }

  cout<<result<<endl;
//  rep(i, m)cout<<p[i]%2<<' ';cout<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;

    int m=a*x+b*y;

    for(int k=0;k<2*max(x,y)+1;k++){
        int i=max(0,(x-k/2));
        int j=max(0,(y-k/2));

        if(m>a*i+b*j+c*k){
            m=a*i+b*j+c*k;
        }
    }

    cout << m << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)
#define EPS (1e-4)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

#define HASH(x) (x[0] + x[1]*4 + x[2]*16 + x[3]*64)

int dp[200][4][256];
int rev[4][4];
int board[5][5];

int ten[4] = { 0,60,70,80 };
int nn;

int solve(int now, int h){
  if(dp[nn][now][h] != -1) return dp[nn][now][h];
  int ret = 0;
  int *x = rev[now];

  for(x[0]=0;x[0]<4;x[0]++){
    for(x[1]=0;x[1]<4;x[1]++){
      for(x[2]=0;x[2]<4;x[2]++){
        for(x[3]=0;x[3]<4;x[3]++){
          int point = 0;
          REP(i,5){
            int p = board[now][i];
            if(p == 0) continue;
            p = p - 1;
            if(now != 0){
              if(i != 4) p += rev[now-1][i];
              if(i != 0) p += rev[now-1][i-1];
            }
            if(i != 4) p += rev[now][i];
            if(i != 0) p += rev[now][i-1];
            p = p % 4;
            point += ten[p];
          }

          if(now == 3){
            REP(i,5){
              int p = board[now+1][i];
              if(p == 0) continue;
              p = p - 1;
              if(i != 4) p += rev[now][i];
              if(i != 0) p += rev[now][i-1];
              p = p % 4;
              point += ten[p];
            }
            ret = max(ret, point);
          }else{
            int hash = HASH(x);
            ret = max(ret, point + solve(now+1,hash));
          }
        }
      }
    }
  }
  return dp[nn][now][h] = ret;
}

int main(){
  int n = getInt();
    memset(dp, -1, sizeof(dp));
  for(nn = 0; nn < n; nn++){
    REP(i,5) REP(j,5) board[i][j] = getInt();
    print(solve(0,0));
  }
  return 0;
}

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

int main(){
	int a,b,t;
	cin>>a>>b>>t;
	int cnt=0;
	for(int i=1;i<=t;i++){
		if(i%a==0)cnt+=b;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)

template<typename T>
T power(T x, long long n, const T &m){
	if(n == 0) return 1;
	if(n == 1) return x;
	T tmp = power(x, n/2, m);
	if(n%2 == 0) return tmp * tmp % m;
	else return tmp * tmp % m * x % m;
}

template<typename T>
T inverse(T x, T m){
	return power(x, m-2, m);
}

int N;
int A[200000], B[200000];
vector<int> e[200000];

int fact[200001], inve[200001];

int sz[200000];
int par[200000];
vector<int> chi[200000];
int dfs(int n, int p){
	par[n] = p;
	sz[n] = 1;
	rep(i, e[n].size()){
		if(e[n][i] == p) continue;
		chi[n].pb(e[n][i]);
		sz[n] += dfs(e[n][i], n);
	}
	return sz[n];
}

ll dp[200000] ={};

ll calc(int n);

map<int, ll> memo[200000];
ll solve(int n, int b){
	if(n == -1) return 1;
	if(b == par[n]) return calc(n);
	else{
		if(memo[n].count(b) == 1) return memo[n][b];
		ll ret = calc(n);
		ret %= MOD;
		ret *= inve[sz[n]-1];
		ret %= MOD;
		ret *= fact[N-sz[b]-1];
		ret %= MOD;
		ret *= fact[sz[b]];
		ret %= MOD;
		ret *= inve[N-sz[n]];
		ret %= MOD;
		ret *= inverse(solve(b, n), MOD);
		ret %= MOD;
		ret *= solve(par[n], n);
		ret %= MOD;
		return memo[n][b] = ret;
	}
}

ll calc(int n){ //親除く
	if(dp[n] != 0) return dp[n];
	ll ret = fact[sz[n]-1];
	rep(i, chi[n].size()){
		ret *= inve[sz[chi[n][i]]];
		ret %= MOD;
		ret *= calc(chi[n][i]);
		ret %= MOD;
	}
	return dp[n] = ret;
}

signed main(){
	scanf("%d", &N);
	rep(i, N-1){
		scanf("%d %d", A+i, B+i);
		A[i]--;
		B[i]--;
		e[A[i]].pb(B[i]);
		e[B[i]].pb(A[i]);
	}
	fact[0] = 1;
	inve[0] = 1;
	rep(i, N+1){
		fact[i+1] = (fact[i] * (ll)(i+1))%MOD;
		inve[i+1] = inverse((ll)fact[i+1], MOD);
	}
	dfs(0, -1);
	rep(i, N){
		ll ans = fact[N-1];
		rep(j, chi[i].size()){
			ans *= inve[sz[chi[i][j]]];
			ans %= MOD;
			ans *= calc(chi[i][j]);
			ans %= MOD;
		}
		if(i != 0){
			ans *= inve[N-sz[i]];
			ans %= MOD;
			ans *= solve(par[i], i);
			ans %= MOD;
		}
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 50048
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input1 = sc.nextLine();
        String input2 = sc.nextLine();
        String[] data = input1.split(" ");

        int pebbles = Integer.valueOf(data[0]);
        int indexesCount = Integer.valueOf(data[1]);

        if(pebbles>=indexesCount) {
            System.out.println(0);
            return;
        }

        ArrayList<Integer> indexes = new ArrayList<>();
        ArrayList<Integer> diffs = new ArrayList<>();
        String[] indexesString = input2.split(" ");

        for(String input: indexesString) {
            indexes.add(Integer.valueOf(input));
        }

        Collections.sort(indexes);
        Iterator<Integer> integerIterator = indexes.iterator();
        int lastNumber = integerIterator.next();
        while(integerIterator.hasNext()) {
            int nextNumber = integerIterator.next();
            diffs.add(nextNumber-lastNumber);
            lastNumber = nextNumber;
        }

        Collections.sort(diffs);
        Collections.reverse(diffs);

        Iterator<Integer> integerDiffIterator = diffs.iterator();
        int removeHigh = pebbles-1;

        while(removeHigh>0)
        {
            integerDiffIterator.next();
            removeHigh--;
        }
        int sum = 0;
        while(integerDiffIterator.hasNext()) {
           sum =  sum + integerDiffIterator.next();
        }
        System.out.println(sum);

    }
}


Measured memory_bytes: 48608
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
  IOS;
  int n,k;
  cin>>n>>k;
  string d,a;
  for(int i=0;i<k;++i){
	cin>>d;
	a+=d;
  }
  while(string::npos!=to_string(n).find_first_of(a)) ++n;
  cout<<n;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define INPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in"
#define OUTPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

void solve()
{
    int x;
    cin >> x;
    
    int ans = 1;
    for(int i = 2; i * i <= x; i++)
    {
        int cnt = i;
        while(cnt <= x)
        {
            ans = max(ans, cnt);
            cnt *= i;
        }
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    //freopen(INPUT, "r", stdin);freopen(OUTPUT, "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        
        int a = x/500;
        int b = x%500/5;
        
        int h = 1000*a + 5*b;
        System.out.println(h);
    }
}


Measured memory_bytes: 21844
#!/usr/bin/env python3
import copy

N, Ma, Mb = map(int, input().split())
a = []
b = []
c = []
for i in range(N):
    ai, bi, ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)

def update(mincosti, a_b, c):
    if a_b not in mincosti:
        mincosti[a_b] = c
        return
    if mincosti[a_b] > c:
        mincosti[a_b] = c
        return

mincost = [{(a[0],b[0]): c[0]}]

for i in range(1,N):
    mincost.append(copy.deepcopy(mincost[i-1]))
    update(mincost[i], (a[i],b[i]), c[i])
    for a_, b_ in mincost[i-1].keys():
        a_b = (a_+a[i], b_+b[i])
        update(mincost[i], a_b, mincost[i-1][(a_,b_)]+c[i])

Na = Ma
Nb = Mb

ans = None

while (Na <= 400) and (Nb <= 400):
    if (Na, Nb) in mincost[N-1].keys():
        if ans == None:
            ans = mincost[N-1][(Na, Nb)]
        else:
            ans = min(ans, mincost[N-1][(Na, Nb)])
    Na += Ma
    Nb += Mb

if ans == None:
    print(-1)
else:
    print(ans)


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

int n,k,a[200010];

void work()
{
	scanf("%d %d",&n,&k);
	for (int i=1,x; i<=n; i++)  scanf("%d",&x),a[x]++;
	sort(a+1,a+n+1),reverse(a+1,a+n+1);
	for (int i=1; i<=k; i++)  n-=a[i];
	printf("%d",n);
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
class act1
{
	public:
	int a,b,c;
};
int main()
{
	int n;
	cin>>n;
	vector<act1> v(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i].a;
		cin>>v[i].b;
		cin>>v[i].c;
	}
	int dp[n+1][3];
	//memset(dp,0,sizeof(dp));
	dp[1][0]=v[1].a;
	dp[1][1]=v[1].b;
	dp[1][2]=v[1].c;
	for(int i=2;i<=n;i++)
	{
		dp[i][0]=v[i].a+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=v[i].b+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=v[i].c+max(dp[i-1][1],dp[i-1][0]);
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, t;
	cin >> n >> t;
	int a, b, ans = 1145141919;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		if (b <= t)
		{
			ans = min(ans, a);
		}
	}
	if (ans == 1145141919)
	{
		cout << "TLE" << endl;
	}
	else
	{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))

# N, M = 4, 1
# A = [5, 4, 2, 1]

sum_vote = sum(A)
th = 1 / (4 * M)

A.sort(reverse=True)

count = 0
for i in range(M):
    # i = 0
    if A[i] / sum_vote >= th:
        count += 1
    else:
        break

if count >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,to=b;i<to;++i)
#define MOD 1000000007
using namespace std;
typedef long long ll;


int cc[3005][3005];

int comb(int n, int k){
	return cc[n][k];
}

char s[4096];
int n,m;
vector<pair<int,int> > w;
int sp[4096];
map<int,int> z;
int dp[3005][3005];

int f(int k, int q){
	if(dp[k][q]>=0)return dp[k][q];
	int r;
	if(k==w.size())r=1;
	else {
		int s=w[k].fst;
		int e=w[k].snd;
		int m0;
		if(k>0)m0=max(s,w[k-1].snd);
		else m0=s;
		int m1;
		if(k<w.size()-1)m1=min(e,w[k+1].fst);
		else m1=e;
		int n1=sp[e]-sp[m0]+q;
		int n0=e-s-n1;
		r=0;
		fore(j,0,min(e-m1,n1)+1){
			int jj=n1-j;
			r+=(1LL*comb(m1-s,jj)*f(k+1,j))%MOD;
			r%=MOD;
		}
	}
	return dp[k][q]=r;
}


int main(){
	memset(cc,0,sizeof(cc));
	fore(i,1,3005){
		cc[i][0]=cc[i][i]=1;
		fore(j,1,i){
			cc[i][j]=(cc[i-1][j-1]+cc[i-1][j])%MOD;
		}
	}
	scanf("%d%d%s",&n,&m,s);
	sp[0]=0;
	fore(i,1,n+1){
		sp[i]=sp[i-1]+s[i-1]-'0';
	}
	fore(i,0,m){
		int x,y;
		scanf("%d%d",&x,&y);x--;
		z[x]=max(z[x],y);
	}
	int k=-1;
	for(map<int,int>::iterator it=z.begin();it!=z.end();++it){
		int x=it->fst,y=it->snd;
		if(y<=k)continue;
		k=max(k,y);
		w.pb(mp(x,y));
	}
	memset(dp,-1,sizeof(dp));
	printf("%d\n",f(0,0));
	return 0;
}

Measured memory_bytes: 71040
var abk;
function ex(a, b) {
  if (abk[a] % 2 == 1) -- abk[a];
  abk[a] /= 2
  abk[b] += abk[a];
}
function Main(input) {
    abk = input.split("\n")[0].split(/\s/).map(function(value) { return value - 0; });
    var K = abk[2];
    for (var n = 1; n <= K; n++) {
      if (n % 2 == 1) ex(0, 1);
      else ex(1,0);
    }
    console.log('%d %d', abk[0], abk[1]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <stdio.h>
 
int main(void) {

	// ??????????????\??????????????°?????\???????????°
	int num;
	scanf("%d", &num);

	// ???????????????
	int build[15][10] ={};

	//???????????????left:?????????????????????right:?????????????????????
	int ridge, stage, order, man;
	int left, right;

	// ??\?????????????£?????????°?????¨?±????????????°??????????????\??????
	for (int cnt = 0; cnt < num; cnt++) {

		scanf("%d", &ridge);
		scanf("%d", &stage);
		scanf("%d", &order);
		scanf("%d", &man);

		left = (ridge - 1) * 4 + stage - 1;
		right = order - 1;

		build[left][right] += man;
	}

	// ????????????????????????
	for (left = 0; left < 15; left++) {

		if (left == 3 || left == 7 || left == 11) {

			printf("####################\n");

		} else {

			for (right = 0; right < 10; right++) {

				switch (right) {

				case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
					printf(" %d", build[left][right]);
					break;

				case 9:
					printf(" %d\n", build[left][right]);
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1852
#include<cstdio>
#define A(a) ((a)>0?(a):-(a))
int n,m,k;
signed main()
{
	scanf("%d%d%d",&n,&m,&k);int t1,t2(0);
	while(n--)
	{
		t1=t2,scanf("%d",&t2);
	}
	return printf("%d\n",t1?(A(t2-t1)>A(t2-k)?A(t2-t1):A(t2-k)):A(t2-k)),0;
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}

fn main() {
    input! {
        n: usize,
        s: [chars; n],
    }
    let mut t = [50; 26];

    for s in s {
        let mut t2 = [0; 26];
        for c in s {
            t2[(c as u8 - b'a') as usize] += 1;
        }

        for i in 0..26 {
            t[i] = std::cmp::min(t[i], t2[i]);
        }
    }

    for i in 0..26 {
        for _ in 0..t[i] {
            print!("{}", (b'a' + i as u8) as char);
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
typedef pair<int, int> P;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    map<ll, int> m;
    ll tmp = n;
    for (ll i = 2; i * i < n; i++)
    {
        if (tmp % i == 0)
        {
            int cnt = 0;
            while (tmp % i == 0)
            {
                cnt++;
                tmp /= i;
            }
            m[i] = cnt;
        }
    }
    if (tmp > 1)
    {
        m[tmp] += 1;
    }
    ll res = 0;
    for (auto p : m)
    {
        for (int i = 1; i < 50; i++)
        {
            if (p.second >= i)
            {
                res++;
                p.second -= i;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3604
import itertools

(N, M, Q) = [int(n) for n in input().split()]
reqs = []
for _ in range(Q):
    a, b, c, d = [int(n) for n in input().split()]
    a -= 1
    b -= 1
    reqs.append((a, b, c, d))

ans = 0

for A in itertools.combinations_with_replacement(range(1, M+1), N):
    score = 0
    for a, b, c, d in reqs:
        if A[b] - A[a] == c:
            score += d
    ans = max(score, ans)
    #print('A = {} score = {}'.format(A, score))
print(ans)


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

int main(){
	int n;
	int count;

	while (cin >> n){
		
		count = 0;

		for (int a = 0; a < 10; a++){
			for (int b = 0; b < 10; b++){
				for (int c = 0; c < 10; c++){
					for (int d = 0; d < 10; d++){
						if (a + b + c + d == n)count++;
					}
				}
			}
		}
		
		cout << count << endl;
	
	}

	return 0;
}


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

int main(){
  vector<int> A;
  int x=0,n;
  
  cin >> n;
  A.resize(n);
  for(int i=0;i<n;i++){
    cin >> A[i];
  }

  for(int j=0;j<n-1;j++){
    if(A[j] <= A[n-1]){
      if(x!=j){
        A[x] ^= A[j]; A[j] ^=A[x]; A[x] ^= A[j];
      }
      x++;
    }
  }
  A[x] ^= A[n-1]; A[n-1] ^= A[x]; A[x] ^= A[n-1];

  cout << A[0];
  for(int i=1;i<n;i++){
    if(x==i) cout << " [" << A[i] << "]";
    else cout << " " << A[i];
  }
  cout << endl;
}


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

int main() {
    string S;
    ll K;
    cin >> S;
    cin >> K;
    int n = (int)S.size();
    int cnt = 0;
    
    if (n == 1){
        cout << K/2 << endl;
        return 0;
    }
    for (int i = 1; i < n; i++) {
        if (S[i] == S[i-1]) {
            cnt++;
            i++;
        }
    }
    ll ans;
    ans = cnt * K;
    if (S[0] == S[n-1]) {
        int l = 0;
        int r = n-1;
        while (S[l] == S[0] && l < r) {
            l++;
        }
        while (S[r] == S[n-1] && l < r) {
            r--;
        }
        if (l == n-1) {
            ans = (n * K) / 2;
        }
        else if ((l + (n-1-r)) % 2 == 0 && l % 2 == 1) {
            ans += (K-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

type point struct {
	x int
	y int
}

const k = 3

func checkBingo(val []int, b map[int]bool) bool {
	cnt := 0
	for _, v := range val {
		if b[v] {
			cnt++
			if cnt == 3 {
				return true
			}
		}
	}
	return false
}

func main() {
	a := make(map[point]int)
	for i := 0; i < k; i++ {
		for j := 0; j < k; j++ {
			var tmp int
			fmt.Scan(&tmp)
			a[point{j, i}] = tmp
		}
	}

	var n int
	fmt.Scan(&n)
	b := make(map[int]bool, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		b[tmp] = true
	}

	for i := 0; i < k; i++ {
		valr := make([]int, k)
		valc := make([]int, k)
		for j := 0; j < k; j++ {
			valr[j] = a[point{j, i}]
			valc[j] = a[point{i, j}]
		}
		if checkBingo(valr, b) || checkBingo(valc, b) {
			fmt.Println("Yes")
			return
		}
	}

	vald1 := make([]int, k)
	vald2 := make([]int, k)
	for i := 0; i < k; i++ {
		vald1[i] = a[point{i, i}]
		vald2[i] = a[point{k - 1 - i, i}]
	}
	if checkBingo(vald1, b) || checkBingo(vald2, b) {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
    using namespace std;
    #define For(i,a,b) for(int i = a;i<=b;++i)
    #define For_(i,a,b) for(int i = a;i>=b;--i)
    typedef long long LL;
    inline int read(){
        int r = 0,f = 1;
        char c = getchar();
        while(c<'0' || c >'9'){
            if(c =='-') f = -1;
            c = getchar();
        }
        while(c>='0' && c<='9'){
            r = (r<<1) + (r<<3) + c - '0';
            c = getchar();
        }
        return r * f;
    }
    int n;
    const int N = 1+5;
    int main(){
        n = read();
        if(n == 0) cout<<1<<endl;
        else cout<<0<<endl;
     
     
        system("pause");
        return 0;
    }

Measured memory_bytes: 3692
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;

long long mod = 1000000000 + 7;
long long dp[2005][2005];
long long sum[2005][2005];
long long s[2005];
long long t[2005];
int main(void){
	int n,m;scanf("%d%d",&n,&m);
	for(int i = 0;i < n;i++) cin >> s[i+1];
	for(int i = 0;i < m;i++) cin >> t[i+1];
	
	sum[0][0] = dp[0][0] = 1LL;
	for(int i = 0;i <= n;i++)sum[i][0] = 1LL;
	for(int j = 0;j <= m;j++)sum[0][j] = 1LL;
	long long ans = 1LL;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(s[i]==t[j]){
				dp[i][j] = (sum[i-1][j-1] )% mod;
				ans += dp[i][j];
			}
			sum[i][j] = (sum[i-1][j] + sum[i][j-1] + mod - sum[i-1][j-1] + dp[i][j]) % mod;
		}
	}
	cout << ans %mod << endl;
	return 0;
}


Measured memory_bytes: 62848
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Computation of Salary
 * PCK2013 ??¬???2
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();

		int N, M;
		N = parseInt(line.substring(0, line.indexOf(' ')));
		M = parseInt(line.substring(line.indexOf(' ') + 1));

		Map<Integer, Map<Integer, Integer>> map = new HashMap<>();
		
		for (int i = 1; i <= N; i++) map.put(i, new HashMap<>());

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			if (line.equals("0 0 0")) break;
			StringTokenizer st = new StringTokenizer(line);
			int s, t, e;
			s = parseInt(st.nextToken());
			t = parseInt(st.nextToken());
			e = parseInt(st.nextToken());
			map.get(s).put(t, e);
		}

		int L = parseInt(br.readLine());

		for (int i = 0; i < L; i++) {
			int[] b = new int[M + 1];
			StringTokenizer st = new StringTokenizer(br.readLine());
			for (int j = 1; j <= M; j++) {
				b[j] = parseInt(st.nextToken());
			}

			List<String> list = new ArrayList<>();

			for (int j = 1; j <= N; j++) {
				int c = 0;
				for (int t : map.get(j).keySet()) {
					c += b[t] * map.get(j).get(t);
				}
				list.add(String.valueOf(c));
			}

			System.out.println(String.join(" ", list));
		}
	}
}

Measured memory_bytes: 175492
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict

geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)
h = geta(int)

INF = 1 << 60
h += [INF]
dp = [INF, 0, INF]

for i in range(N - 1):
    dp1 = dp[1]
    dp[0] = dp1
    dp[1] = min(dp[2], dp1 + abs(h[i] - h[i + 1]))
    dp[2] = dp1 + abs(h[i] - h[i + 2])

print(dp[1])


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

int main(){
  priority_queue<ll> que;
  ll n, m, a, ans=0;
  cin >> n >> m;
  RAP(i, n){
    cin >> a;
    que.push(a);
  }
  RAP(i, m){
    a = que.top()/2;
    que.pop();
    que.push(a);
  }
  while(!que.empty()){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
using namespace std;
using LL = long long int;
int main(){
    int n;
    cin >> n;
    LL counter = 0;
    int last;
    cin >> last;
    for(int i = 0;i < n-1;i++){
        int buf;
        cin >> buf;
        if(last > buf){
            counter += last - buf;
        }else{
            last = buf;
        }

    }
    cout << counter ;


    return 0;
}


Measured memory_bytes: 3616