akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){

	ll n;
	cin>>n;
	ll a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	ll dp[n+1][n+1];
    ll sum[n+1];
    sum[0]=0;
    for(int i=1;i<=n;i++){
      sum[i]=sum[i-1]+a[i];
    }
    for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=1e18;
   for(int i=0;i<=n;i++) dp[i][i]=0;
        int i=1;

    	for(int j=i+1;j<=n;j++){
         
            dp[i][j]=a[i]+a[j];
          //  cout<<dp[i][j]<<" ";
            i++;
 
    }
   // cout<<endl;
 
    for(int len=2;len<n;len++){
        int i=1;
         
    	for(int j=i+len;j<=n;j++){

         
         for(int k=i;k<j;k++){
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]);
        
    	       }
         // cout<<dp[i][j]<<" ";
    	       i++;
    	}

    	///cout<<endl;
    }

   cout<<dp[1][n]<<endl;
}

Measured memory_bytes: 1536
xn=input().split()
x=int(xn[0])

data=input().split()
for i in range(100):
    for d in data:
        if int(d) == x-i:
            break
    else:
        print(x-i)
        break
    
    for d in data:
        if int(d) == x+i:
            break
    else:
        print(x+i)
        break
    

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    string s;
    FOR(i,0,b+2){
        cout << "#";
    }
    cout << endl;
    FOR(i,0,a){
        cin >> s;
        cout << "#";
        cout << s;
        cout << "#";
        cout << endl;
    }
    FOR(i,0,b+2){
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2010;
int n,a[N],sum;
bitset<N*N> dp;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
    dp[0]=1;
    for (int i=1;i<=n;i++) dp|=dp<<a[i];
    for (int i=(sum+1)>>1;;i++)
    if (dp[i]) printf("%d\n",i),exit(0);
    return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {//最大フロー求める Ford-fulkerson
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));//最小カットの場合逆辺は0にする
}

Matrix mat(202020,Array(1));
ll c[202020];

ll dfs(Graph& g, ll v, ll par,Array& num) {
	ll ret = 0;
	ll now = num[c[v]];
	REP(i, g[v].size()) {
		ll to = g[v][i].to;
		if (to == par)continue;
		mat[c[v]].push_back(0);
		num[c[v]] = mat[c[v]].size() - 1;
		ll tmp = dfs(g, to, v, num);
		mat[c[v]][num[c[v]]] += tmp;
		ret += tmp;

	}
	ret++;
	num[c[v]] = now;
	mat[c[v]][num[c[v]]] -= ret;
	return ret;
}


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


	ll n;
	cin >> n;
	Graph g(n);
	REP(i, n)cin >> c[i], c[i]--;
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		add_edge(g, a, b, 1, true, 1);
	}
	REP(i, n)REP(j,1)mat[i][j] = n;
	Array num(n, 0);
	
	dfs(g, 0, -1, num);
	REP(i, n) {
		ll ans = n * (n + 1) / 2;
		REP(j, mat[i].size()) {
			ans -= mat[i][j] * (mat[i][j] + 1) / 2;
		}

		cout << ans << "\n";
	}

	

	return 0;
}


Measured memory_bytes: 61708
/*
	In the name of ALLAH
	Author : Raashid Anwar
*/

#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define mod 1000000007


int power(int a,int b) {
	int r=1;
	while(b) {
		if(b&1)
			r=(r*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return r;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int x,k;
	cin>>x>>k;
	if(x*500>=k)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
P = []
t = []
for i in range(N - 1):
    if h[i] <= h[i+1]:
        t.append(h[i])
    else:
        t.append(h[i])
        P.append(t)
        t = []
t.append(h[N - 1])
P.append(t)
ans = 0
for j in range(len(P) - 1):
    ans += max(P[j]) - min(P[j+1])
    
ans += max(P[len(P)-1])

print(ans)

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println(euler_phi(n))
}

func euler_phi(n int) int {
	r := n
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			r = r / i * (i - 1)
			for ; n%i == 0; n /= i {
			}
		}
	}
	if n != 1 {
		r = r / n * (n - 1)
	}
	return r
}


Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
using ll = long long;
using namespace std;


void max_self(ll& a, ll b) {
	a = max(a, b);
}

void min_self(ll&a, ll b) {
	a = min(a, b);
}

const ll INF = 1e18 + 5;


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

	vector<int> weight(n), value(n);
	for (int i = 0; i < n; i++) {
		cin >> weight[i] >> value[i];
	}

	int sum_value = 0;
	for (int i : value)
		sum_value += i;
	
	vector<ll> dp(sum_value + 1, INF);
	dp[0] = 0;

	for (int item = 0; item < n; ++item) {
		for (int value_already = sum_value - value[item]; value_already >= 0; --value_already) {
			min_self(dp[value_already + value[item]], dp[value_already] + weight[item]);
		}
	}

	ll answer = 0;

	for (int i = 0; i <= sum_value; i++) {
		if (dp[i] <= W) {
			max_self(answer, ll(i));
		}
	}

	cout << answer;


	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
  int i,n,r,box[4][13]={{0}},digit,j;
  char mark;
  scanf("%d",&n);
  while(n>0)
  {
    scanf(" %c %d",&mark,&digit);
    if(mark=='S')r=0;
    else if(mark=='H')r=1;
    else if(mark=='C')r=2;
    else if(mark=='D')r=3;
    box[r][digit-1]=1;
    n--;
  }
  for(i=0;i<4;i++)
  {
    for(j=0;j<13;j++)
    {
      if(box[i][j]==0)
      {
        if(i==0)mark='S';
        else if(i==1)mark='H';
        else if(i==2)mark='C';
        else if(i==3)mark='D';
        printf("%c %d\n",mark,j+1);
      }
    }
  }
return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
int main(int argc, char const* argv[])
{
	int a,b,t;
	cin >> a >> b >> t;
	cout << ((t / a) * b) << endl;
	return 0;
}



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

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
int ans = 0;

int main(){
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

//Big Hit !
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int b = sc.nextInt();
			int r = sc.nextInt();
			int g = sc.nextInt();
			int c = sc.nextInt();
			int s = sc.nextInt();
			int t = sc.nextInt();
			if((b|r|g|c|s|t)==0)break;
			System.out.println(100 + b*15 + r*15 + (b*5+r*3)*15 + g*7 + c*2 - (b*5+r*3)*2 - (t-b*5-r*3-s)*3);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>

using namespace std;


int main ()
{
    int n;
    int tmp [100001] ;
    while (scanf ("%d",&n)!=EOF )
    {
        int now , ans;
        for (int i=0;i<n;i++ )
        {
            scanf ("%d",&tmp[i]) ;
        }
        now = 0,ans=0;
         for (int j=0;j<n;j++)
            {
                    ans+=abs(tmp[j] - now) ;
                    now = tmp [j] ;
                    //cout<<now<<endl;
            }
        ans+=abs(now) ;
        int res =ans;
       // cout<<res<<endl ;
        for (int i=0;i<n;i++)
        {
            ans=  res;
            if (i==0)
            {
                ans -= abs(tmp[0]) ;

                ans -=abs (tmp [1]- tmp [0]) ;

                ans += abs (tmp[1]) ;

            }
            else if (i==n-1)
            {
                 ans -= abs(tmp[i] -0) ;
                ans -=abs (tmp [i]- tmp [i-1]) ;
                ans += abs (tmp[i-1]) ;
            }
            else
            {
                 ans -= abs(tmp[i] -tmp[i-1]) ;
                ans -=abs (tmp [i]- tmp [i+1]) ;
                ans += abs (tmp[i-1] -tmp[i+1]) ;
            }
            printf ("%d\n",ans);
        }

    }
    return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,a,b,c=0,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    hin(a);
  }
  for(i=b=0;i<n;i++){
    a=N[hout()];//printf("%d %d\n",a,b);
    if(a-b){
      c++;
      b=a;
    }
    else{
      b=0;
      c--;
    }
  }
  printf("%d\n",c);
  return 0;
}
  


Measured memory_bytes: 4608
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ns()
a = int(n)
r = sum(map(int, list(n)))

if a % r == 0:
    print("Yes")
else:
    print("No")


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

using namespace std;

typedef long long ll;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    string o, e;

    cin >> o;
    cin >> e;

    int i, len = o.size() + e.size();
    int j = 0;
    int k = 0;

    for (i = 1; i <= len; i++) {
        if (i % 2 == 1) cout << o[j++];
        else cout << e[k++];
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (a, p) = readListOfInt() 
    val num = (a*3 + p) / 2
    println(num)
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37816
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,K = inputIL()
l = inputIL()

l.sort(reverse = True)

print(sum(l[:K]))

Measured memory_bytes: 38384
import sys, heapq
def input():
	return sys.stdin.readline()[:-1]

class DijkstraList():
	#隣接リスト版
	#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
	def __init__(self, adj, start):
		self.list = adj
		self.start = start
		self.size = len(adj)

	def solve(self):
		self.dist = [10**30 for _ in range(self.size)]
		self.dist[self.start] = 0
		self.prev = [-1 for _ in range(self.size)]
		self.q = []
		self.cnt = 0

		heapq.heappush(self.q, (0, self.start))

		while self.q and self.cnt < self.size:
			u_dist, u = heapq.heappop(self.q)
			if self.dist[u] < u_dist:
				continue
			for v, w in self.list[u]:
				if self.dist[v] > u_dist + w:
					self.dist[v] = u_dist + w
					self.prev[v] = u
					heapq.heappush(self.q, (self.dist[v], v))
			self.cnt += 1
		return

	def distance(self, goal):
		return self.dist[goal]

	def path(self, goal):
		self.path = [goal]
		while self.path[-1] != self.start:
			self.path.append(self.prev[self.path[-1]])
		return self.path[::-1]

INF = 10**20
n, m, s = map(int, input().split())
s = min(s, m*50)
adj = [[] for _ in range(n*(m+1)*50)]

for _ in range(m):
	u, v, a, b = map(int, input().split())
	u, v = u-1, v-1
	for i in range(a, m*50+1):
		adj[i * n + u].append(((i - a) * n + v, b))
		adj[i * n + v].append(((i - a) * n + u, b))

for i in range(n):
	c, d = map(int, input().split())
	for j in range(m*50):
		adj[j * n + i].append((min(m*50, j + c) * n + i, d))

dijk = DijkstraList(adj, s*n)
dijk.solve()
ans = [INF for _ in range(n)]
for num, x in enumerate(dijk.dist):
	i = num%n
	ans[i] = min(ans[i], x)
print(*ans[1:], sep="\n")

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	vector<int>dp(3);
	for(int i=0;i<n;i++){
		vector<int>new_dp(3,0);
		vector<int>c(3);
		for(int j=0;j<3;j++)cin>>c[j];
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(j!=k)new_dp[k]=max(new_dp[k],dp[j]+c[j]);
			}
		}dp=new_dp;
	}cout<<max({dp[0],dp[1],dp[2]});
	return 0;
}

Measured memory_bytes: 256
def isOK(x):
    return x == "".join(reversed(x))


def calculate(S):
    if isOK(S) == False:
        print("No")
        return

    arr = list(S)
    length = len(arr)

    s1 = arr[0:(length-1)//2]

    if isOK("".join(s1)) == False:
        print("No")
        return

    s2 = arr[(length+2)//2:length]

    if isOK("".join(s2)) == False:
        print("No")
        return

    print("Yes")




S = input()

calculate(S)


Measured memory_bytes: 3064
class FenwickTree:
    def __init__(self, size):
        self.size = size
        self.array = [0]*size
 
    def add(self, index, value):
        while index < self.size:
            self.array[index] += value
            index += index&(-index)
 
    def sum(self, index):
        answer = 0
        while index > 0:
            answer += self.array[index]
            index -= index&(-index)
        return answer
 
    def rangesum(self, start, end):
        return self.sum(end)-self.sum(start-1)


def solve():
    N, Q = map(int, input().split())
    *c, = map(int, input().split())
    tree2 = FenwickTree(N+1)
    m = [tuple(map(int, input().split())) for _ in range(Q)]
    idxs = sorted(tuple(range(Q)), key=lambda i: m[i][1])

    right = 0
    pos = [-1] * (N+1)
    ans = [-1] * (Q)

    for idx in idxs:
        l, r = m[idx]
        for i in range(right, r):
            x = pos[c[i]]
            if x != -1:
                tree2.add(x, -1)
            pos[c[i]] = i+1
            tree2.add(i+1, 1)
        ans[idx] = tree2.rangesum(l, r)
        right = r
    print(*ans, sep="\n")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 247956
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_N = 105;

int N, v[MAX_N];

bool check(int now){
  vector<int> vv;
  REP(i, N) if(i != now) vv.push_back(v[i]);
  int d = vv[1] - vv[0];
  FOR(i, 1, vv.size())
    if(vv[i] - vv[i - 1] != d) return false;
  return true;
}

int main() {
  while(cin >>N && N){
    ++N;
    REP(i, N) cin >>v[i];
    int ans = -1;
    REP(i, N)
      if(check(i)){
        ans = i;
        break;
      }
    cout <<v[ans] <<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,h,w;
	cin>>n>>h>>w;
	int ans=0;
	while(n--)
	{
		int a,b;
		cin>>a>>b;
		if(a>=h&&b>=w)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static char X[][] = {{'w', 'w', 'x'}, {'z', '.', 'x'}, {'z', 'y', 'y'}};

	static void solve() throws Exception {
		int n = scanInt();
		if (n == 2) {
			out.print(-1);
		} else if (n % 2 == 0) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					int ii = i / 2, jj = j / 2, nn = n / 2;
					out.print(ii == jj ? (i % 2 == 0 ? 'a' : 'b') : (ii - jj + nn) % nn == 1 ? (j % 2 == 0 ? 'c' : 'd') : '.');
				}
				out.println();
			}
		} else if (n % 3 == 0) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					out.print(i / 3 == j / 3 && (i % 3 == 0) != (j % 3 == 0) ? 'a' : '.');
				}
				out.println();
			}
		} else if (n % 3 == 2) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					out.print(i < 3 && j < 3 ? X[i][j] : i < 3 && j < 5 ? (char) ('a' + i) : i < 5 && j < 3 ? (char) ('a' + j) :
						i < 5 || j < 5 ? '.' : (i - 5) / 3 == (j - 5) / 3 ? X[(i - 5) % 3][(j - 5) % 3] :
						(i - 5) / 6 == (j - 5) / 6 && ((i - 5) % 3 == 0) != ((j - 5) % 3 == 0) ? 'q' : '.');
				}
				out.println();
			}
		} else /*(n % 3 == 1)*/ {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					out.print(i < 7 && j < 7 && (i == 0) != (j == 0) ? (char) ('a' + (i + j + 1) / 2) :
						i >= 7 && j >= 7 && (i - 7) / 3 == (j - 7) / 3 ? X[(i - 7) % 3][(j - 7) % 3] :
						i >= 1 && j >= 1 && (i - 1) / 6 == (j - 1) / 6 && ((i - 1) % 3 == 0) != ((j - 1) % 3 == 0) ? 'q' : '.');
				}
				out.println();
			}
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int start, end ;
  start = min(A, C);
  end   = max(B, D);
  
  int cnt = 0;
  bool Alice, Bob;
  for(int i = start; i < end; ++i) {
    if (i >= A && i < B) Alice = true;
    else Alice = false;
    if (i >= C && i < D) Bob = true;
    else Bob = false;
    if (Alice && Bob) ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int k,x; cin>>k>>x;
	cout<<(k*500>=x?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); i++)

using namespace std;
using pii = pair<int, int>;

const int N = 15;

pii data[N][N];
int guess[N];
int cnt = 0;
int ans = 0;

void dfs(int now, int n) {
  if (now == n) {
    if (cnt <= ans)
      return;
    int i;
    for (i = 0; i < n; i++) {
      if (guess[i] == 1) {
        int j;
        for (j = 0; data[i][j].first != -1; j++) {
          if (guess[data[i][j].first - 1] != data[i][j].second)
            break;
        }
        if (data[i][j].first != -1)
          break;
      }
    }
    if (i == n) {
      ans = max(ans, cnt);
    }
    return;
  }
  guess[now] = 1;
  cnt += 1;
  dfs(now + 1, n);
  cnt -= 1;
  guess[now] = 0;
  dfs(now + 1, n);
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    for (int j = 0; j < a; j++) {
      int x, y;
      scanf("%d%d", &x, &y);
      data[i][j] = {x, y};
    }
    data[i][a].first = -1;
  }
  dfs(0, n);
  printf("%d\n", ans);
}


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

int main()
{
   int  n;
   cin >> n;
   ll answer = 0;
   for(int i = 1; i < n+1; i++){
       if (i % 3 != 0 && i % 5 != 0 )
       {
           answer += i;
       }
   }
  cout << answer << endl;
} 

Measured memory_bytes: 3616
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def egcd(a: int, b: int):
    """
    A solution of ax+by=gcd(a,b). Returns
    (gcd(a,b), (x, y)).
    """
    if a == 0:
        return b, 0, 1
    else:
        g, x, y = egcd(b % a, a)
        return g, y - (b // a) * x, x


def modinv(a: int, mod: int = 10**9 + 7):
    """
    Returns a^{-1} modulo m.
    """
    g, x, y = egcd(a, mod)
    if g > 1:
        raise Exception('{}^(-1) mod {} does not exist.'.format(a, mod))
    else:
        return x % mod


import numpy as np


def main():
    N, S = geta(int)
    A = list(geta(int))
    A.sort()
    mod = 998244353

    inv2 = modinv(2, mod)

    dp = np.zeros((N + 1, S + 1), dtype=np.int64)

    _t = pow(2, N, mod)
    dp[:, 0] = _t
    for i in range(1, N + 1):
        dp[i, :] = dp[i - 1, :]
        if A[i - 1] <= S:
            tmp = np.roll(dp[i - 1, :], A[i - 1])
            tmp[:A[i - 1]] = 0
            dp[i, :] += tmp * inv2
            dp[i, :] %= mod

    print(dp[N][S])


if __name__ == "__main__":
    main()

Measured memory_bytes: 97528
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]
    
    def sp(self, goal):
        path = []
        node = goal
        for _ in range(2):
            path.append(node)
            node = self.prev[node]
        return path[1]

n, m = map(int, input().split())
g = Graph()
for i in range(m):
    a, b = map(int, input().split())
    g.add_edge(a-1, b-1, 1)
    g.add_edge(b-1, a-1, 1)

d = Dijkstra(g, 0)
A = []
# print(d.sp(2))
for i in range(n):
    a = d.shortest_distance(i)
    if a == float('inf'):
        print("No")
        break
    else:
        A.append(d.shortest_distance(i))

if len(A) == n:
    print("Yes")
    for i in range(1, n):
        print(d.sp(i) + 1)

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

int main(){
    int a,b,c,d;
    int e,f,g,h;
    cin>>a>>b>>c>>d;
    e=c-(d-b);
    f=d+(c-a);
    g=e-(c-a);
    h=f-(d-b);
    cout<<e<<" "<<f<<" "<<g<<" "<<h<<endl;
    return 0;
}

Measured memory_bytes: 256
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;

vi adj[N], dp(N);
bool vis[N];

void dfs(int node)
{
    vis[node] = 1;

    for(auto i : adj[node]) {
        if(!vis[i]) {
            dfs(i);
            dp[node] = max(dp[node], 1 + dp[i]);
        } else {
            dp[node] = max(dp[node], 1 + dp[i]);
        }
    }
}

void solve()
{
    int n, m;
    scn(n); scn(m);

    rep(i, 0, m) {
        int u, v;
        scn(u); scn(v);
        adj[u].pb(v);
    }

    int mx = 0;

    rep(i, 1, n+1) {
        if(!vis[i])
            dfs(i);
        mx = max(mx, dp[i]);
    }

    prin(mx);
}

int main()
{
    int t = 1;
    // scn(t);
    
    while(t --) {
        solve();
    }
    return 0;
}

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

int main() {
    string s; cin >> s;
    vector<int> cnt(2, 0);
    for (char &c : s) cnt[c - '0']++;
    cout << min(cnt[0], cnt[1]) * 2 << endl;
    return 0;
}

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

int main(void){
   string s;
   cin >> s;
   vector<int> a(26);
   
   for(int i = 0;i < s.size();i++){
       a[s[i] - 'a']++;
   }
   for(int i = 0;i < 26;i++){
       if(a[i] % 2 == 1){
           cout << "No" << endl;
           return 0;
       }
   }
   
   cout << "Yes" << endl;
   
   
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 2e5;
struct Prime{
  vector<ll> pl;
  void init(int a){ // a以下の素数列挙
    pl.resize(0);
    vector<bool> z(a+1, true);
    FOR(i, 2, a+1){
      if(z[i])pl.push_back(i);
      for(int b=i*2; b <= a; b+=i) z[b]=false;
    }
  }
  void prime_division(ll a, vector<pair<ll, int> >&v){ // vに素因数分解の結果が入る
    v.resize(0);
    for(ll b: pl){
      if(b*b > a) break;
      if(a%b) continue;
      int c = 0;
      while(a%b==0) a/=b, c++;
      v.push_back(make_pair(b, c));
    }
    if(a>1) v.push_back(make_pair(a, 1));
  }
} prime;

ll fac[N];
int n, m;
vector<pair<ll, int> > v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  fac[0] = 1;
  FOR(i, 1, N) fac[i] = fac[i-1] * i % mod;
  cin >> n >> m;
  prime.init(N);
  prime.prime_division(m, v);
  ll ans = 1;
  each(itr, v) ans = ans * fac[n-1+itr->se] % mod * modpow(fac[n-1], mod-2, mod) % mod * modpow(fac[itr->se], mod-2, mod) % mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100100],L,s[100100],n;
int anses[100100],tp;
int main(){
	scanf("%lld%lld",&n,&L);
	for(int i=1;i<=n;++i)
		scanf("%lld",&a[i]),s[i]=s[i-1]+a[i];
	int l=1,r=n;
	for(int i=1;i<=n-1;++i){
		if(s[r]-s[l-1]<L){
			puts("Impossible");
			return 0;
		}
		if(a[l]+a[l+1]>a[r]+a[r-1])anses[++tp]=r-1,r--;
		else anses[++tp]=l,l++;
	}
	printf("Possible\n");
	for(int i=1;i<=tp;++i)printf("%d\n",anses[i]);
}

Measured memory_bytes: 2816
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  vector<int> a;
  
  for (int i=0; i<n; ++i)
  {
    int v;
    cin >> v;
    a.push_back(v);
  }
  
  int cnt = 0;
  while (true)
  {
    for (auto &v : a)
    {
      if (v & 1) goto end;
      
      v /= 2;
    }
    ++cnt;
  }
  
end:
  cout << cnt << endl;
 
  return 0;
}

Measured memory_bytes: 256
from heapq import heappop, heappush

manhattan = [[abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)] for i in range(16)]
movables = [{1, 4}, {0, 2, 5}, {1, 3, 6}, {2, 7}, {0, 5, 8}, {1, 4, 6, 9}, {2, 5, 7, 10}, {3, 6, 11},
            {4, 9, 12}, {5, 8, 10, 13}, {6, 9, 11, 14}, {7, 10, 15}, {8, 13}, {9, 12, 14}, {10, 13, 15}, {11, 14}]
swap_mul = [[(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)]
destination = 0xfedcba9876543210

i = 0
board_init = 0
blank_init = 0
for _ in range(4):
    for n in map(int, input().split()):
        if n:
            n -= 1
        else:
            n = 15
            blank_init = i
        board_init += n * 16 ** i
        i += 1

estimation_init = sum(manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init)

queue = [(estimation_init, board_init, blank_init)]
visited = set()

while True:
    estimation, board, blank = heappop(queue)
    if board in visited: continue
    elif board == destination:
        print(estimation)
        break
    visited.add(board)
    for new_blank in movables[blank]:
        num = (board >> (4 * new_blank)) & 15
        new_board = board + swap_mul[new_blank][blank] * (15 - num)
        if new_board in visited: continue
        new_estimation = estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
        if new_estimation > 45: continue
        heappush(queue, (new_estimation, new_board, new_blank))




Measured memory_bytes: 161660
from collections import deque

s = deque(input())

q = int(input())

check = 1
for _ in range(q):
    t = list(input().split())
    if t[0] == '1':
        check = 1 - check
    else:
        if t[1] == '1':
            if check == 1:
                s.appendleft(t[2])
            else:
                s.append(t[2])
        else:
            if check == 1:
                s.append(t[2])
            else:
                s.appendleft(t[2])



if check == 1:
    print(''.join(s))
else:
    s = list(reversed(s))
    print(''.join(s))


Measured memory_bytes: 8436
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int a,b,n;
int check(int mid){
	return (a*mid)/b - (a*(mid/b));
}

int32_t main(){
	fastio();
	
	cin>>a>>b>>n;
	int ans = 0;
	int l = 0, r = n;
	while(r-l>2){
		int m1 = l+(r-l)/3;
		int m2 = r - (r-l)/3;
		if(check(m1)<=check(m2)){
			l = m1;
		}else r = m2;
	}
	for(int i=l;i<=r;i++){
		ans = max(ans,check(i));
	}
	cout<<ans;
}

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

int main(){
  int N;
  cin >> N;
  string A;
  int count = 0;
  for(int i = 0; i < N; i++){
    cin >> A;
    if(A == "Y"){
      count++;
      cout << "Four" << endl;
      break;
    }
  }
  if(count == 0){
    cout << "Three" << endl;
  }
}


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

int gcd( int x, int y ){
    if (y == 0)
        return x;
    return gcd(y, x%y);
}

int main()
{

    int N;
    cin >> N;
    vector<int> A(N, 0);
    vector<int> l(N, 0), r(N, 0);
    for (auto &&a : A)
    {
        cin >> a;
    }

    for (int i = 0; i < N - 1; ++i){
        l[i + 1] = gcd(l[i], A[i]);
    }
    for (int i = N-1; i >=1; --i)
    {
        r[i -1] = gcd(r[i], A[i]);
    }

    int ans = 1;

    for (int i = 0; i < N; ++i){
        ans = max(ans, gcd(l[i], r[i]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
#define brk system("pause");

const int N = 1e5 + 1;
long long dp[N][101], a[101], c[101];

main()
{
	int n; cin >> n;
	int w; cin >> w;
	
	for(int i = 1; i <= n; i++)
		cin >> a[i] >> c[i];
	
	for(int i = 1; i <= w; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			dp[i][j] = dp[i][j - 1]; if(i >= a[j])
				dp[i][j] = max(dp[i][j], dp[i - a[j]][j - 1] + c[j]);
		}
	}
	
	cout << dp[w][n];
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 200005
//<<fixed << setprecision(9)
vi G[space];
int dist[2][space];

int mx;
void dfs(int n,int p,int c,int tim)
{
    tim++;
    for(auto z:G[n])
    {
        if(z!=p)
        {
            dist[c][z]=tim;
            dfs(z,n,c,tim);
        }
    }
    if(c==0)return;
    if(dist[1][n]<dist[0][n])
    {
        mx=max(dist[1][n] + (dist[0][n]-dist[1][n]) -1 ,mx);
    }
}
int main()
{
    int i,j,n,t;
    boost;
    
    int a;
    cin>>n>>t>>a;
    rep(i,0,n-1)
    {
        int u,v;
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }
    dfs(a,-1,0,0);
    dfs(t,-1,1,0);
   // rep(i,1,n+1)cout<<dist[0][i]<<' '<<dist[1][i]<<"\n";
    cout<<mx;
    return 0;
}



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


a = []

for i in range(N):
    a.append(int(input()))
# a=[0]*N
# for i in range(N):
#   a[i]=int(input())
count=0

#loopの定義→同じインデックスを使用したらloop判定
#in の処理を爆速で実行するためにsetを使用する
#loop=[]
loop=set()

tmp=1
while True:  
  tmp=a[tmp-1]
  count+=1
  if tmp==2:
    print(count)
    exit()
  if tmp-1 in loop:
    print(-1)
    exit()
  #loop.append(tmp-1)
  loop.add(tmp-1)

Measured memory_bytes: 15992
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*--------------------------------------------------------------------*/


signed main(){
  int h,w;
  cin>>h>>w;
  int m[h][w];
  int cnt=0;//black
  rep(i,h){
    string s;
    cin>>s;
    rep(j,w){
      m[i][j]=(s[j]=='.'?0:1);
      cnt+=(s[j]=='#');
    }
  }
  // black:1, white:0

  // rep(i,h){
  //   rep(j,w) cout<<m[i][j];
  //   cout<<endl;
  // }

  queue<pii> q;
  vector<vi> d(h,vi(w,INF));
  d[0][0]=0;
  
  q.push(make_pair(0,0));
  while(!q.empty()){
    pii p=q.front();
    q.pop();
    int x=p.first,y=p.second;
    rep(i,4){
      int nx=x+dx[i];
      int ny=y+dy[i];
      if(nx<0||nx>=h||ny<0||ny>=w||m[nx][ny]==1||d[nx][ny]<INF){
        continue;
      }
      d[nx][ny]=d[x][y]+1;
      q.push(make_pair(nx,ny));
    }
  }
  int ans=h*w-d[h-1][w-1]-1-cnt;

  if(d[h-1][w-1]==INF) ans=-1;

  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 (b<a) { a=b; return 1; } return 0; }



int n;
void solve(){
	cin >> n;
	
	int ans = 0;
	ans += 1000*(n/500);
	n %= 500;
	ans += 5*(n/5);
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String reg1 = "RRR";
		String reg2 = "RR";
		String reg3 = "R";
		Pattern p1 = Pattern.compile(reg1);
		Pattern p2 = Pattern.compile(reg2);
		Pattern p3 = Pattern.compile(reg3);
		Matcher m1 = p1.matcher(s);	
		Matcher m2 = p2.matcher(s);	
		Matcher m3 = p3.matcher(s);	

		if(m1.find()) {
			System.out.println("3");
		}else if(m2.find()) {
			System.out.println("2");
		}else if(m3.find()) {
			System.out.println("1");
		}else {
			System.out.println("0");
		}
	}

}

Measured memory_bytes: 35672