akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long Int;

Int n;
Int a[108000], b[108000];

int main(){
  cin >> n;
  for(Int i = 0;i < n;i++){
    cin >> a[i] >> b[i];
  }
  Int res = 0;
  Int need = 0;
  for(Int i = n-1;i >= 0;i--){
    a[i] += need;
    if(a[i] % b[i]){
      Int tmp = (a[i] / b[i] + 1) * b[i];
      need += tmp - a[i];
    }
  }
  cout << need << endl;
  return 0;
}


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

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

    int k, x;
    cin >> k >> x;

    for(int i = x - k + 1; i <= x + k - 1; i++){
        cout << i << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;
	using BigNum = std::vector<double>;

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(double);
		void decrement(void);
		void decrement(double);
		double getResult(void);
	private:
		double result;
	};
	void Ans::showResult(void) {
		printf("%.0lf\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(double value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(double value) {
		this->result -= value;
	}
	double AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void input(Str* str) {
		str->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				str->push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		str->push_back(row);
	}
	void input(Num* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atoi(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atoi(row.c_str()));
	}
	void input(BigNum* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atof(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atof(row.c_str()));
	}
	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::Num s;
	AtCoder::input(&s);

	const int k = s[0], x = s[1];

	if (x <= (k * 500)) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 888
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
	private	static	Scanner				stdin = null;
	private	static	ArrayList<Integer>	list  = null;

	static {
		list  = new ArrayList<Integer>();
		stdin = new Scanner(System.in);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int		nLine  = stdin.nextInt();
		int		nCross = stdin.nextInt();
		int[]	aCross = null;
		int[]	aIndex = new int[2];

		for(int i = 1; i <= nLine; i++) {
			list.add(i);
		}

		for(int nLoop = 1; nLoop <= nCross; nLoop++) {
			aCross    = parseCross();
			aIndex[0] = list.indexOf(aCross[0]);
			aIndex[1] = list.indexOf(aCross[1]);
			list.set(aIndex[1], aCross[0]);
			list.set(aIndex[0], aCross[1]);
		}

		for(int i = 1; i <= nLine; i++) {
			System.out.println(list.indexOf(i) + 1);
		}
	}

	private static int[] parseCross() {
		int[]		aCross = new int[2];
		String[]	aNum   = stdin.next().split(",");

		aCross[0] = Integer.parseInt(aNum[0]);
		aCross[1] = Integer.parseInt(aNum[1]);

		return aCross;
	}
}

Measured memory_bytes: 17204
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<string> vs;
#define ifr(i,n) for((i)=0;(i)<(n);i++)
#define dfr(i,n) for((i)=(n);(i)>=0;i--)
/*
char upper(char C){
  if('a'<=C && C<='z')
    C = C-32;
  return C;
}
*/
char upper(char C){
   if(C >= 'a' && C <= 'z')
	C = C + 'A' - 'a';
   return C;
}
int main(){
  string str;
  string str2;
  int num=0;
  cin>>str2;
  for(int i=0;i<str2.size();i++)
    str2[i]=upper(str2[i]);
  while(cin>>str,str!="END_OF_TEXT"){
  for(int j=0;j<str.size();j++)
    str[j]=upper(str[j]);
  if(str[str.size()-1]=='.')
    str=str.substr(0,str.size()-1);
  if(str == str2)
    num++;
  }
  cout << num<<endl;
  return 0;
}

Measured memory_bytes: 3152
#include<stdio.h>
int main(){
  int a,b,c,i;
  scanf("%d%d%d",&a,&b,&c);
  for(i=1;i<=b;i++){
    if((a*i)%b==c){
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
  {
    int n,i,k,l;
  cin>>n;
  k=n/100;
  l=n%100;
  if(0<l && l<13 && 0<k && k<13)
    cout<<"AMBIGUOUS";
  else if(0<l && l<13)
    cout<<"YYMM";
  else if( 0<k && k<=12)
    cout<<"MMYY";
  else
    cout<<"NA";
}

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


int N,M,A,B,C,TT;

typedef vector<int> Arr;
typedef vector<Arr> Mat;


Mat mul(const Mat &a,const Mat &b){
	int n = a.size();
	Mat c(n,Arr(n,0));
	for(int i = 0 ; i < n ; i++)
		for(int j = 0 ; j < n ; j++)	
			for(int k = 0 ; k < n ; k++)
				c[i][j] = (c[i][j]+(a[i][k] * b[k][j])) % M;
	return c;
}
Mat E(int n){
	Mat c(n,Arr(n,0));
	for(int i = 0 ; i < n ; i++) c[i][i] = 1;
	return c;
}
Mat pow(Mat a,int k){
	Mat res = E(a.size());
	if( k == 0 ) return res;
	if(k&1) res = mul(res,a);
	res = mul(res,pow(mul(a,a),k/2));
	return res;
}

int main(){
	while(cin >> N >> M >> A >> B >> C >> TT && N){
		int S[50] = {};
		for(int i = 0 ; i < N ; i++) cin >> S[i];
		Mat mat(N,Arr(N,0));
		for(int i = 1 ; i < N ; i++) mat[i][i-1] = A;
		for(int i = 0 ; i < N ; i++) mat[i][i] = B;
		for(int i = 0 ; i+1 < N ; i++) mat[i][i+1] = C;

		Mat cal = pow(mat,TT);
		
		for(int i = 0 ; i < N ; i++){
			int ans = 0;
			for(int j = 0 ; j < N ; j++){
				ans += cal[i][j] * S[j];
			}
			ans %= M;
			cout << ans << (i+1==N?"\n":" ");
		}
	}
}

Measured memory_bytes: 1936
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int counter = 0;
  if(s[0] == '1') ++counter;
  if(s[1] == '1') ++counter;
  if(s[2] == '1') ++counter;
  cout << counter << endl;
}


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
int main(){
	int N,M;
	cin >> N >> M;
	static bool visited[300005] = {};
	static ll cost[300005] = {};
	vector<vector<int>> E(300005);

	REP(i,M){
		int u,v;
		cin >> u >> v;
		u *= 3;
		v *= 3;
		E[u].PB(v+1);
		E[u+1].PB(v+2);
		E[u+2].PB(v);
	}

	queue<int> Q;
	int S,T;
	cin >> S >> T;
	S *= 3; T *= 3;
	Q.push(S);
	visited[S] = true;

	while(!Q.empty()){
		int now = Q.front();
		visited[now] = true;
		Q.pop();

		for (int i = 0; i < E[now].size(); ++i) {
			int next = E[now][i];
			if (visited[next]) continue;
			visited[next] = true;
			cost[next] = cost[now] + 1;
			Q.push(next);
		}
	}

	if (visited[T]) cout << cost[T] / 3 << endl;
	else cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 19328
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}





int main(){
    string s;
    getline(cin , s);

    rep(i,s.length()){
        if(s[i] >= 'a' && s[i] <= 'z') s[i] -= 'a'-'A';
        else if(s[i] >= 'A' && s[i] <='Z') s[i] += 'a'-'A';
    }

    cout << s << endl;


}



Measured memory_bytes: 3168
object Main {
  def main(args: Array[String]): Unit = {
    val Array(n, m, l, _*) = io.StdIn.readLine().split(" ").map(_.toInt)
    val a = Array.ofDim[Int](n, m)
    val b = Array.ofDim[Int](m, l)

    for (row <- 0 until n) {
      io.StdIn.readLine().split(" ").map(_.toInt)
        .zipWithIndex
        .foreach { case (v, col) => a(row)(col) = v }
    }
    for (row <- 0 until m) {
      io.StdIn.readLine().split(" ").map(_.toInt)
        .zipWithIndex
        .foreach { case (v, col) => b(row)(col) = v }
    }

    val c = Array.ofDim[Long](n, l)
    for {
      i <- 0 until n
      j <- 0 until l
    } {
      c(i)(j) = (0 until m).foldLeft(0L) { case (acc, k) =>
        acc + a(i)(k) * b(k)(j)
      }
    }

    c.map(_.mkString(" ")).foreach(println)
  }
}

Measured memory_bytes: 86928
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w, h;
		int x, y;
		while(true){
			x = 0;
			y = 0;
			w = sc.nextInt();
			h = sc.nextInt();
			if(w == 0 && h == 0)
				break;
			Game game = new Game(w, h);
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					game.map[i][j] = sc.nextInt();
					if(game.map[i][j] == 2){
						x = i;
						y = j;
					}
				}
			}
			game.search(x, y, 0);
			System.out.println(game.answer <= 10 ? game.answer : -1);
		}
	}
}
class Game{
	int answer = 11;
	int w, h;
	int[][] map;
	int[][] v = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
	Game(int iw, int ih){
		w = iw;
		h = ih;
		map = new int[h][w];
	}
	boolean isInRange(int x, int y){
		return (x >= 0 && x < h && y >= 0 && y < w);
	}
	void search(int x, int y, int k){
		if(k >= answer)
			return;
		int p, q;
		for(int i = 0; i < v.length; i++){
			p = x + v[i][0];
			q = y + v[i][1];
			if(!isInRange(p, q) || map[p][q] == 1)
				continue;
			while(isInRange(p, q)){
				if(map[p][q] == 1){
					map[p][q] = 0;
					search(p-v[i][0], q-v[i][1], k+1);
					map[p][q] = 1;
					break;
				}
				if(map[p][q] == 3){
					if(k+1 < answer)
						answer = k + 1;
					break;
				}
				p += v[i][0];
				q += v[i][1];
			}
		}
		return;
	}
}

Measured memory_bytes: 36948
#include <bits/stdc++.h>
using namespace std;
struct pnt{
  pnt * alp[26];
  bool exist[26];
  int sz, dist;
  bool is_end;
  pnt(){
    sz=0;
    is_end=0;
    dist=1;
    for(int i=0; i<26; ++i){
      exist[i]=0;
    }
  }
} * root;
string a[100010];
void ins(int x){
  pnt * p = root;
  ++(p->sz);
  int chr;
  for(int i=0; i<a[x].size(); ++i){
    chr=a[x][i]-'a';
    if(!(p->exist[chr])){
      p->alp[chr]=new pnt();
      p->exist[chr]=1;
    }
    p=p->alp[chr];
    ++(p->sz);
  }
  p->is_end=1;
}
int ans, k;
string alphabet;
void qry(){
  pnt * p =root;
  ans=0;
  int ch;
  for(int i=0; i<a[k].size(); ++i){
    if(p->is_end)
      ++ans;
    for(int j=0; j<26; ++j){
      ch=alphabet[j]-'a';
      if(alphabet[j]==a[k][i]){
        i+=(p->dist)-1;
        p=p->alp[ch];
        break;
      }
      if((p->exist[ch]))
        ans+=(p->alp[ch])->sz;
    }
  }
}
int simplify1(pnt * p){
  for(int i=0; i<26; ++i){
    if((p->exist[i])){
      if(p->sz==p->alp[i]->sz){
        p->dist = 1+simplify1(p->alp[i]);
        return p->dist;
      }
      else{
        simplify1(p->alp[i]);
      }
    }
  }
  return 0;
}
pnt* simplify2(pnt * p){
  for(int i=0; i<26; ++i){
    if((p->exist[i])){
      if(p->sz==p->alp[i]->sz){
        p->alp[i] = simplify2(p->alp[i]);
        return p->alp[i];
      }
      else{
        simplify2(p->alp[i]);
      }
    }
  }
  return p;
}
int main(){
  int n, q;
  root = new pnt();
  cin>>n;
  for(int i=1; i<=n; ++i){
    cin>>a[i];
    ins(i);
  }
  simplify1(root);
  simplify2(root);
  cin>>q;
  for(int i=0; i<q; ++i){
    cin>>k>>alphabet;
    qry();
    cout<<ans+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 114052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll X = min({A, B, C, D, E});
    cout << (X + N - 1) / X + 4;
    return 0;
}

Measured memory_bytes: 256
a, b, k = map(int, input().split())

# print(a)
# print(b)
# print(k)

if (a + b) <= k:
    a = 0
    b = 0
elif a <= k:
    b = b - (k - a)
    a = 0
else:
    a = a - k
    b = b
    
print("{} {}".format(a, b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
int a[maxn],b[maxn],w[maxn],id[maxn],pos[maxn];
ll sum[maxn],dp[maxn];
int fa[maxn];
int Begin[maxn],Next[maxn<<1],to[maxn<<1],e;
inline void add_edge(int x,int y){
	to[++e]=y;
	Next[e]=Begin[x];
	Begin[x]=e;
}
inline bool cmp(const int A,const int B){
	return w[A]<w[B];
}
int find(int x){
	if(fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
int main(){
	int n=read(),m=read();
	REP(i,1,n){
		a[i]=read(),b[i]=read();
		w[i]=max(a[i]-b[i],0);
		id[i]=i;
	}
	sort(id+1,id+n+1,cmp);
	REP(i,1,n) pos[id[i]]=i;
	while(m--){
		int x=read(),y=read();
		if(pos[x]<pos[y]) add_edge(y,x);
		else add_edge(x,y);
	}
	REP(i,1,n){
		int u=id[i];
		dp[u]=w[u],fa[u]=u,sum[u]=b[u];
		for(int j=Begin[u];j;j=Next[j]){
			int v=to[j];
			if(u==find(v)) continue;
			v=find(v);
			chkmin(dp[u],max(dp[v],w[u]-sum[v]));
			fa[v]=u;
			sum[u]+=sum[v];
		}
	}
	printf("%lld\n",dp[id[n]]+sum[id[n]]);
	return 0;
}


Measured memory_bytes: 5376
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

// Javaなら通るかなと思って
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int Ch = sc.nextInt() - 1;
        int Cw = sc.nextInt() - 1;
        int Dh = sc.nextInt() - 1;
        int Dw = sc.nextInt() - 1;
        char[][] maze = new char[H][W];
        for(int i = 0; i < H; i++){
            String s = sc.next();
            for(int j = 0; j < W; j++)
                maze[i][j] = s.charAt(j);
        }
        sc.close();

        int[][] dist = new int[H][W];
        for(int i = 0; i < H; i++)
            Arrays.fill(dist[i], Integer.MAX_VALUE / 2);
        dist[Ch][Cw] = 0;

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

        Deque<Integer> deque = new ArrayDeque<>(100000);
        deque.addLast(Ch);
        deque.addLast(Cw);
        int d = dist[Ch][Cw];
        while(deque.isEmpty() == false){
            int pi = deque.poll();
            int pj = deque.poll();
            d = dist[pi][pj];
            for(int i = 0; i < 4; i++){
                int ni = pi + dx[i];
                int nj = pj + dy[i];
                if(ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
                if(maze[ni][nj] == '#') continue;
                if(dist[ni][nj] <= d) continue;
                dist[ni][nj] = d;
                deque.addFirst(nj);
                deque.addFirst(ni);
            }
            for(int i = -2; i <= 2; i++){
                for(int j = -2; j <= 2; j++){
                    int ni = pi + i;
                    int nj = pj + j;
                    if(ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
                    if(maze[ni][nj] == '#') continue;
                    if(dist[ni][nj] <= d + 1) continue;
                    dist[ni][nj] = d + 1;
                    deque.addLast(ni);
                    deque.addLast(nj);
                }
            }
        }

        int ans = dist[Dh][Dw];
        if(ans == Integer.MAX_VALUE / 2) ans = -1;
        System.out.println(ans);
    }
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int M = 2019;

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

  string s;
  cin >> s;
  vector<int64> acc(M);
  vector<int64> cur(M);
  vector<int64> next(M);

  for (int i = 0; i < s.length(); i++) {
    int d = s[i] - '0';
    for (int k = 0; k < M; k++) {
      next[(k * 10 + d) % M] += cur[k];
    }
    next[d] += 1;
    swap(next, cur);
    for (int k = 0; k < M; k++) {
      next[k] = 0;
    }
    for (int k = 0; k < M; k++) {
      acc[k] += cur[k];
    }
  }
  cout << acc[0] << endl;
}

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

int a, b;
int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
 // freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=210;
const int inf=2147483647;
const int mod=998244353;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int Pow(int x,int y)
{
	if(!y)return 1;
	int t=Pow(x,y>>1),re=(LL)t*t%mod;
	if(y&1)re=(LL)re*x%mod;
	return re;
}
int n;bool mark[Maxn];
struct Point{int x,y;}p[Maxn];
bool cmp(Point a,Point b)
{
	if(a.x!=b.x)return a.x<b.x;
	return a.y<b.y;
}
int multi(Point p0,Point p1,Point p2)
{
	int X1=p1.x-p0.x,X2=p2.x-p0.x;
	int Y1=p1.y-p0.y,Y2=p2.y-p0.y;
	return X1*Y2-X2*Y1;
}
int main()
{
	n=read();
	int ans=(Pow(2,n)-1+mod)%mod;
	for(int i=1;i<=n;i++)p[i].x=read(),p[i].y=read();
	sort(p+1,p+1+n,cmp);
//	for(int i=1;i<=n;i++)printf(" %d %d\n",p[i].x,p[i].y);
	for(int i=1;i<=n;i++)
	{
//		bool flag=false;
		memset(mark,false,sizeof(mark));
		for(int j=i+1;j<=n;j++)
		{
			if(mark[j])continue;
			int cnt=1;
			for(int k=j+1;k<=n;k++)
			if(multi(p[i],p[j],p[k])==0)cnt++,mark[k]=true;
//			printf("%d %d %d\n",i,j,(Pow(2,cnt)-1+mod)%mod);
			ans=(ans-(Pow(2,cnt)-1+mod)%mod+mod)%mod;
//			if(flag)break;
		}
	}
	
	printf("%d",(ans-n+mod)%mod);
}

Measured memory_bytes: 256
import sys
def main():
    s = sys.stdin.readlines()
    N, M, Q = map(int, s[0].split())
    x = [[0] * N for _ in [0] * N]
    for e in s[1:M + 1]:
        L, R = map(int, e.split())
        x[L - 1][R - 1] += 1
    for k in range(1, N):
        for i in range(N - k):
            j = i + k
            x[i][j] += x[i][j - 1] + x[i + 1][j] - x[i + 1][j - 1]
    res = []
    for e in s[M + 1:]:
        p, q = map(int, e.split())
        res.append(x[p - 1][q - 1])
    print('\n'.join(map(str, res)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 37168
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main(){
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    for(auto& e : A) cin >> e;
    for(auto& e : B) cin >> e;
    for(auto& e : C) cin >> e;

    priority_queue<ll, vector<ll>, greater<ll> > q, r;
    for(auto a : A) {
        for(auto b : B) {
            q.push(a+b);
            if(q.size() > K) q.pop();
        }
    }

    while(q.size()) {
        auto e = q.top(); q.pop();
        for(auto c : C) {
            r.push(e+c);
            if(r.size() > K) r.pop();
        }
    }

    vector<ll> v;
    while(r.size()) {
        auto e = r.top(); r.pop();
        v.push_back(e);
    }

    for(auto iter = v.rbegin(); iter != v.rend(); iter++) {
        cout << *iter << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI 3.1415926535897932384626433832795028841971693993
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    int n,ans=0;
    string s;
    cin>>n>>s;
    ll a=0,b=0,c=0;
    rep(i,n){
        if(s[i]=='R') a++;
        else if(s[i]=='G') b++;
        else c++;
    }
    ll sum=a*b*c;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            int k=2*j-i;
            if(n<=k) continue;
            if(i>=j||j>=k||i>=k) continue;
            if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i]) sum--;
        }
    }
    cout<<sum<<endl;
}

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

ll mod = 1000000007;
ll ans = 1<<29;

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

    int mae =211111,usi=0;;
    rep(i,s.size()){
        if(s[i]=='A'){
            mae = min(mae,i);
        }
        if(s[i]=='Z'){
            usi = max(usi,i);
        }
    }
    cout << usi- mae +1 << endl;
    

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using ll = unsigned long long;


bool f(ll a, ll b, ll c)
{
	if (a + b >= c)
	{
		return false;
	}
	else
	{
		ll r = c - a - b;
		return 4 * a * b < r * r;
	}
}


int main()
{
	ll a, b, c;
	std::cin >> a >> b >> c;

	std::cout << (f(a, b, c) ? "Yes" : "No");
}



Measured memory_bytes: 256
import java.util.*;

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

	int m = sc.nextInt();//f[^ZbgÌ

	while(m!=0){

	    int money = sc.nextInt();//^pà
	    int year = sc.nextInt();//N
	    int type = sc.nextInt();//^pû@ÌíÞ

	    int finalAns = 0;//ÅåÌÅIà

	    while(type!=0){
		int tanri = sc.nextInt();//Por¡
		double rate = sc.nextDouble();//N¦
		int tesu = sc.nextInt();//NÌè¿
		int ans = solve(money,year,tanri,rate,tesu);//^pû@²ÆÌÅIà
		if(ans>finalAns) finalAns = ans;
		type--;
	    }
	    System.out.println(finalAns);
	    m--;
	}
    }

    public static int solve(int money, int year, int tanri, double rate, int tesu){
	int zandaka = 0;//c
	int ratesum = 0;//qÝv
	if(tanri==1){//¡Ìê
	    while(year!=0){
		zandaka = money + (int)(money*rate) - tesu;
		money = zandaka;
		year--;
	    }
	}else if(tanri==0){//PÌê
	    while(year!=0){
		zandaka = money - tesu;
		ratesum += (int)(money*rate);
		money = zandaka;
		year--;	    
	    }
	}
	
	return zandaka + ratesum;
    }
}

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

int main(){
  string s;
  int k,i=0;
  cin >> s >> k;
  k--;
  while(i<s.size()&&s.at(i)=='1')
    i++;
  //cout << i << '/';
  if(i>k)
    cout << 1 << endl;
  else
    cout << s.at(i) << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define MOD 1000000007
 
int n, k;
vector<int> graph[100010];
int a[100010];
 
void dfs(int idx, int oya){
    int cnt = (idx == oya ? 1 : 2);
 
    for(int i = 0;i < graph[idx].size();i++){
        int ko = graph[idx][i];
        if(ko != oya){
            a[ko] = max(0ll, k-cnt);
            cnt++;
            dfs(ko, idx);
        }
    }
}
 
signed main(){
    cin >> n >> k;
 
    int ax, b;
    for(int i = 0;i < n-1;i++){
        cin >> ax >> b;
        ax--;
        b--;
        graph[ax].push_back(b);
        graph[b].push_back(ax);
    }
 
    dfs(0, 0);
 
 
    int ans = k;
    for(int i = 1;i < n;i++){
        ans = (ans * a[i]) % MOD;
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 11136
ls = [int(input()) for i in range(5)]
ans = []
num = 0
minNum = 10
flag = True
    
for j in ls:
    x = j % 10
    if x < minNum and x > 0:
        num = j
        minNum = x
    elif minNum == 10 and j == ls[-1]:
        flag = False
if flag:
    ans.append(num)
    ls.pop(ls.index(num))

for i in ls:
    y = ((i + 9) // 10) * 10
    ans.append(y)

print(sum(ans))

Measured memory_bytes: 3064
import qualified Data.Map as M

main = do
  [n,k] <- map read.words <$> getLine :: IO [Int]
  as    <- map read.words <$> getLine :: IO [Int]
  let ds = M.fromList $ zip [1..] $ map ((k+1)-) as
  putStr $ solve n k ds [] 0

solve :: Int -> Int -> M.Map Int Int -> [Int] -> Int -> String
solve n k ds acc step
  | step == k && able = show (n+k*(n-1)) ++ "\n" ++ unwords ( map show (ans n k acc 0) )
  | step == k && not able = "-1"
  | otherwise = solve n k (M.insert mk (mv-1) ds) (mk:acc) (step+1)
  where
  able = all (<=0) ds
  (mk,mv) = M.foldlWithKey (\(mk,mv) k v -> if v > mv && k /= prev then (k,v) else (mk,mv) ) (0,-100) ds
  prev = if null acc then 0 else head acc
  ans n k (a:as) 0 = filter (/=a) [1..n] ++ a : ans n k (a:as) 1
  ans n k [a] _    = filter (/=a) [1..n]
  ans n k (a:b:as) step = filter (\i -> i/=a && i/=b) [1..n] ++ b : ans n k (b:as) (step+1)

-- 下記の操作で、財宝が見つからなかったとき、移動回数は1以上消費される。
-- 操作：財宝が存在する可能性のあるすべての箱を開ける。最後の箱は開けたままにする。
-- 操作をK+1回繰り返せば、必ず財宝が見つかる。(最初のK回で移動回数がすべて消費されるから。)
-- 1回目の操作で、財宝が存在する可能性がある箱はN個である。
-- 2回目以降の操作で、財宝が存在する可能性がある箱はN-1個(開いている箱を除く)である。
-- それぞれの箱が開けられる回数は、(K+1)-(最初のK回の操作のうち、最後に開けられた回数) である。
-- K回の操作で、どの箱を最後に開けるかを選べばよいが、下記の不足回数が最大の箱を選び、選ぶたびに1減らせばよい。
-- 不足回数：すべての操作で開けるには何回足りないか、すなわち最後に開けられる回数の必要最小限。(K+1-a_i)
-- ※ただし、連続して2度選ばれることはできない。(操作で開けない箱を最後に開けることはできないから。)
-- 最後に開ける箱をすべて選び終わった後、すべての箱の不足回数がゼロ以下であれば、勝てる。
-- 箱を開ける回数は、N + K(N-1) である。

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

int main() {string s;
cin >> s;
  int tmp = 0;
  string ans = "None";
for(char i = 'a'; i <= 'z'; i++){
  tmp = 0;
  for(int j = 0; j < s.size(); j++){
    if(s.at(j) == i){
    tmp = 1;
    break;
    } 
  }
  if(tmp == 0){
     ans = i;
     break;
  }
}


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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int mod=998244353;
const int maxn=1e5+7;

#define N 100010
#define lowbit(x) x&-x
int c[N*10];
int n,a[N],s[N*10];
void add(int x){
    for(int i=x;i<=2*N;i+=lowbit(i))c[i]++;
}
ll query(int x){
    ll sum=0;
    for(int i=x;i>0;i-=lowbit(i))sum+=c[i];
    return sum;
}
bool check(int x){
    for(int i=1;i<=2*N;i++)c[i]=0;
    s[0]=0;
    for(int i=1;i<=n;i++)
        s[i]=s[i-1]+(a[i]>=x?1:-1);
    ll sum=0;
    for(int i=0;i<=n;i++){
        sum+=query(s[i]+N);
        add(s[i]+N);
    }
    return sum>=1ll*n*(n+1)/4;
}
int main(){
    cin>>n;
    int l=0,r=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        r=max(r,a[i]);
    }
    int ans=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid))l=mid+1;
        else r=mid-1;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 5168
#include<bits/stdc++.h>
#define MAX 101
using namespace std;

int G[MAX][MAX]={};

void print(int n){
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(j!=n)cout<<G[i][j]<<" ";
      else cout<<G[i][j];
    }
    cout<<endl;
  }
}
  
int main(){
  int n,i,k,j,A,B;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>A>>k;
    for(j=0;j<k;j++){
      cin>>B;
      G[A][B]=1;
    }
  }
  print(n);
}

    
  



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1e9+7;
using P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す//計算量は0(log(max(a,b))
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す//計算量は0(log(max(a,b))
  return a*b/gcd(a,b);
}
ll mod_pow(ll x,ll y){//x^yを返す//計算量は0(log(y))
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す//計算量は0(sqrt(a))
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  int x;
  cin>>x;
  if(x<600){
    cout<<8<<endl;
  }
  else if(x<800){
    cout<<7<<endl;
  }
  else if(x<1000){
    cout<<6<<endl;
  }
  else if(x<1200){
    cout<<5<<endl; 
  }
  else if(x<1400){
    cout<<4<<endl;
  }
  else if(x<1600){
    cout<<3<<endl;
  }
  else if(x<1800){
    cout<<2<<endl;
  }
  else if(x<2000){
    cout<<1<<endl;
  }
}

Measured memory_bytes: 3632
def main():
	a, b, k = map(int, input().split())
	max_ab = max(a, b)
	cd = 0
	for i in range(max_ab, 0, -1):
		if a % i == 0 and b % i == 0:
			cd += 1
		if cd == k:
			print(i)
			break

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
package main

import (
	"fmt"
	"strconv"
)

type Point struct{ X, Y int }

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

	if n == 1 {
		fmt.Println(1)
		return
	}

	ps := make([]Point, n)
	for i := range ps {
		fmt.Scan(&ps[i].X, &ps[i].Y)
	}

	xm := make(map[string]int)
	for _, v1 := range ps {
		for _, v2 := range ps {
			dx := strconv.Itoa(v1.X - v2.X)
			dy := strconv.Itoa(v1.Y - v2.Y)
			xm[dx+"_"+dy]++
		}
	}
	xm["0_0"] = 1

	max := 0
	for _, v := range xm {
		if v > max {
			max = v
		}
	}
	fmt.Println(n - max)
}


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

int main() {
  int a,b;
  int c=0;
  int d=0;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b;
    c=max(c,b);
    d+=b;
  }
  c=c/2;
  cout<<d-c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

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

const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 100100;
const long double PI = acos(-1);

ll count_digits(ll n){
    int ans = 0;
    while (n) n/=10, ans++;
    return ans;
}

int main (){
    ll n, ini, ans = oo;

    cin >> n;
    ini = (ll)sqrt(n) + 2;
    for (int i=ini; i>=1; i--){
        if (n%i == 0){
            ans = min(ans, max(count_digits(n/i), count_digits(i)));
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORALL(i, n) for(int i = 0; i < n; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define ALL(a) a.begin, a.end()
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	int cnt[2005];
	memset(cnt, 0, sizeof(cnt));
	int mod = 1e9 + 7;

	cnt[0] = 1;
	cnt[1] = cnt[2] = 0;
	cnt[3] = 1;

	cin >> n;
	for(int i = 4; i <= n; i++) {
		for(int j = 3; j <= i; j++) {
			cnt[i] = (cnt[i] + cnt[i - j]) % mod;
		}
	}


	cout << cnt[n] << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <deque>
#include <set>

using namespace std;

vector<int> slide_min(const vector<int> &v, int k) {
    deque<int> deq;
    vector<int> ret;
    for (int i = 0; i < v.size(); i++) {
        while (!deq.empty() && v[deq.back()] >= v[i]) {
            deq.pop_back();
        }
        deq.push_back(i);
        if (i - k + 1 >= 0) {
            ret.emplace_back(v[deq.front()]);
            if (deq.front() == i - k + 1) deq.pop_front();
        }
    }
    return ret;
}

vector<int> slide_max(const vector<int> &v, int k) {
    deque<int> deq;
    vector<int> ret;
    for (int i = 0; i < v.size(); i++) {
        while (!deq.empty() && v[deq.back()] <= v[i]) {
            deq.pop_back();
        }
        deq.push_back(i);
        if (i - k + 1 >= 0) {
            ret.emplace_back(v[deq.front()]);
            if (deq.front() == i - k + 1) deq.pop_front();
        }
    }
    return ret;
}

struct UnionFind {
    vector<int> data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return (false);
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)cin >> p[i];

    UnionFind uf(n);
    vector<int> mi = slide_min(p, k - 1), ma = slide_max(p, k - 1);
    for (int i = 1; i < mi.size() - 1; i++) {
        if (p[i - 1] < mi[i] && ma[i] < p[i + k - 1])uf.unite(i - 1, i);
    }

    vector<int> nochange;
    vector<int> dp(n, 1);
    for (int i = 1; i < n; i++) {
        if (p[i] > p[i - 1])dp[i] = dp[i - 1] + 1;
        else dp[i] = 1;

        if (dp[i] >= k)nochange.push_back(i - k + 1);
    }
    for (auto x:nochange)uf.unite(nochange.front(), x);

    set<int> ret;
    for (int i = 0; i <= n - k; i++)ret.insert(uf.find(i));
    cout << ret.size() << endl;
    return 0;
}

Measured memory_bytes: 13560
#include <stdio.h>

int main(int argc, char const *argv[])
{
    char string[10];
    char target;
    int l;
    int target_num;
    scanf("%d", &l);
    scanf("%s",string);
    scanf("%d", &target_num);
    target=string[target_num-1];
    for(int i = 0; i < l; i++)
    {
        if(string[i]!=target)
            string[i]='*';
    }

    printf("%s\n",string);
    
    return 0;
}


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

using namespace std;

int main() {
	vector<int>dp;
	vector<int>arr;
	int val, n, j;

	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>val;
		arr.push_back(val);
	}

	dp.push_back(0);
	dp.push_back(abs(arr[0]-arr[1]));

	for(int i=2;i<n;i++) {
		dp.push_back(
			min(dp[i-2] + abs(arr[i]-arr[i-2]) , dp[i-1] + abs(arr[i]-arr[i-1])));
	}

	// for(auto x : dp) {
	// 	cout<<x<<" ";
	// }
	

	cout<<dp[n-1];

	return 0;
}

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

import math
import itertools

# 入力
N = int(input())
#S = str(input())
#M1, D1 = map(int, input().split())

X = math.ceil(N/1.08)

if math.floor(X*1.08) == N :
  print (X)
else :
  print (":(")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    int h, w;
    while(true){
        cin >> h >> w;
        if(h == 0 && w == 0) return 0;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i%2 == j%2){
                    printf("#");
                } else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }

}



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

int main(){
  int N;
  cin >> N;
  vector<int> A1(N);
  vector<int> A2(N);
  for(int i = 0;i < N;i++){
    cin >> A1.at(i);
  }
  for(int k = 0;k < N;k++){
    cin >> A2.at(k);
  }
  int R = 0;
  for(int j = 0;j < N;j++){
    int count = 0;
    for(int l = 0;l < N;l++){
      if(l <= j){
        count += A1.at(l);
      }
      if(l >= j){
        count += A2.at(l);
      }
    }
    if(count > R){
      R = count;
    }
  }
  cout << R << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int main()
{
  int h, w;
  char s[6];
  scanf("%d%d", &h, &w);
  
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      scanf("%s", s);
      if (memcmp(s, "snuke", 5) == 0)
      {
        printf("%c%d\n", j + 'A', i + 1);
        return 0;
      }
    }
  }
}

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

int main() {
  string S;
  cin >> S;
  string divide[4] = {"dream", "dreamer", "erase", "eraser"};
  
  reverse(S.begin(), S.end());
  for (int i = 0; i < 4; i++){
    reverse(divide[i].begin(), divide[i].end());
  }
  
  bool check = true;
  for (int i = 0; i < S.size();){
    bool can = false;
    for (int j = 0; j < 4; j++){
      string d = divide[j];
      if (S.substr(i, d.size()) == d){
        can = true;
        i += d.size();
      }
    }
    if(!can){
      check = false;
      break;
    }
    
  }
  
  if (check){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  
 
}


Measured memory_bytes: 512
s = int(input())

dic = {}
dic[s] = 1
a_old = s
counter = 1

while True:
  counter += 1  
  if a_old % 2 == 0:
    a_old //= 2
  elif a_old % 2 == 1:
    a_old = a_old * 3 + 1
  
  if a_old in dic.keys():
    dic[int(a_old)] += 1    
  else:
    dic[int(a_old)] = 1
    
  if 2 in dic.values():
    break

print(counter)

Measured memory_bytes: 38768
// C - Bridge

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

class DisjointSet {
public:
	vector<int> rank;
	vector<int> parent;

	DisjointSet() {}

	// 0, 1, ... size-1 をそれぞれ唯一の要素とする
	// size個の互いに素な集合を作成
	DisjointSet(int size) {
		rank.resize(size, 0);
		parent.resize(size, 0);
		for (int i=0; i<size; i++) {
			makeSet(i);
		}
	}

	// 要素がXただ一つである新しい集合を作る
	void makeSet(int x) {
		parent[x] = x;
		rank[x] = 0;
	}

	// xとyが同じ集合に属しているかを判定する
	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	// 指定された2つの要素x, yを合併する
	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	// 低い方の木を高い方の木に合併
	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			parent[y] = x;
		} else {
			parent[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}

	// 要素xが属する集合の代表の要素を求める
	int findSet(int x) {
		if (x != parent[x]) {
			parent[x] = findSet(parent[x]);
		}
		return parent[x];
	}
};

int a[50], b[50];

int main() {
	int N, M;
	cin >> N >> M;

	for (int i=0; i<M; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}

	int ans = 0;
	for (int not_use = 0; not_use < M; not_use++) {
		DisjointSet ds = DisjointSet(N);
		for (int i=0; i<M; i++) {
			if (i != not_use) {
				ds.unite(a[i], b[i]);
			}
		}

		for (int i=1; i<N; i++) {
			if (ds.same(0, i) == false) {
				ans++;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		double sum = 0;
		for (int i = 0; i < n; i++) {
			double x = sc.nextDouble();
			String u = sc.next();
			if (u.equals("JPY")) {
				sum += x;
			} else {
				sum += x * 380000;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 23380
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	sort(all(s));
	if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
bool isprime(int n) {
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
int ans[4];
signed main() {
    rep(i,6) {
        int a;cin >> a;
        a--;
        ans[a]++;
    }
    int count = 0;
    rep(i, 6) {
        if(ans[i]%2==1) count++;
    }
    if(count==0||count==2)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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 main() {
  int A, B;
  char op;
  cin >> A >> op >> B;
  cout << (op == '+' ? A + B : A - B) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int n,i;
	double x1,x2,x3;
	double y1,y2,y3;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		double a1=2*(x2-x1);
		double b1=2*(y2-y1);
		double c1=x1*x1-x2*x2+y1*y1-y2*y2;
		double a2=2*(x3-x1);
		double b2=2*(y3-y1);
		double c2=x1*x1-x3*x3+y1*y1-y3*y3;
		
		double outx=(b1*c2-b2*c1)/(a1*b2-a2*b1);
		double outy=(c1*a2-c2*a1)/(a1*b2-a2*b1);
		double r=sqrt((x1-outx)*(x1-outx)+(y1-outy)*(y1-outy));
		printf("%.3lf %.3lf %.3lf\n",outx,outy,r);
	}
	return 0;
}

Measured memory_bytes: 664
#include<iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
    while (cin >> a >> b >> c >> d >> e >> f) {
        a *= 100;
        b *= 100;
        int ta = f / a, tb = f / b, tc = f / 100 * e / c + 1, td = f / 100 * e / d + 1;
        double mi = 0;
        int waters = 0, sugars = 0;
        for (int i = 0; i <= ta; i++) {
            for (int j = 0; j <= tb; j++) {
                int water = i*a + j*b;
                if (water && water < f) {
                    for (int k = 0; k <= tc; k++) {
                        for (int w = 0; w <= td; w++) {
                            int sugar = k*c + w*d;
                            if (sugar > water / 100 * e) continue;
                            int all = sugar + water;
                            double t = 100 * sugar*1.0 / (all) + 1e-6;
                            if (all <= f && mi < t) {
                                waters = all;
                                sugars = sugar;
                                mi = t;
                            }
                        }
                    }
                }
            }
        }
        cout << waters << " " <<  sugars << endl;
    }
    return 0;
}

Measured memory_bytes: 256