akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector>
 
using namespace std;

#define RIGHT 1
#define LEFT -1

struct ant {
	bool isOut;
	int vp;
	int pos;
	int outTime;
};

bool isAllOut( vector< ant > *a ) {
	bool b = true;
	for( int i = 0; i < a->size(); i ++ )
		b &= a->at(i).isOut;
	return b;
}

void bumpCheck( vector< ant > *a ) {
	for( int i = 0; i < a->size(); i++ )
		for( int j = 0; j < i; j ++ ) {
			if( a->at(i).isOut | a->at(j).isOut ) continue;
			if( a->at(i).pos == a->at(j).pos && a->at(i).pos % 2 == 0 ) {
				a->at(i).vp *= -1;
				a->at(j).vp *= -1;
			}
		}

}

void outCheck( int l, vector< ant > *a, int time ) {
	for( int i = 0; i < a->size(); i++ ) {
		if( a->at(i).isOut ) 
			continue;
		if( a->at(i).pos < 0 || a->at(i).pos > 2 * l ) {
			a->at(i).outTime = time;
			a->at(i).isOut = true;
		}
	}
}

void antsProcess( vector< ant > *a ) {
	for( int i = 0; i < a->size(); i++ ) {
		if( a->at(i).isOut ) continue;
		a->at(i).pos += a->at(i).vp;
	}
}

int main(void){

	while( true ) {

		int n, l;
		cin >> n >> l;
		if( !( n | l ) ) break; 

		ant newant;
		newant.isOut = false;
		vector< ant > ants( n, newant );

		for( int i = 0; i < n; i++ ) {

			char ch;
			cin >> ch >> ants[i].pos;
			ants[i].pos *= 2;

			switch( ch ) {
				case 'R':
					ants[i].vp = RIGHT;
					break;
				case 'L':
					ants[i].vp = LEFT;
					break;
			}

		}

		int cnt = 0;
		//シュミレーション
		while( !isAllOut( &ants ) ) {
			antsProcess( &ants );
			bumpCheck( &ants );
			outCheck( l, &ants , cnt );
			cnt ++;
		}

		int ans = 0, max = 0;
		for( int i = 0; i < n; i ++ ) {
			if( max < ants[i].outTime ) {
				max = ants[i].outTime;
				ans = i + 1;
			} else if( max == ants[i].outTime && ants[i].pos < 0 ) {
				ans = i + 1;
			}
		}

		cout << cnt / 2 << " " << ans << endl;

	}

    return 0;
}

Measured memory_bytes: 1200
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int sum = 0;
		if(a>b) sum+=b;
		else sum+=a;
		if(c>d) sum+=d;
		else sum+=c;
		System.out.print(sum);

	}

}


Measured memory_bytes: 22612
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        long[] as = new long[t];
        long[] bs = new long[t];
        long[] cs = new long[t];
        long[] ds = new long[t];
        for (int i = 0;i < t;++i){
            as[i] = scanner.nextLong();
            bs[i] = scanner.nextLong();
            cs[i] = scanner.nextLong();
            ds[i] = scanner.nextLong();
        }
        for (int i = 0;i < t;++i){
            long a = as[i];
            long b = bs[i];
            long c = cs[i];
            long d = ds[i];
            if(d < b||a < b){
                System.out.println("No");
                continue;
            }
            if(c >= b){
                System.out.println("Yes");
                continue;
            }
            long k1 = a - ((a - (c + 1)) / b + 1) * b;
            if(k1 < 0){
                System.out.println("No");
                continue;
            }
            long k2 = g(b,d);
            long k3 = k1 % k2 - k2;
            if(k3 + b > c){
                System.out.println("No");
            }
            else System.out.println("Yes");
        }
    }

    public static long g(long a,long b) {
        while (a != b){
            if(a > b){
                long k = (a % b);
                a = k == 0 ? b : k;
            }
            else{
                long k = (b % a);
                b = k == 0 ? a : k;
            }
        }
        return a;
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

vector<ll> G[101010];
vector<ll> T[101010];
map<pll, ll> mp;
const ll INF = (1ll<<60);

vector<ll> mark(101010, -1);
bool is_bipartite(ll now, ll now_mark){
	if(mark[now]!=-1) return (mark[now]==now_mark);
	mark[now] = now_mark;
	bool flag = true;
	REP(i, T[now].size()){
		ll next = T[now][i];
		flag &= is_bipartite(next, 1-now_mark);
	}
	return flag;
}

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

    ll N, M;
    cin >> N >> M;
    vector<ll> D(N);
    REP(i, N) cin >> D[i];

    const ll ma = 1e9;
    vector<ll> res(M, ma);
    vector<pll> edges;
    REP(i, M){
    	ll u, v;
    	cin >> u >> v;
    	u--, v--;
    	G[u].push_back(v);
    	G[v].push_back(u);
    	if(u>v) swap(u, v);
    	mp[{u, v}] = i;
    	edges.push_back({u, v});
    }

    REP(i, N){
    	//dump(i)
    	pll mi = {INF, -1};
    	for(ll next: G[i]){
    		if(D[next]<=D[i]){
    			mi = min(mi, {D[next], next});
    		}
    	}
    	//cout << mi << endl;
    	if(mi.first == INF){
    		cout << -1 << endl;
    		return 0;
    	}

    	T[i].push_back(mi.second);
    	T[mi.second].push_back(i);

    	ll u = i;
    	ll v = mi.second;
    	if(u>v) swap(u, v);
    	res[mp[{u, v}]] = D[i];
    } 

    REP(i, N) is_bipartite(i, 0);

    REP(i, N) cout << (mark[i] ? 'B' : 'W');
    cout << endl;

    REP(i, M){
    	cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 35820
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {
    int x; cin >> x;
    x /= 200;
    x = 10 - x;
    cout << x << endl;

    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	string s1, s2, s3;
	cin >> s1;
	cin >> s2;
	cin >> s3;
	cout << s1.at(0) << s2.at(1) << s3.at(2) << endl;
} 

Measured memory_bytes: 3616
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N ,M = cin.mapInt()
    A = [True] * (N + 1)
    for i in range(M):
        a = cin.int()
        A[a - 1] = False

    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(N):
        if A[i] == True:
            dp[i + 1] = dp[i] + dp[i - 1]
            dp[i + 1] %= MOD
    print(dp[N])
    return

if __name__ == "__main__":
    main()


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

int main(void)
{
    char s[200001],t[200001],map1[26],map2[26];
    int st=1,ts=1,i,len,snum[200001],tnum[200001];

    scanf("%s%s",s,t);

    len=strlen(s);

    for ( i = 0; i < 26; i++)
    {
        map1[i]=-1;
        map2[i]=-1;
    }

    for ( i = 0; i < len; i++)
    {
        snum[i]=s[i]-'a';
        tnum[i]=t[i]-'a';
    }

    for ( i = 0; i < len; i++)
    {
        if(map1[snum[i]]==-1) map1[snum[i]]=tnum[i];
        else if(map1[snum[i]]!=tnum[i])
        {
            st=0;
            break;
        }
    }
    
    for ( i = 0; i < len; i++)
    {
        if(map2[tnum[i]]==-1) map2[tnum[i]]=snum[i];
        else if(map2[tnum[i]]!=snum[i])
        {
            ts=0;
            break;
        }
    }

    if(st*ts) printf("Yes");
    else printf("No");

    return 0;
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class10
    {
        static void Main()
        {
            var I = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = I[0];
            int B = I[1];
            int R;
            R = Math.Max(A + B, A - B);
            R = Math.Max(R, A * B);
            Console.WriteLine(R);
        }
    }
}


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

bool isRoot(int t)
{
  bool ret = false;
  int i;
  
  for(i=0;i<1000;i++)
    if(t==(i*i)) 
    {
      ret = true; goto Done;
    }
  
  Done:
  return ret;
}

int main()
{
  string A,B;
  
  cin >> A >> B;
  A+=B;
  
  int t;
  t = atoi(A.c_str());
  
  //printf("%d\n",t);
  printf("%s\n",isRoot(t)?"Yes":"No");
  return 0;
}

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

using namespace std;


int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '1'){
            putchar('9');
        }else{
            putchar('1');
        }
    }
    putchar('\n');
}

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

void array(int size){
    int number;
    int sum=0;
    vector< vector<int> > colm(size+1, vector<int>(size+1));
   
   for(int i=0;i<size;i++){
        for(int j=0;j<size;j++){
            cin >> number;
            sum += number;
            colm[i][j] = number; 
        }
        colm[i][size] = sum;
        sum=0;
   }
   //sum=0;
   
   for(int j=0;j<=size;j++){
      for(int i=0;i<size;i++){
        sum += colm[i][j];
      }
      colm[size][j] = sum;
      sum=0;
   }
   
   for(int i=0;i<=size;i++){
       for(int j=0;j<=size;j++){
           cout.width(5);
           cout << colm[i][j];
       }
       cout << endl;
   }
}


int main(){
   int size;
    string str;
    cin >> size;
    cin.ignore();
    while(size != 0){
        array(size);
        cin >> size;
    }
    return 0;
}

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

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

int main()
{
    int n;
    cin>>n;
    vector<int> a(n+2),dp(n+2),pd(n+2);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }

    for(int i=1;i<=n;i++)
    {
        dp[i] = gcd(dp[i-1],a[i-1]);
    }

    for(int i=n;i>=1;i--)
    {
        pd[i] = gcd(pd[i+1],a[i+1]);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        ans = max(ans,gcd(dp[i],pd[i]));
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

long long GCD(long long x, long long y) {
    return y ? GCD(y, x%y) : x;
}

long long a, b, c, d;

long long num(long long n) {
    long long g = GCD(c, d);
    long long l = c / g * d;
    return n - n / c - n / d + n / l;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> a >> b >> c >> d) {
        cout << num(b) - num(a-1) << endl;
    }
}


















Measured memory_bytes: 256
import sys
input = sys.stdin.readline

mm = 10**10
k = mm.bit_length()
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(200001)]]

n,m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0]*100001

for i in a:
    b[i] += 1
    
c = li(st(nu(b)*nu(b)))
ans = 0
for i in range(200001)[::-1]:
    if c[i] > 0:
      p = min(m,c[i])
      m -= p
      ans += i*p
      if m == 0:
        break
print(ans)

Measured memory_bytes: 199088
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>

#pragma comment(linker, "/STACK:336777216")  

using namespace std;

const int MAXN = 100000 + 10;
const int MAXM = 200000 + 10;

int N, M;
int To[MAXM], Next[MAXM], Node[MAXN], nE;
int Vis[MAXM * 2];
int Q[MAXN * 2];

void InsertEdge(int a, int b)
{
	To[nE] = b;
	Next[nE] = Node[a];
	Node[a] = nE ++;
}

int BFS()
{
	int nQ = 0;
	memset(Vis, -1, sizeof(Vis));
	Q[nQ ++] = 0;
	Vis[0] = 0;

	int Tot = 0;
	for (int h = 0; h < nQ; h ++)
	{
		int i = Q[h];
		for (int jj = Node[i >> 1]; jj != -1; jj = Next[jj])
		{
			int j = To[jj];
			int conjb = ((j << 1) | (i & 1)) ^ 1;
			if (Vis[conjb] == -1)
			{
				Vis[conjb] = Vis[i] + 1;
				Q[nQ ++] = conjb;
			}
		}
	}
	return -1;
}

void Work()
{
	scanf("%d%d", &N, &M);
	memset(Node, -1, sizeof(Node));
	nE = 0;
	for (int i = 0; i < M; i ++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a --;
		b --;
		InsertEdge(a, b);
		InsertEdge(b, a);
	}
	BFS();

	long long x = 0, y = 0, z = 0;
	for (int i = 0; i < N; i ++)
	{
		if (Vis[(i << 1)] != -1 && Vis[(i << 1) + 1] != -1) z ++;
		else if (Vis[(i << 1)] != -1) x ++;
		else y ++;
	}
	long long Ans = (x * y) + (x * z) + (y * z) + (z * (z - 1) / 2) - M;
	printf("%lld\n", Ans);
}

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

Measured memory_bytes: 4480
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

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

typedef long long ll;
using namespace std;

int main() {
  ll A, B, K;
  cin >> A, cin >> B, cin >> K;

  if (abs(A - B) <= K) {
    
    for (ll i = A; i <= B; i++) {
      cout << i << endl;
    }
  } else {
    vector<ll> vec;
    for (ll i = A; i < A + K; i++) {
      vec.push_back(i);
    }
    for (ll i = B - K + 1; i <= B; i++) {
      vec.push_back(i);
    }
    sort( vec.begin(), vec.end() );
    vec.erase( unique( vec.begin(), vec.end() ), vec.end() );

    REP(i, vec.size()) {
      cout << vec[i] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
  
#define INF 1000000
#define NIL NULL
#define WHITE 5000
#define BLACK 5001
void initializeSource(void);
void heavy(void);
int v[101][101],c[101][101];
int *d,*pi,*color,*k;
int n;



int main(){
  int i,j;
  int *u;
  scanf("%d",&n);
  
  u = malloc(sizeof(int)*n);
  d = malloc(sizeof(int)*n);
  pi = malloc(sizeof(int)*n);
  color = malloc(sizeof(int)*n);
  k = malloc(sizeof(int)*n);


  
  for(i = 0;i < n;i++){
    scanf("%d %d",&u[i],&k[i]);
    for(j = 0;j < k[i];j++){
      scanf("%d",&v[i][j]);
      scanf("%d",&c[i][j]);
    }
  }
  
  heavy();
  
  for(i = 0;i < n;i++){
    printf("%d %d\n",u[i],d[i]);
  }
  
  return 0;
}



void initializeSource(){
  int i;
  for(i = 0;i < n;i++){
    d[i] = INF;
    pi[i] = NIL;
    color[i] = WHITE;
  }
  d[0] = 0;
}



void heavy(){
  int i,j,mincost,u1,v1;
  
  initializeSource();
  
  while(1){
    mincost = INF;
    for(i = 0;i < n;i++){
      if(color[i] != BLACK && d[i] < mincost){
    mincost = d[i];
    u1 = i;
      }
    }
  
    if(mincost == INF)break;
  
    color[u1] = BLACK;
  
    for(v1 = 0;v1 < k[u1];v1++){
      if(color[v[u1][v1]] != BLACK && (d[u1] + c[u1][v1]) < d[v[u1][v1]]){
    pi[v[u1][v1]] = u1;
    d[v[u1][v1]] = d[u1] + c[u1][v1];
      }
    }
  }
}

Measured memory_bytes: 680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int n;
vector<int> edge[100000];
map<P, int> mp;
queue<P> q;
int cnt = 0;

void dfs(int current, int last, int color){
  for(int x : edge[current]){
    if(x == last) continue;
    color = (color+1) % cnt;
    if(mp.count(P(current, x))) mp[P(current, x)] = color;
    else mp[P(x, current)] = color;
    dfs(x, current, color);
  }
}

int main(){
  cin >> n;
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
    mp[P(a, b)] = -1;
    q.push(P(a, b));
  }
  
  rep(i, n) cnt = max(cnt, int(edge[i].size()));
  
  dfs(0, -1, -1);
  cout << cnt << endl;
  rep(i, n-1){
    cout << mp[q.front()]+1 <<endl;
    q.pop();
  }
}



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

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

    string result = "";
    if (a > b) {
        for (size_t i = 0; i < a; i++)
        {
            result += to_string(b);
        }
        
    } else {
        for (size_t i = 0; i < b; i++)
        {
            result += to_string(a);
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long ans=1;
		for(int i=1;i<=n;i++)
		{
			ans=ans*i;
			ans%=1000000007;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35580
#include <map>
#include <iostream>

using namespace std;

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

    map<char, bool> mp;
    int n = (int) s.size();
    for (int i = 0; i < n; ++i) {
        mp[s[i]] = true;
    }

    if (mp['N'] != mp['S'] || mp['E'] != mp['W']) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;

}

Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}
ll n,m;
bool ok(ll a,ll b){
    return a>=0&&b>=0&&a<n&&b<m;
}
ll dx[8]={1,0,-1,0,1,-1,1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};

int main(){
    IOS;
    cin>>n>>m;
    vector <string> vec(n);
    fr(i,n) cin>>vec[i];
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            if(vec[i][j]=='.'){
                ll c=0;
                fr(k,8){
                    ll x=i+dx[k]; ll y=j+dy[k];
                    if(ok(x,y) && vec[x][y]=='#') c++;
                }
                vec[i][j]=c+'0';
            }
        }
    }
    for(auto x: vec){
        for(auto y : x){
            cout<<y;
        }
        cout<<endl;
    }


    return 0;
}


Measured memory_bytes: 3644
#!/usr/bin/env python3
# Submit as pypy2


from __future__ import print_function, division, unicode_literals

__metaclass__ = type

try:
    input = raw_input
    range = xrange
except NameError:
    pass


import sys


# Test code requires python3
# from hypothesis import given
# from hypothesis import strategies as st
#
#
# def debug(*args, **kwargs):
#     print(*args, *('{}={}'.format(k, v) for k, v in kwargs.items()),
#           sep='; ', file=sys.stderr)


import itertools as it
from collections import deque


def main():
    H, W = map(int, input().split())
    S = [[x == '#' for x in input()] for _ in range(H)]
    ans = 0
    for s in it.product(range(H), range(W)):
        if S[s[0]][s[1]]:
            continue
        D = {s: 0}
        Q = deque([s])
        while Q:
            u = Q.popleft()
            for dr, dc in [(0, +1), (-1, 0), (0, -1), (+1, 0)]:
                v = (u[0] + dr, u[1] + dc)
                if not (0 <= v[0] < H and 0 <= v[1] < W) or S[v[0]][v[1]] or v in D:
                    continue
                D[v] = D[u] + 1
                ans = max(ans, D[v])
                Q.append(v)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 33256
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18 

using namespace std;
int power(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n;
    cin>>n;
    int a=power(10,n,mod);
    int b=power(9,n,mod);
    int c=power(8,n,mod);
    b*=2;
    b%=mod;
    int ans=a-b;
    ans+=mod;
    ans%=mod;
    ans+=c;
    ans%=mod;
    cout<<ans;
}

Measured memory_bytes: 3660
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string S;
    int Q;
    cin >> S >> Q;
    deque<char> sq;
    for (char c : S)
        sq.push_back(c);

    bool reversed = false;
    while (Q--) {
        int t;
        cin >> t;
        if (t == 1) {
            reversed = !reversed;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (reversed ^ (f == 1))
                sq.push_front(c);
            else
                sq.push_back(c);
        }
    }
    
    while (!sq.empty()) {
        char c = reversed ? sq.back() : sq.front();
        if (!reversed)
            sq.pop_front();
        else
            sq.pop_back();
        cout << c;
    }
    cout << endl;
    return 0;
};

Measured memory_bytes: 976
l,r = map(int,input().split())
l2 = l % 2019
r2 = r % 2019
if r - l >= 2019:
    print(0)
    exit()
else:
    result = 2018
    for i in range(l,r):
        for j in range(i+1,r+1):
            result = min(result,(i*j)% 2019)
    print(result)

Measured memory_bytes: 3060
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let a: f64 = sc.read();
    let b: f64 = sc.read();
    let x: f64 = sc.read();
    let min = |a, b| if a < b { a } else { b };
    let ans = bis_f64(0., 90., 0.00000000001, |deg| {
        let t = deg.to_radians().tan();
        x <= a * min(a, b / t) * (b - min(b, a * t) / 2.)
    });

    format!("{:.10}\n", ans)
}
fn bis_f64<P>(t: f64, f: f64, allow: f64, eval: P) -> f64
where
    P: Fn(f64) -> bool,
{
    if (t - f).abs() < allow {
        return t;
    }
    let m = (t + f) / 2.;
    if eval(m) {
        bis_f64(m, f, allow, eval)
    } else {
        bis_f64(t, m, allow, eval)
    }
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read,Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <map>

using namespace std;

int main(){

  string s;
  cin >> s;
  
  map<char,int> base;
  base['A'] = 1;
  base['C'] = 1;
  base['G'] = 1;
  base['T'] = 1;
  
  int score = 0, res = 0;
  
  for(int i = 0; i < s.length();i++){
      if(base[s[i]]){
        score += 1;
      }else{
        if(res < score)
          res = score;
        score = 0;
      }
  }
  if(res < score)
    res = score;
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,d; cin>>n>>d;
	vvi v(n,vi(d));
	rep(i,0,n){
		rep(j,0,d){
			cin>>v[i][j];
		}
	}
	int ans=0;
	rep(i,0,n-1){
		rep(j,i+1,n){
			int l=0;
			rep(k,0,d){
				int p=(v[i][k]-v[j][k]);
				p*=p;
				l+=p;
			}
			//cout<<"l:"<<l<<endl;
			int y=sqrt(l);
			if(y*y==l) ans++;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
def main():



    n = int(input())
    bList = list(map(int,input().split()))
    ansList = []
    ansList.append(bList[0])

    for i in range(0,len(bList)-1):
        if bList[i] >= bList[i+1]:
            ansList.append(bList[i+1])
        else:
            ansList.append(bList[i])

    ansList.append(bList[-1])
    print(sum(ansList))




if __name__ == "__main__":
    main()



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

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

  string a[55][55], b[55][55];
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, (int)s.size()) a[i][j] = s[j];
  }
  rep(i, m) {
    string s;
    cin >> s;
    rep(j, (int)s.size()) b[i][j] = s[j];
  }

  bool match = false;
  rep(i, n-m+1) {
    rep(j, n-m+1) {
      match = true;
      rep(k, m) {
        rep(l, m) {
          if (a[i+k][j+l] != b[k][l]) {
            match = false;
            break;
          }
        }
        if (!match) break;
      }
      // remaining match == true at this point infers that some part of image a perfectly matched to image b
      if (match) break;
    }
    if (match) break;
  }

  cout << (match ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3780
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>

using std::endl;

#define ll long long int
#define FOR(a, s, n) for(int a = s; a < n; ++a)
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define MOD 1000000007
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std
#define asn ans

ll Data[123456];

ll SX, SY, EX, EY;

int main()
{

	IN >> SX >> SY >> EX >> EY;

	LEP(a, EX - SX) OUT << "R";
	LEP(a, EY - SY) OUT << "U";
	LEP(a, EX - SX) OUT << "L";
	LEP(a, EY - SY) OUT << "D";

	OUT << "D"; LEP(a, EX - SX + 1) OUT << "R";
	LEP(a, EY - SY + 1) OUT << "U"; OUT << "L";
	OUT << "U"; LEP(a, EX - SX + 1) OUT << "L";
	LEP(a, EY - SY + 1) OUT << "D"; OUT << "R";

	OUT << endl;

	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

/*

確率漸化式
確率DP 期待値DP
小数 近似値 絶対誤差 format

個数の分布だけを考えればよい
3個の皿がi個、2個の皿がj個、1個の皿がk個（、0個の皿がl個）であるときの残り回数の期待値を

x[i][j][k]

とすると

x[i][j][k] = 1
	+	(i / n) * x[i - 1][j + 1][k]
	+ (j / n) * x[i][j - 1][k + 1]
	+ (k / n) * x[i][j][k - 1]
	+ (l / n) * x[i][j][k]

だから

(1 - l / n) x[i][j][k] = n / n
	+	(i / n) * x[i - 1][j + 1][k]
	+ (j / n) * x[i][j - 1][k + 1]
	+ (k / n) * x[i][j][k - 1]

(i + j + k) x[i][j][k] = n + i * x[i - 1][j + 1][k] + j * x[i][j - 1][k + 1] + k * x[i][j][k - 1]

i、j、kの降順でDPでもできそうだが、メモ化再帰が書きやすそう

*/

void main(){
	int n = read.to!int;
	
	int x, y, z;
	foreach(i; 0 .. n){
		int a = read.to!int;
		if(a == 3) x += 1;
		else if(a == 2) y += 1;
		else z += 1;
	}
	
	real[int] memo;
	real solve(int i, int j, int k){
		if(i + j + k == 0) return 0.0;
		
		int key = i * (n * n + 10) + j * (n + 10) + k;
		if(key !in memo){
			real res = n;
			if(i > 0) res += i * solve(i - 1, j + 1, k);
			if(j > 0) res += j * solve(i, j - 1, k + 1);
			if(k > 0) res += k * solve(i, j, k - 1);
			memo[key] = res / (i + j + k);
		}
		
		return memo[key];
		
	}
	
	real ans = solve(x, y, z);
	
	format("%12.12f", ans).writeln;
	
}


Measured memory_bytes: 328572
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P =pair<int,int>;
 
 int main(){
     int n=5;
     vector<int> x(n);
     rep(i,n)cin>>x[i];
     rep(i,n){
         if(x[i]==0){
             cout<<i+1<<endl;
         }
     }
 }

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


int main(){
//A
/*
string s;
cin>>s;
if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
*/
//B
/*
ll X;cin>>X;
ll x;
x=X%500;
//cout<<X/500*1000<<endl;
//cout<<x<<endl;
cout<<X/500*1000+x/5*5<<endl;
*/
//C
int k,n;
cin>>k>>n;
vector<int> a(n);
rep(i,0,n) cin>>a[i];
sort(a.begin(),a.end());
vector<int> b(n);
rep(i,0,n-1) b[i]=a[i+1]-a[i];
b[n-1]=a[0]+k-a[n-1];
sort(b.begin(),b.end());
cout<<k-b[n-1]<<endl;//外周ー最大間隔 
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 10007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> v(n, 0), c(n, 0);
    for(int i = 0; i < n; i++) cin >> v[i];
    for(int i = 0; i < n; i++) cin >> c[i];
    vector<int> vec(n, 0);
    for(int i = 0; i < n; i++) vec[i] = v[i] - c[i];
    sort(vec.begin(), vec.end());
    
    int total = 0;
    
    while(!vec.empty() && vec.back() > 0)
    {
        total += vec.back();
        vec.pop_back();
    }
    cout << total << endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
import os
# import math
# input = sys.stdin.readline

def int_array():
    return list(map(int, input().strip().split()))


def str_array():
    return input().strip().split()

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b);

def take_input():
	if os.environ.get("check"):
		sys.stdin = open('input.txt', 'r') 
		sys.stdout = open('output.txt', 'w')
		
take_input()
######################### TEMPLATE ENDS HERE #################################

a,b,c = int_array()
k = int(input())

# conditions
#c>b>a

count = 0

for _ in range(k):
    if a>=b:
        b*=2
    elif b>=c:
        c*=2
    if a<b<c:
        break

if a<b<c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61828
###==================================================
### import
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInLH(): return list(map(int, input().split()))
### setting
sys.setrecursionlimit(10 ** 6)
###---------------------------------------------------

N, M, K = iInM()
A = iInLH()
B = iInLH()

id_a = -1
t_pre = 0
for i in range(N):
    if t_pre + A[i] <= K: ## read
        id_a += 1
        t_pre += A[i]
    else:
        break

id_b = -1
for j in range(M):
    if t_pre + B[j] <= K: ## read
        id_b += 1
        t_pre += B[j]
    else:
        break

ans = (id_a + 1) + (id_b + 1)
if id_a < 0:
    print(ans)
    exit()

while (id_a >= 0):
    t_pre -= A[id_a]
    id_a -= 1
    for j in range(id_b+1, M):
        if t_pre + B[j] <= K:
            id_b += 1
            t_pre += B[j]
        else:
            break
    if ans < (id_a + 1) + (id_b + 1):
        ans = (id_a + 1) + (id_b + 1)
    #print(id_a, id_b)


print(ans)






Measured memory_bytes: 108464
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int min = Integer.MAX_VALUE;
        int minIdx = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (min > x) {
                min = x;
                minIdx = i + 1;
            }
        }
        System.out.println(minIdx);
    }
}


Measured memory_bytes: 69272
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <set>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x, n;
    cin, x, n;
    set<int> s;
    REP(i, 0, n) {
        int a;
        cin, a;
        s.insert(a);
    }

    int ans = 1 << 30;
    REP(i, -100, 200) {
        if (!s.count(i)) {
            if (abs(ans - x) > abs(x - i)) {
                ans = i;
            }
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> a(N);
    for (auto& e : a) std::cin >> e;

    int M;
    std::cin >> M;
    std::vector<int> b(M);
    for (auto& e : b) std::cin >> e;

    std::vector<int> ans;
    std::set_intersection(a.begin(), a.end(),
                          b.begin(), b.end(),
                          std::back_inserter(ans));

    for (auto& e : ans) std::cout << e << std::endl;
    return 0;
}


Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rdv(type, v, n) vector<type> v(n); rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) vector<vector<type>>(h, vector<type>(w)) v; rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
typedef long long ll;
void solve();
signed main() {ios::sync_with_stdio(false); cin.tie(0);
  cout << fixed; cout.precision(12); solve(); return 0;}
template<typename T> void prv(vector<T> v) {rep(__ii, 0, sz(v)) {if (__ii) cout << ' '; cout << v[__ii];} cout << '\n';} 
template<typename T> void prm(vector<vector<T>> v) {rep(__ii, 0, sz(v)) {rep(__jj, 0, v[__ii].size()) {if (__jj) cout << ' '; cout << v[__ii][__jj];} cout << '\n';}}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void pr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void pr(const Head& head, const Tail&... tail) {cout << head << ' '; pr(tail...);}
template<typename... T> void err(const T&... cod) {pr(cod...); exit(0);}

void solve() {
  rd(int, l, r);
  if (r - l > 2040) r = l + 2021;
  int ans = 2021;
  const int mod = 2019;
  rep(i, l, r + 1) rep(j, i + 1, r + 1) ans = min(ans, ((i % mod) * (j % mod)) % mod);
  pr(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

const int M = 100005;

int main(void) {

    int n; cin >> n;
    vector<ll> cnt(M);
    ll sum = 0;
    rep(i, n){
        int a;
        cin >> a;
        cnt[a]++;
        sum += a;
    }
    // cout << sum << endl;

    int q; cin >> q;
    rep(i, q) {
        int b, c;
        cin >> b >> c;
        cnt[c] += cnt[b];
        // cout << cnt[b] << cnt[c] << endl;
        sum -= b * cnt[b];
        sum += c * cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }


    return 0;
}

Measured memory_bytes: 4044
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        var N = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
        a.Sort();
        var ans = a[0];
        
        for(var i = 1; i < N;i++){
            ans = (ans + a[i]) / 2;
        }
        Console.WriteLine(ans);
    }
}


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

const int N = 3e2;

int n;
long long g[N+10][N+10],ans;
bool bo[N+10][N+10];

int main(){
    //freopen("F:\\rush.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    for (int i = 1;i <= n;i++)
        for (int j = 1;j <= n;j++){
            cin >> g[i][j];
            if (j > i) ans+=g[i][j];
        }

    for (int i = 1;i <= n;i++)
        for (int j = 1;j <= n;j++)
            if (g[i][j]!=g[j][i])
                return cout <<-1<<endl,0;

    for (int k = 1;k <= n;k++)
        for (int i = 1;i <= n;i++)
            if (k!=i)
                for (int j = 1;j <= n;j++)
                    if (k!=j && i!=j)
                        if (g[i][j]>g[i][k]+g[k][j])
                            return cout<<-1<<endl,0;
                        else
                            if (g[i][j]==g[i][k]+g[k][j] && !bo[i][j]){
                                    ans -= g[i][j];
                                    bo[i][j] = true;
                                    bo[j][i] = true;
                            }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
import itertools
import bisect

N = int(input())
Llist  =[int(i) for i in input().split()]
Llist.sort()

#print(Llist)


ans=0
for i in range(len(Llist)):
    for j in range(i+1,len(Llist)):
        a = Llist[i]
        b = Llist[j]
        index = bisect.bisect_right(Llist,b-a)
        #print("i"+str(i)+"  a"+str(a)+"  j"+str(j)+"  b"+str(b)+"  index"+str(index))
        if i>index:
            ans+=i-index

print(ans)

Measured memory_bytes: 3188
A, B, C, X, Y = gets.strip.split(/ /).collect{|n| n.to_i}

sum = 0
x = X
y = Y

if A + B >= 2 * C
	n = [x, y].min
	x -= n
	y -= n
	sum += C * 2 * n
end
if x > 0 && A >= C * 2
	sum += C * 2 * x
	y -= x
	x = 0
end
if y > 0 && B >= C * 2
	sum += C * 2 * y
	x -= y
	y = 0
end
if x > 0
	sum += A * x
	x = 0
end
if y > 0
	sum += B * y
	y = 0
end
puts sum



Measured memory_bytes: 1788
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vector<double> p(n);
  rep(i,n)cin>>p[i];
  double dp[3010][3010];
  rep(i,3010){
    rep(j,3010)dp[i][j]=0;
  }
  dp[0][0]=1;
  dp[1][0]=1-p[0];
  dp[1][1]=p[0];
  for(ll i=1;i<=n;i++){
    if(i==1)continue;
    rep(j,i+1){
      if(j>=1)dp[i][j]+=dp[i-1][j-1]*p[i-1];
      dp[i][j]+=dp[i-1][j]*(1-p[i-1]);
    }
  }
  double sum=0;
  rep(i,n+1){
    if(i>n-i)sum+=dp[n][i];
  }
  //rep(i,n+1){
    //rep(j,n+1)cout<<dp[i][j]<<" ";
    //cout<<endl;
  //}
  cout<<fixed<<setprecision(10)<<sum<<endl;
}

Measured memory_bytes: 71168
#include<cstdio>
char bom[10][10];
int dy[]={-1,-2,-3,0,0,0,1,2,3,0,0,0},dx[]={0,0,0,1,2,3,0,0,0,-1,-2,-3};
void dfs(int y,int x){
    if(y<0||x<0||y>8||x>8)return;
    if(bom[y][x]==0)return;
    if(bom[y][x]=='1'){
        bom[y][x]='0';
        for(int i=0;i<12;i++){
                dfs(y+dy[i],x+dx[i]);
        }
    }
}
int main(){
    int a,b,num;
    scanf("%d",&num);
        for(int kazu=0;kazu<num;kazu++){
        for(int i=0;i<8;i++){
                scanf("%s",bom[i]);
        }
        scanf("%d %d",&a,&b);
        dfs(b-1,a-1);
        printf("Data %d:\n",kazu+1);
        for(int i=0;i<8;i++){
                printf("%s\n",bom[i]);
        }
        }
}

Measured memory_bytes: 1036
N, M = map(int, input().split())
D = [[] for i in range(N)]

for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) #市ごとにリストに入れる．この時，元の順番をタプルの1番目の要素として入れておく

ans = [None]*M

for i, d in enumerate(D): #enumerateは要素の中身とインデックス番号を持ってこれる．print(i, d)で確認
  d.sort()
  for k, (y, j) in enumerate(d): #こちらも同様．(y, j)となっているため，yには年数が，jには元の順番の情報が入る
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) #ans[j]に12桁の認識番号を挿入

print(*ans, sep = '\n') 

Measured memory_bytes: 37480