akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <vector>
using namespace std;


int findBuyT(int N, vector<int>& A, int curT) {
  int buyT = curT;
  for (int t = curT + 1; t < N; t++) {
    if (A[t] > A[buyT]) break;
    buyT = t;
  }
  return buyT;
}

int findSellT(int N, vector<int>& A, int curT) {
  if (curT == N-1) return curT;
  int sellT = curT;
  for (int t = curT + 1; t < N; t++) {
    if (A[t] < A[sellT]) break;
    sellT = t;
  }
  return sellT;
}


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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int curT = 0;
  long long money = 1000;

  while (curT < N - 1) {
    int buyT = findBuyT(N, A, curT);
    int sellT = findSellT(N, A, buyT);
    if (sellT > buyT) {
      long long numBuyStock = money / A[buyT];
      money += (A[sellT] - A[buyT]) * numBuyStock;
    }
    curT = sellT;
  }

  cout << money << endl;

  return 0;
}


Measured memory_bytes: 3620
m, d = gets.split.map(&:to_i)  # スペースで区切られた複数の整数

ans = 0
(1..m).each do |month|
  (1..d).each do |day|
	d1 = day % 10
	d10 = day / 10
    next if d1 <= 1 || d10 <= 1
	ans += 1 if month == d1 * d10
  end
end
puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    float a,b,c,d,e,f;

    while(cin>>a>>b>>c>>d>>e>>f)
    {
        float x1=c*e-b*f;
        float y1=a*f-c*d;
        float z1=a*e-b*d;

        float x,y;

        if(a==0 && d==0) x=0;

        else x=x1/z1;

        if(b==0 && e==0) y=0;

        else y=(c-a*x)/b;

        if(x==-0.00) x=0.00;

        printf("%.3f %.3f\n",x,y);
    }

    return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

vector<string> rotate(vector<string> C, int R) {
	if (R == 0) return C;

	int H = C.size();
	int W = C[0].length();

	if (R == 90) {
		vector<string> res(W);
		rep(i, W) {
			res[i] = "";
			rep(j, H) res[i] += C[H - 1 - j][i];
		}
		return res;
	}

	if (R == 180) {
		vector<string> res(H);
		rep(i, H) {
			res[i] = "";
			rep(j, W) res[i] += C[H - 1 - i][W - 1 - j];
		}
		return res;
	}

	if (R == 270) {
		vector<string> res(W);
		rep(i, W) {
			res[i] = "";
			rep(j, H) res[i] += C[j][W - 1 - i];
		}
		return res;
	}

	return C;
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<string> s(2);
	rep(i, 2) cin >> s[i];
	vector<string> rec = rotate(s, 180);
	if (rec == s) printf("%s\n", "YES");
	else printf("%s\n", "NO");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    int n;
    cin >> n;
    ll ans = 0;
    ll cur = 0;
    for (int i=0;i<n;++i) {
        ll x;
        cin >> x;
        if (x == 0) {
            ans += cur/2;
            cur = 0;
        }
        else {
            cur += x;
        }
    }
    ans += cur/2;
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
long long MOD = 1e9 + 7;
int main(){
    long long N;
    cin >> N;
    string S;
    cin >> S;
    map<char, long long> m;
    for(int i = 0; i < N; i++){
        m[S[i]]++;
    }
    long long ans = 1;
    for(auto v: m){
        ans *= (v.second + 1);
        ans %= MOD;
    }
    ans -= 1;
    cout << (ans + MOD) % MOD << endl;
}

Measured memory_bytes: 512
from itertools import *
import copy
N,M=map(int,input().split())
KL=[list(map(int,input().split())) for i in range(N)]

human=[set() for i in range(N+1)]
gengo=[set() for i in range(M+1)]
for i in range(N):
    for m in range(1,KL[i][0]+1):
        human[i].add(KL[i][m])
        gengo[KL[i][m]].add(i)

usedhuman=set([1])
usedgengo=set(human[1])
stack=[i for i in human[1]]
while stack:
    g=stack.pop()
    for h in gengo[g]:
        if not h in usedhuman:
            usedhuman.add(h)
            for ng in human[h]:
                if not ng in usedgengo:
                    usedgengo.add(ng)
                    stack.append(ng)

if len(usedhuman)==N:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 101080
import sys
input = sys.stdin.readline
N = int(input())

def dec_to_n(N, n):
    if N == 0:
        return "0"
    digits = []
    i = 0
    base = 1
    while N != 0:
        if N % (base * n) == 0:
            digits.append('0')
        else:
            digits.append('1')
            N -= base
        i += 1
        base *= n
    return "".join(digits[::-1])

print(dec_to_n(N, -2))

Measured memory_bytes: 38256
import java.util.*;
public class Main {
	//0155 start
	//0211 cording end
	//0221 sample matched
	int INF = 1 << 24;
	
	class State implements Comparable<State> {
		int now, cost, fix;

		public State(int now, int cost, int fix) {
			this.now = now;
			this.cost = cost;
			this.fix = fix;
		}

		@Override
		public int compareTo(State o) {
			if(this.fix < o.fix)return -1;
			if(this.fix > o.fix) return 1;
			if(this.cost < o.cost) return -1;
			if(this.cost > o.cost ) return 1;
			return 0;
		}

		@Override
		public String toString() {
			return "State [now=" + now + ", cost=" + cost + ", fix=" + fix
					+ "]";
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int c = sc.nextInt();
			if((n|m|c) == 0 ) break;
			int [][] pass = new int[n][n];
			for(int i = 0 ; i < n;i++){
				Arrays.fill(pass[i], INF);
				pass[i][i] = 0;
			}
			for(int i = 0 ; i < m; i++){
				int from = sc.nextInt() - 1;
				int to = sc.nextInt() - 1;
				int cost = sc.nextInt();
				pass[from][to] = cost;
				//pass[to][from] = cost;
			}
			
			PriorityQueue<State> open = new PriorityQueue<Main.State>();
			open.add(new State(0, 0, 0));
			int [][] close = new int[n][m + 2];
			for(int i = 1 ; i < n; i++){
				Arrays.fill(close[i], INF);
			}
			
			int ans = INF;
			while(! open.isEmpty()){
				State now = open.poll();
				if(now.now == n-1){
					//System.out.println(now);
					ans = now.fix;
					break;
				}
				for(int i = 0 ; i < n; i++){
					if(pass[now.now][i] == INF) continue;
					int nextfix = now.fix + 1;
					if(close[i][nextfix] > now.cost){
						open.add(new State(i, now.cost, nextfix));
						close[i][nextfix] = now.cost;
					}
					
					nextfix = now.fix;
					int nextcost = now.cost + pass[now.now][i];
					if(nextcost > c) continue;
					if(close[i][nextfix] > nextcost){
						open.add( new State(i, nextcost, nextfix));
						close[i][nextfix] = nextcost;
					}
				}
			}
			System.out.println(ans);
		}
	}
	
	
	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 14000
#include<iostream>
using namespace std;
int main(){
  int floor[4][3][10]={{{}}},n,b,f,r,v;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    floor[b-1][f-1][r-1] += v;
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
    cout << " " << floor[i][j][k];
      }
      cout << endl;
    }
    if(i!=3)
    cout << "####################" << endl;
  }
}


Measured memory_bytes: 3100
/*s1190073  Rina Sato
  File name: prog3b.c
  This is a program that simulates the round-robin scheduling using a queue.
*/

#include <stdio.h>
#include <string.h>

struct Process{
  char name[100];
  int t;
};

struct Process Q[1001];
int n;
void enqueue(struct Process x){
  struct Process S;
  int i;
  S = x;
  for(i = 0 ; i < n ; i++){
    if(i == n-1){
      Q[i] = S;
    }
    else {
      Q[i] = Q[i+1];
    }
  }
}
struct Process dequeue(void){
  struct Process R;
  int i;
  R = Q[0];
  for(i = 0 ; i < n ; i++){
    if(i == n-1){
      n = n-1;
    }
    else {
      Q[i] = Q[i+1];
    }
  }
  return R;   
}

int main(){
  struct Process A;
  int i,q,time1=0,time2=0;
  scanf("%d %d",&n,&q);
  
  for(i = 0 ; i < n ; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  while(1){
    time1 = Q[0].t - q; 
    if(time1 <= 0){
      time2 += Q[0].t;
      Q[0].t = time2;
      A = dequeue();
      printf("%s %d\n",A.name,A.t);
      if(n == 0) break;
      
    }
    else {
      Q[0].t = time1;
      enqueue(Q[0]);
      time2 += q;
    }
  }
  return 0;
}

Measured memory_bytes: 516
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(void){
    int a,b;
    cin >> a >> b;
    for(int i=0;i<200000;i++){
      if(i/10==b&&i*2/25==a){
        cout << i;
        return 0;
      }
    }
    cout << -1;
}


Measured memory_bytes: 256
def main():
    from math import ceil
    from itertools import accumulate
    from bisect import bisect_left
    n, h, *ab = map(int, open(0).read().split())

    x = max(ab[::2])
    *y, = filter(lambda i: i >= x, ab[1::2])
    y.sort(reverse=True)
    *z, = accumulate(y)

    if z[-1] <= h:
        print(len(y) + ceil((h - z[-1]) / x))
    else:
        print(bisect_left(z, h) + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25636
import java.util.*;
import java.io.*;

public class Main {

    static int[] a;
    static int n;
    static int k;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        n = Integer.parseInt(st.nextToken());
        k = Integer.parseInt(st.nextToken());
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(br.readLine());
        }
        System.out.println(solv());
    }

    static int solv() {
        int left = 0;
        int right = 1000000000;
        while (right - left > 1) {
            int cent = (left + right) / 2;
            if (check(cent)) {
                right = cent;
            } else {
                left = cent;
            }
        }
        return right;
    }

    static boolean check(int p) {
        int index = 0;
        for (int i = 0; i < k; i++) {
            int sum = 0;
            while (sum+a[index] <= p) {
                sum += a[index];
                index++;
                if (index == n) { return true; }
            }
        }
        return false;
    }
}

Measured memory_bytes: 35332
#include<stdio.h>
int main(void){
  int N,A,B,ansA,ansB;
  scanf("%d %d %d",&N,&A,&B);
  ansA=N*A;
  ansB=B;
  if(ansA<=ansB){
    printf("%d",ansA);
  }
  else{
    printf("%d",ansB);
  }
  return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

map<VI, int> mp;
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n) {
    int w;
    cin >> w;
    VI vec = {0, 1, 2};
    REP(j, w) {
      int a; cin >> a;
      if(a == 0) {
        swap(vec[0], vec[1]);
      } else{
        swap(vec[1], vec[2]);
      }
    }
    mp[vec]++;
  }

  if(n >= 6) {
    cout << "yes" << endl;
    return 0;
  }

  VVI vv;
  for(auto i: mp) {
    REP(j, i.second) {
      vv.PB(i.first);
    }
  }

  sort(ALL(vv));
  FOR(i, 1, 1<<vv.size()) {
    VVI v;
    REP(j, vv.size()) {
      if(i&1<<j) v.PB(vv[j]);
    }
    // sort(ALL(v));
    // cout << v << endl;
    do {
      VI v2 = {0, 1, 2};
      for(auto &i: v) {
        v2[0] = i[v2[0]];
        v2[1] = i[v2[1]];
        v2[2] = i[v2[2]];
      }
      if(v2 == VI{0, 1, 2}) {
        cout << "yes" << endl;
        return 0;
      }
    } while(next_permutation(ALL(v)));
  }

  cout << "no" << endl;

  return 0;
}



Measured memory_bytes: 3236
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let (x, t) = get!(i64, i64);
    println!("{}", cmp::max(0, x - t));
}

Measured memory_bytes: 2112
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int d;
ll g;
vector<ll> p, c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> d >> g;
  p.resize(d); c.resize(d);
  REP(i, d) cin >> p[i] >> c[i];

  ll res = 1 << 29;

  REP(bit, (1 << d)) {
    ll sum = 0;
    ll num = 0;

    REP(i, d) {
      if(bit & (1 << i)) sum += c[i] + p[i] * (100 * (i + 1)), num += p[i];
    }
    if(sum >= g) res = min(res, num);
    else {
      RREP(i, d) {
        if(bit & (1 << i)) continue;
        REP(j, p[i]) {
          if(sum >= g) break;
          sum += 100 * (i + 1);
          num++;
        }
        if(g < sum) sum += c[i];
      }
      res = min(res, num);
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int n;

	int count = 0;
	vector<int> result;
	while(cin >> n){

		for(int a = 0; a <= 9; a++)
			for(int b = 0; b <= 9; b++)
				for(int c = 0; c <= 9; c++)
					for(int d = 0; d <= 9; d++)
						if(a+b+c+d == n)
							count++;

		result.push_back(count);
		count = 0;
	}

	for(const int& x : result){
		cout << x << endl;
	}


	return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>

#define INFTY 1000000000

typedef struct
{
  char mark;
  int number;
}Card;

void merge(Card B[],int left,int mid,int right)
{
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  Card L[n1],R[n2];
  for(i = 0;i < n1;i++)
    {
      L[i] = B[left + i];
    }
  for(i = 0;i < n2;i++)
    {
      R[i] = B[mid + i];
    }
  L[n1].number = INFTY;
  R[n2].number = INFTY;
  i = 0;
  j = 0;
  for(k = left;k < right;k++)
    {
      if(L[i].number <= R[j].number)
	{
	  B[k] = L[i++];
	}
      else
	{
	  B[k] = R[j++];;
	}
    }
}
void mergeSort(Card B[],int left,int right)
{
  int mid;
  if(left + 1 < right)
    {
      mid = (left + right)/2;
      mergeSort(B,left,mid);
      mergeSort(B,mid,right);
      merge(B,left,mid,right);
    }
}
int partition(Card A[],int p,int n)
{
  int i,j;
  Card x,temp;
  x = A[n];
  i = p - 1;
  for(j = p;j < n;j++)
    {
      if(A[j].number <= x.number)
	{
	  i ++;
	  temp = A[i];
	  A[i] = A[j];
	  A[j] = temp;
	}  
    }
    temp = A[i + 1];
    A[i + 1] = A[n];
    A[n] = temp;
    
  return i+1;
}

void quicksort(Card A[],int p,int r)
{
  int q;
  if(p < r)
    {
      q = partition(A,p,r);
      quicksort(A,p,q - 1);
      quicksort(A,q + 1,r);
    }
}

int main()
{
  int n,i,f = 0;
  Card A[100000],B[100000];
  
  scanf("%d",&n);

  for(i = 0;i < n;i ++)
    {
      scanf("%s %d",&A[i].mark,&A[i].number);
      B[i].mark = A[i].mark;
      B[i].number = A[i].number;
    }

  quicksort(A,0,n - 1);
  mergeSort(B,0,n);

  for(i = 0;i < n;i++)
    {
      if(A[i].mark != B[i].mark)
	{
	  f = 1;
	}
    }

  if(f == 1)
    {
      printf("Not stable\n");
    }
  else
    {
      printf("Stable\n");
    }

  for(i = 0;i < n;i++)
    {
      printf("%c %d\n",A[i].mark,A[i].number);
    }
  return 0;
}



Measured memory_bytes: 4072
//by rko27
// how can i win if i am afraid to lose
/////////////////////////////
/////////////////////////////
/// *** JAI SHREE RAM *** ///
/// *** JAI HANUMAN *** ///
/////////////////////////////
/////////////////////////////
//---------------------------------------------------------------------------------------------------------------------------------------------------

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int  long long
#define double long double 
#define ll  long long 
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define nl "\n"
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)(x.size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define god ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//----------------------------------------------------------------------------------------------------------------------------------------------------

const double pi = 3.14159265358979323;
int mod=1000000000+7;
int modu=998244353;
const double pii=acos(-1.0);
const int INF=1e18;
const int inf=1e9;

//----------------------------------------------------------------------------------------------------------------------------------------------------

ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll powe(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
bool isPrime(int n){for(int i=2;i*i<=n;i++)if(n%i==0) return false;return true;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}

//-------------------------------------------------------------------------------------------------------------------------------------------------------

void fun()
{
	
	//786
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------

const int N=1e5+7;
int dx[8] = {1, 0,-1, 0, 1, -1, 1, -1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

//--------------------------------------------------------------------------------------------------------------------------------------------------------



//--------------------------------------------------------------------------------------------------------------------------------------------------------
signed main() 
{
	god;
	//rko;
	fun();
	int tttt=1; //cin>>tttt;
	while(tttt--)
	{
		string s; cin>>s;
		int n=sz(s);
		int m= 2019;
		std::vector<int> count(2019);
		int val=0;
		count[val]++;
		int power_of_ten = 1;
		int ans=0;
		for(int i=n-1;i>=0;i--)
		{
			int digit = s[i] - '0';
			val = (val + digit * power_of_ten) % m;
			ans += count[val];
			count[val]++;
			power_of_ten *= 10;
			power_of_ten %= m;
		}
		cout<<ans<<nl;
	}
	return 0;
}

Measured memory_bytes: 3776
import time
start = time.time()
n = int(input())
a = list(map(int,input().split()))
b = []
m = 0
for i in range(1,n):
    m = m ^ a[i]
b.append(m)
for j in range(1,n):
    m = m ^ a[j-1]
    m = m ^ a[j]
    b.append(m)
b = map(str,b)
print(' '.join(b))

Measured memory_bytes: 39424
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <functional>
#include <queue>

#define rep(i, n) for(int i = 0, end = (int)(n); i < end; i++)

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

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
struct UnionFind{
	int par[10100],rank[10100];
	void init(int n){
		for(int i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		else return par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(rank[x]>rank[y]){
			par[y]=x;
		}else{
			if(rank[x]==rank[y])rank[y]++;
			par[x]=y;
		}
		return;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
}uf;
struct edge{
	int from,to,dist,cost;
	edge(){}
	edge(int from,int to,int dist,int cost):from(from),to(to),dist(dist),cost(cost){}
	edge(int to,int cost):from(from),to(to),cost(cost){}
	bool operator < (const edge &a) const {
		return cost < a.cost;
	}
};
int N,M;
vector<edge> g[10010];
vector<edge> es;
int d[10010];
bool in[10010];
void dijkstra(){
	for(int i=0;i<N;i++)d[i]=INF;
	d[0]=0;
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(0,0));
	while(!q.empty()){
		P a = q.top();
		q.pop();
		int v = a.sec;
		if(d[v]<a.fi)continue;
		for(int i=0;i<g[v].size();i++){
			edge e = g[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				q.push(P(d[e.to],e.to));
			}
		}
	}
}
int solve(){
	scanf("%d %d",&N,&M);
	if(N+M==0)return 1;
	for(int i=0;i<N;i++)g[i].clear();
	es.clear();
	memset(in,false,sizeof(in));
	uf.init(N);
	for(int i=0;i<M;i++){
		int u,v,d,c;
		scanf("%d %d %d %d",&u,&v,&d,&c);
		u--;v--;
		g[u].pb(edge(v,d));
		g[v].pb(edge(u,d));
		es.pb(edge(u,v,d,c));
	}
	sort(all(es));
	dijkstra();
	//for(int i=0;i<N;i++)printf("%d:%d\n",i,d[i]);
	ll ans = 0ll;
	for(int i=0;i<es.size();i++){
		edge e = es[i];
		if(d[e.to]<d[e.from])swap(e.to,e.from);
		if(d[e.to]-d[e.from]==e.dist){
			if(!in[e.to]){
				in[e.to]=true;
				ans += (ll)e.cost;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}	
int main(){
	while(!solve()){}
	return 0;
}

Measured memory_bytes: 5884
class FutureMath:
    def gcd(self, a, b):
        if a < b:
            return self.gcd(b, a)
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    def gcd_(self, list):
        result = list[0]
        for el in list[1:]:
            result = self.gcd(result, el)
        return result

    def lcm(self, a, b):
        return a * b // self.gcd(a, b)

    def lcm_(self, list):
        result = list[0]
        for el in list[1:]:
            result = self.lcm(result, el)
        return result

    def cds(self, n):
        result = list()
        for i in range(1, n+1):
            if n % i == 0:
                result.append(i)
        return result


fm = FutureMath()

if __name__ == "__main__":
    a, b, k = map(int, input().split())
    gcd = fm.gcd(a, b)
    cds = fm.cds(gcd)
    print(cds[-k])


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

int main(){
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < 4; i++) {
        if(S.at(i) == '+') {
            ans++;
        } 
        else {
            ans--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3476
#include<iostream>
#include<cstdio>
#define INF 100000000
#define rep(i,n) for(int i=0;i<n;i++)
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef pair<int,int> p;
typedef pair<int,p> pp;
typedef pair<double,pp> P;
struct edge{
	int to,d,c;
};
int main(){
	double dp[31][31][31];
	int n,m,s,g,x,y,d,c,ds[]={1,-1,0};
	while(cin>>n>>m,n||m){
		vector<edge> G[31];
		cin>>s>>g;
		s--;g--;
		rep(i,m){
			cin>>x>>y>>d>>c;
			x--;y--;
			edge e;
			e.d=d;e.c=c;
			e.to=y;
			G[x].push_back(e);
			e.to=x;
			G[y].push_back(e);
		}
		rep(i,31)
		rep(j,31)
		rep(k,31)
		dp[i][j][k]=INF;
		dp[0][s][s]=0.0;
		priority_queue<P,vector<P>,greater<P> > que;
		que.push(P(0.0,pp(-1,p(0,s))));
		double ans=INF;
		while(!que.empty()){
			P q=que.top();que.pop();
			if(q.second.second.second==g&&q.second.second.first==1){
				ans=min(ans,dp[q.second.second.first][q.second.second.second][q.second.first]);
			//	cout<<ans<<endl;
				break;
			}
			//cout<<q.second.second<<' '<<q.second.second.first<<' '<<q.first<<endl;
			if(dp[q.second.second.first][q.second.second.second][q.second.first]<q.first)
				continue;
			rep(i,G[q.second.second.second].size()){
				edge e=G[q.second.second.second][i];
				if(e.to==q.second.first)
				continue;
				rep(j,3){
					int pre=q.second.second.first+ds[j];
					if(pre<1)
						continue;
					double tes=(double)e.d/pre+q.first;
					if(pre<=e.c&&dp[pre][e.to][q.second.second.second]>tes){
						que.push(P(tes,pp(q.second.second.second,p(pre,e.to))));
						dp[pre][e.to][q.second.second.second]=tes;
					}
				}
			}
		}
		if(ans==INF)
		cout<<"unreachable"<<endl;
		else
		printf("%.5lf\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1708
#include <stdio.h>
#define MAX 100000
int p,parent[MAX],sibling[MAX],degree[MAX];
int Depth(int i),Height(int i);
int main(){
  int i,j,id,a,b;;
  scanf("%d",&p);
  for(i=0;i<p;++i){
    parent[i]=-1;
    sibling[i]=-1;
    degree[i]=0;
  }
  for(i=0;i<p;++i){
    scanf("%d%d%d",&id,&a,&b);
    if(a!=-1){
      parent[a]=id;
      sibling[a]=b;
      ++degree[id];
    }
    if(b!=-1){
      parent[b]=id;
      sibling[b]=a;
      ++degree[id];
    }
  }
  for(i=0;i<p;++i) {
    int depth=Depth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,parent[i],sibling[i],degree[i],depth,Height(i));
    if(depth==0){
      printf("root\n");
    }
    else if(degree[i]==0)
      printf("leaf\n");
    else
      printf("internal node\n");
  }
  return 0;
  }

int Depth(int i){
  if(parent[i]==-1)
    return 0;
  return Depth(parent[i])+1;
}

int Height(int i){
  int k,h;
  h=0;
  for(k=0;k<p;++k){
    if(parent[k]==i){
      int tmp=Height(k)+1;
      if(tmp>h){
        h=tmp;
      }
    }
  }
  return h;
}



Measured memory_bytes: 2104
#include<cstdio>

using namespace std;

int boal[11];
bool ans;


void BFS(int L,int R,int c){
	
	if(c == 10 || ans){
		ans = true;
		return;
	}
	
	if(L < boal[c]){
		L = boal[c];
		BFS(L,R,c+1);
	}
	if(R < boal[c]){
		R = boal[c];
		BFS(L,R,c+1);
	}
}

int main(void){
	int n;
	while(scanf("%d", &n) != EOF){
		for(int j = 0; j < n; j++){
			ans = false;
			for(int i = 0; i < 10; i++){
				scanf("%d", &boal[i]);
			}
			
			BFS(0,0,0);
			
			printf("%s\n",ans?"YES":"NO");
		}
	}
	return 0;
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int n,a[100];
	cin >> n;
    fori(n){cin>>a[i];}
    int score=1000000000;
    sort(a,a+n);
    int mini=a[0];
    int max=a[n-1];
    for(int i=mini;i<=max;++i){
        int hoge=0;
        for(int j=0;j<n;++j){
            hoge+=(i-a[j])*(i-a[j]);
        }
        if(hoge<score){
            score=hoge;
        }
    }
    cout<<score;
	return 0;
}

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

int main()
{
	double b=0,c;
	int n;
	cin>>n;
	int a[n],i;
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
		{
			b=b+(float)(1)/(float)(a[i]);
		}
	c=1/b;
	cout<<c<<endl;	
}

Measured memory_bytes: 3712
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt() - 1;
        int b = sc.nextInt() - 1;
        char[][] g = new char[100][100];
        for(int i=0; i<50; i++) {
            Arrays.fill(g[i], '#');
        }
        for(int i=50; i<100; i++) {
            Arrays.fill(g[i], '.');
        }

        int x = 0;
        int y = 0;
        for(int i=0; i<a; i++) {
            g[x][y] = '.';
            y += 2;
            if(y >= 100) {
                x += 2;
                y = 0;
            }
        }
        x = 51;
        y = 0;
        for(int i=0; i<b; i++) {
            g[x][y] = '#';
            y += 2;
            if(y >= 100) {
                x += 2;
                y = 0;
            }
        }

        System.out.println("100 100");
        for(int i=0; i<100; i++) {
            System.out.println(new String(g[i]));
        }

    }

}


Measured memory_bytes: 24532
#include <bits/stdc++.h>
 
//g++ -std=c++11
//g++ -std=c++1z 

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector< pair<int,int> > vp;

int main() {
 
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
 
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);

   	double r;
    cin >> r;

    const double PI = 3.14159265;
    cout << std::setprecision(20) << std::fixed;
    cout << 2*M_PI*r << endl;

    return 0;
}

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

int main()
{
    int r,g,b;
    cin >> r >> g >> b;
    int ans = g*10+b;
    if(ans % 4 == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
N = int(input())
node = [[]for i in range(N)]
side = []
count = [0]*N
ans = [0]*(N-1)
closed = [0]*N
for i in range(N-1):
    a,b = map(int,input().split())
    side.append([a-1, b-1])
    node[a-1].append(i)
    node[b-1].append(i)
    count[a-1] += 1
    count[b-1] += 1

K = max(count)
print(K)

queue = deque([[0,K+1]])


while queue:
    q,m = queue.popleft()
    p = 1
    for i in node[q]:
        if p == m:
            p += 1
        if ans[i] == 0:
            ans[i] = p
            s = side[i]
            next = s[(s.index(q)+1)%2]
            if closed[next] == 0:
                queue.append([next,p])
                closed[next] = 1
            p += 1

for i in ans:
    print(i)

Measured memory_bytes: 87328
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i,0,n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

class BIT{
    vector<long long> bit;
public:
    void BIT_init(long long n){
        bit.assign(n + 1, 0);
        return;
    }
    long long get_sum(int i){
        i++;
        long long res = 0;
        while(i > 0){
            res += bit[i];
            i -= i&(-i);
        }
        return res;
    }
    void add(int i, long long x){
        i++;
        while(i <= bit.size() - 1){
            bit[i] += x;
            i += i&(-i);
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,Q;
    cin >> N >> Q;
    vl A(N);
    BIT bit;
    bit.BIT_init(N);
    rep(i,N){
        int a;
        cin >> a;
        bit.add(i,a);
    }
    rep(i,Q){
        int t,pos,x;
        cin >> t >> pos >> x;
        if(t){
            cout << bit.get_sum(x-1)-bit.get_sum(pos-1) << '\n';
        }
        else{
            bit.add(pos,x);
        }
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
Is q inputed?
*/

Measured memory_bytes: 12144
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let n:usize = read();
    let mut a: Vec<i32> = Vec::with_capacity(n);
    let mut sum: i32 = 0;
    let mut mini: i32 = 0;
    let mut max: i32 = 0;
    unsafe{
	a.set_len(n);
    }
    for i in 0..n{
	let number:i32 = read();
	a[i] = number;
	sum += number;
    }
    sum /= n as i32;
    for i in 0..n{
	mini += (a[i]-sum)*(a[i]-sum);
	max += (a[i]-sum-1)*(a[i]-sum-1);
    }
    if mini < max {
	println!("{}",mini);
    }else{
	println!("{}",max);
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

/**
 * 解説通り実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray();
			char pre2 = s[0];
			char pre1 = s[1];
			int start = -1, end = -1;
			if (pre2 == pre1) {
				start = 1;
				end = 2;
			} else {
				for (int i = 2; i < s.length; i++) {
					char now = s[i];
					if (pre2 == now) {
						start = i - 1;
						end = i + 1;
						break;
					} else if (pre1 == now) {
						start = i;
						end = i + 1;
						break;
					}
					pre2 = pre1;
					pre1 = now;
				}
			}
			System.out.println(start + " " + end);
		}
	}
}


Measured memory_bytes: 41740
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000
#define SIZE 51

bool f[SIZE][SIZE]; //true=land (1)
int w,h;

void wfs(int i, int j){
  //width-first search
  int d[]={1,0,-1};
  rep(di,3){
    int ni=i+d[di];
    if(ni<0 || ni>=h) continue;
    rep(dj,3){
      int nj=j+d[dj];
      if(nj<0 || nj>=w) continue;
      if(f[ni][nj]){
	f[ni][nj]=false;
	wfs(ni,nj);
      }
    }
  }
}

int main(){
  while(true){
    cin >>w>>h;
    if(w==0&&h==0) break;
    
    rep(i,h){
      rep(j,w){
	int d;
	scanf("%d", &d);
	if(d==0) f[i][j]=false;
	else  f[i][j]=true; //1=land
      }
    }

    int ans=0;
    rep(i,h){
      rep(j,w){
	if(f[i][j]){
	  ans++;
	  wfs(i,j);
	}
      }
    }

    cout << ans << endl;

  }
}

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

#define Fo(i,k,n) for(i=k ; i<n ; i++)
#define ll  long long
#define ull unsigned long long
#define f(i,n) for(int i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007

void solve()
{
  int n,k;
  cin>>n>>k;
  int H[n+1];
  for(int i=1;i<=n;i++)
    cin>>H[i];
  int dp[n+1];
  for(int i=1;i<=n;i++) dp[i] = INT_MAX;
  dp[1] = H[1];
  for(int i = 2; i<=k+1 && i<=n; i++)
    dp[i] = abs(H[i]-H[1]);
  for(int i = k+2; i<=n;i++)
  {
    for(int j=i-k;j<i;j++)
    {
      dp[i] = min(dp[i],dp[j]+abs(H[i]-H[j]));
      //cout<<"When j = "<<j<<"\n";
      //cout<<"dp["<<i<<"] at "<<i<<" = "<<dp[i]<<"\n";
    }
  }
  cout<<dp[n];
}

signed main()
{
  fastio

  int t=1;
  //cin>>t;
  
  for(int i = 1;i<=t;i++)
  {
    //cout<<"Case #"<<i<<": "<<solve()<<"\n";
    solve();
  }

}

Measured memory_bytes: 4380
n=int(input())
a=list(map(int,input().split()))
d=[-1,-1,-1]
x=1
for i in a:
  b=0
  f=True
  for j in range(3):
    if d[j]==i-1:
      b+=1
      if f:
        f=False
        d[j]=i
  x*=b
  x%=10**9+7
print(x)

Measured memory_bytes: 52952
S = list(input())
s_list = []
index = 0
result = "Good"
for x in S:
  if index == 0:
    s_list.append(x)
    index+=1
  else:
    if s_list[index-1] == S[index]:
      result = "Bad"
    else:
      s_list.append(x)
      index+=1
print(result)



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

int main(){
    int h,w; cin>>h>>w;
    vector<string> s;
    rep(i,h){
        string x; cin>>x;
        bool flg=0;
        rep(i,w){
            if(x[i]=='#') flg=1;
        }
        if(flg) s.push_back(x);
    }
    rep(i,w){
        bool flg=1;
        for(auto j:s){
            // cout<<j<<endl;
            if(j[i]=='#') flg=0;
        }
        if(flg){
            // cout<<1<<endl;
            for(auto &j:s){
                // cout<<j[i]<<endl;
                j[i]='x';
            }
        }
    }
    // for(auto i:s) cout<<i<<endl;
    for(auto i:s){
        rep(j,w){
            if(i[j]!='x') cout<<i[j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long  
using namespace std;
const int MAXN = 101;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N, M, cnt;
char s[MAXN][MAXN];
void dfs(int i, int j, int num) {
	if(i == N && j == M) {
		if(num == cnt) puts("Possible");
		else puts("Impossible");
		exit(0);
	}
	if(s[i + 1][j] == '#') dfs(i + 1, j, num + 1);
	if(s[i][j + 1] == '#') dfs(i, j + 1, num + 1);
}
int main() {
	N = read(), M = read();
	for(int i = 1; i <= N; i++) {
		scanf("%s", s[i] + 1);
		for(int j = 1; j <= M; j++) if(s[i][j] == '#') cnt++;
	}
	dfs(1, 1, 1);
	puts("Impossible");
	return 0;
}
/*
1
2 21
*/


Measured memory_bytes: 256
n, m = map(int, input().split())
if m == 0:
  if n == 1:
    print(0)
    exit()
  else:
    print(pow(10,n-1))
    exit()
num = 0
dic = {}
for i in range(m):
  s_tmp, c_tmp = list(map(int, input().split()))
  if s_tmp in dic:
    if dic[s_tmp] != c_tmp:
      print(-1)
      exit()
    else:
      continue
  dic[s_tmp] = c_tmp

if 1 in dic:
  if dic[1] == 0:
    if n != 1:
      print(-1)
      exit()
    else:
      print(0)
      exit()
else:
  num = pow(10,n-1)
for i in range(1,n+1):
  if i in dic:   
    num += dic[i] * pow(10, n-i)

      
print(num)

Measured memory_bytes: 3064
//
//  main.cpp
//

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <cmath>

using namespace::std;

#define V vector
#define VC vector<char>
#define VI vector<int>
#define VS vector<string>
#define VD vector<double>
#define VI2 vector<vector<int>>
#define VC2 vector<vector<char>>
#define VS2 vector<vector<string>>
#define VD2 vector<vector<double>>
#define S string
#define LL long long int
#define L long long
#define U unsigned
#define ULL unsigned long long int
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define out cout <<
#define in cin >>
#define output(x) cout << (x) << endl
#define debug(x) cout<<#x<<": "<<x<<endl
#define numIn(n) int (n); cin >> (n)
#define getl(s) getline(cin,(s))
#define RT cout << endl
#define rt endl
#define isUp(s,i) (s)[(i)] >= 65 && (s)[(i)] <= 90
#define ismin(a,b) (a>b?b:a)
#define ismax(a,b) (a>b?a:b)
#define outVC(v) for(int i = 0; i < (v).size(); ++i){ cout << (v)[i]; } cout << endl
#define outVI(v) for(int i = 0; i < (v).size() - 1; ++i){ cout << (v)[i] << " "; } cout << (v)[v.size() - 1]; cout << endl
#define vAll(v) (v).begin(), (v).end()
#define vSort(v) sort((v).begin(), (v).end())

#define Seed() srand((int)time(0))
#define Random(x) arc4random() / 2 % (x) + 1

VS split(const char* strTop, int length, char delm);
VS split(const string& str, char delm);

typedef struct point{
    int x;
    int y;
}Point;

int main()
{
    VI can(3);
    REP(i, 3){
        in can[i];
    }
    vSort(can);
    if(can[2] == can[1] + can[0]){
        output("Yes");
    }
    else{
        output("No");
    }
    
    return 0;
}


VS split(const char* strTop, int length, char delm)
{
    VS result;
    VC baka;
    for(int i = 0; i < length; ++i)
    {
        //区切り文字が来たらそれまでのやつを突っ込む
        if(*(strTop + i) == delm){
            string tmp(baka.begin(), baka.end());
            baka.clear();
            result.push_back(tmp);
        }
        //区切り文字が来るまでvector<char>に一つづつ入れておく
        else{
            baka.push_back(*(strTop + i));
        }
    }
    //最後だけ区切り文字がなく無視されるためそれに対する処理
    string tmp(baka.begin(), baka.end());
    result.push_back(tmp);
    
    return result;
}

VS split(const string& str, char delm)
{
    VS result;
    VC baka;
    for(int i = 0; i < str.length(); ++i)
    {
        //区切り文字が来たらそれまでのやつを突っ込む
        if(str[i] == delm){
            string tmp(baka.begin(), baka.end());
            baka.clear();
            result.push_back(tmp);
        }
        //区切り文字が来るまでvector<char>に一つづつ入れておく
        else{
            baka.push_back(str[i]);
        }
    }
    //最後だけ区切り文字がなく無視されるためそれに対する処理
    string tmp(baka.begin(), baka.end());
    result.push_back(tmp);
    
    return result;
}















Measured memory_bytes: 256
n,m=map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
MOD = 10**9+7

sum_x = 0
sum_y = 0
for i in range(n):
    sum_x += (n-1-i*2)*X[i] 
for i in range(m):
    sum_y += (m-1-i*2)*Y[i]
sum_x = sum_x%MOD
sum_y = sum_y%MOD
print((sum_x*sum_y)%MOD)



Measured memory_bytes: 18624
#include <iostream>
#include <algorithm>
#include <complex>

using namespace std;

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

  int max;

  max = a + b;

  if (max < a - b) {
    max = a - b;
  }

  if (max < a * b) {
    max = a * b;
  }

  cout << max << endl;


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}
 
Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }
}
 
Node treeSuccessor(Node x){
  Node y;
  if (x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL){
    y=z;
  }
  else{
    y=treeSuccessor(z);
  }
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else if(y==y->parent->left){
    y->parent->left=x;
  }
  else {
    y->parent->right=x;
  }
  if(y!=z){
    z->key=y->key;
  }
}
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL; 
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
    if(y==NIL){
      root=z;
    }
    else if(z->key<y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
void inorder(Node u){
  if (u->left != NIL){
    inorder(u->left);
  }
  printf(" %d", u->key);
  if (u->right != NIL){
    inorder(u->right);
  }
}
void preorder(Node u){
  printf(" %d",u->key);
  if (u->left != NIL){
    preorder(u->left);
  }
  if (u->right != NIL){
    preorder(u->right);
  }
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

Measured memory_bytes: 19364