akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #define ll long long
    #define ull unsigned long long

    using namespace std;

    void rundp(int n, string &s, vector<int> &dp, int b, int c) {
        dp[b] = 1;
            for(int i = b + 1; i <= c; i ++) {
                if(s[i] == '#')
                    continue;
                if(s[i - 1] == '.')
                    dp[i] = dp[i - 1];
                if(s[i - 2] == '.')
                    dp[i] += dp[i - 2];

                if(dp[i] > 4)
                    dp[i] = 2;
            }
    }

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

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

        int n, a, b, c, d;
        string s;
        cin >> n >> a >> b >> c >> d >> s;
        s = " " + s;

        if(c < d) {
            swap(a, b);
            swap(c, d);
        }

        if(a < b) {
            vector<int> dp(n + 1, 0);
            rundp(n, s, dp, b, d);
            if(dp[d] < 2 && !(d < n && s[d + 1] == '.' && s[d - 1] == '.' && dp[d - 1] > 0) && !(b < n && s[b + 1] == '.' && s[b - 1] == '.')) {
                cout << "No";
                return 0;
            }

            vector<int> dp2(n + 1, 0);
            rundp(n, s, dp2, a, c);
            if(dp2[c] < 1) {
                cout << "No";
                return 0;
            }

            cout << "Yes";
        } else {
            vector<int> dp(n + 1, 0);
            rundp(n, s, dp, a, c);
            if(dp[c] < 1) {
                cout << "No";
                return 0;
            }

            vector<int> dp2(n + 1, 0);
            rundp(n, s, dp2, b, d);
            if(dp2[d] < 1) {
                cout << "No";
                return 0;
            }

            cout << "Yes";
        }

        return 0;
    }


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

const int INF = 1e15;

int N, x[1005], y[1005];
int dp[1005][1005];

void solve(){
  
  if( N == 1 ){
    cout<<0<<endl;
    return;
  }
  
  for(int i=0;i<=N;i++)
    for(int j=0;j<=N;j++) dp[i][j] = INF;
  
  for(int len=0;len<N;len++){
    
    for(int l=0;l<N-len;l++){
      
      int r = l + len;
      
      if( l == r ){
	
	dp[l][r] = 0;
	
      }else{
	
	for(int m=l;m<r;m++){
	  
	  int cost = x[m+1] - x[l] + y[m] - y[r];
	  
	  dp[l][r] = min( dp[l][r], dp[l][m] + dp[m+1][r] + cost );
	  
	}
	
      }
      
    }
    
  }
  
  cout<<dp[0][N-1]<<endl;
  
}

signed main(){
  
  cin>>N;
  
  for(int i=0;i<N;i++) cin>>x[i]>>y[i];
  
  solve();  
  
  return 0;
}



Measured memory_bytes: 10884
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  string s;
  sc.scan(s);

  int res = 0;

  foreach (i; 0 .. s.length) {
    int tmp;
    foreach (j; i .. s.length) {
      if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T')
        tmp++;
      else
        break;
    }
    if (res < tmp)
      res = tmp;
  }

  writeln(res);
}


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

int main(){
 string a;
  cin >> a;
  for(int i = 1; i < a.size(); ++i){
  	if(a[i-1] == a[i]){
		cout << i << " " << i+1;
      return 0;
  	}
  }
  for(int i = 2; i < a.size(); ++i){
  	if(a[i-2] == a[i]){
		cout << i-1 << " " << i+1;
      return 0;
  	}
  }
  cout << "-1 -1";
  return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>

using namespace std;

struct Node{
  int key;
  Node *right,*left,*parent;
};

Node *root,*NIL;

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;
  
  z = (Node*)malloc(sizeof(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;
    }
  }
}

Node * find(Node *u,int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key){
      u = u->left;
    }else{
      u = u->right;
    }
  }
  return u;
}

void inorder(Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,x;
  string com;
  
  scanf("%d",&n);
  
  for(int i=0;i<n;++i){
    cin>>com;
    if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com == "find"){
      scanf("%d",&x);
      Node *t = find(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }
  }
  
  return 0;
}



Measured memory_bytes: 22012
#include <bits/stdc++.h>
#define MAX 100005
#define read (freopen("input.txt", "r", stdin));
#define write (freopen("output.txt", "w", stdout));
using namespace std;

typedef long long ll;

int counter[MAX];
map<int, int> mp;
set<int> s;
int n, m, arr[MAX];

int main()
{
    //read; write;
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int b, c;

    cin>>n>>m;

    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }

    sort(arr, arr + n);

    int idx = 1;
    for(int i = 0; i < m; i++){
        cin>>b>>c;
        if(mp[c] == 0){
            mp[c] = idx++;
        }
        counter[mp[c]] += b;
        s.insert(c);
    }

    int u;
    for(int i = 0; i < n; i++){
        if(!s.empty())
            u = *s.rbegin();
        if(!s.empty() && arr[i] < u){
            arr[i] = u;
            counter[mp[u]]--;
            if(counter[mp[u]] <= 0){
                s.erase(u);
            }
        }
    }

    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += (ll) arr[i];
    }
    cout<<sum<<endl;


    return 0;
}

Measured memory_bytes: 10368
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


def main():
    N, Q = map(int, input().split())

    uni = UnionFind(N)
    for i in range(Q):
        t, u, v = map(int, input().split())
        if t == 0:
            uni.unite(u, v)
        else:
            if uni.same(u, v):
                print(1)
            else:
                print(0)


main()


Measured memory_bytes: 18172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

ll mpow(ll x, ll n){ //x^n(mod mo) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mo;
        x = x*x % mo;
        n = n >> 1;
    }
    return ans;
}
 
const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<mint> dp(N+1);
    rep(i,N){
        cin >> A[i];
    }
    mint ans = 1;
    dp[0] = 3;
    rep(i,N){
        ans *= dp[A[i]];
        dp[A[i]] -= 1;
        dp[A[i]+1] += 1;
    }
    cout << ans << endl;
}

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

int main( void ) {
    ios::sync_with_stdio( false );
    int n, m;
    string s;
    cin >> n >> s >> m;
    char ch = s[ m - 1 ];
    for( int i = 0; i < s.length(); ++i ) if( s[ i ] != ch ) s[ i ] = '*';
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[]
xy=[[] for i in range(n)]
ans=0 #最大値が答え

for i in range(n):
    aa=int(input())
    a.append(aa)
    for j in range(aa):
        xx,yy=map(int,input().split())
        xy[i].append([xx-1,yy])
#print(xy)

for i in range(pow(2,n)): 
    who=[0]*n #最初はみんな嘘つき
    count=0
    syoujiki=0
    for j in range(n-1,-1,-1): #誰が正直か
        if (i>>j)&1:
            who[count]=1
            syoujiki+=1
        count+=1
    #print(i)
    #print(who)
    check=0
    for j in range(n):
        if who[j]==0: #嘘つきなら無視
            continue
        num=a[j]#正直者jの情報量
        for k in range(num):
            if who[xy[j][k][0]]!=xy[j][k][1]:
                check=1
                break
        if check==1:
            break
    if check==0 and syoujiki>ans:
        ans=syoujiki
print(ans)
#print(xy)

Measured memory_bytes: 3064
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int k = sc.nextInt();
      	if(k % 2 == 0){
        	System.out.println(k*k/4);
        }else{
        	System.out.println((k/2)*((k/2)+1));
        }
    }
}

Measured memory_bytes: 35828
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define all(a) a.begin(), a.end()
#define sz(a) a.size()
#define pb push_back
using namespace std;

const ll mod = 1e9+7;

ll n, d[10000001], ans=0;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("A.txt", "r", stdin);
    #endif
    cin >> n;
    for(int i=1; i<=n; i++){
        ll x = n/i;
        ans += x*(i+n-n%i)/2;
    }
    cout << ans;
}


Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long LL;
char str[200005];
int main(){
	int n;
	cin >> n >> str;
	int fsr = n-1;
	int fsw = 0;
	int cnt = 0;
	while(fsr > fsw&&fsr >=0 && fsw < n){
		while(fsr > 0 && str[fsr]!='R') fsr--;
		while(fsw < n && str[fsw]!='W') fsw++;
		//cout << fsr << ' ' << fsw << endl; 
		if(fsr > fsw&&fsr >=0 && fsw < n){
			 swap(str[fsr],str[fsw]);
			 cnt++;
		}
	}
	cout << cnt;
} 

Measured memory_bytes: 3384
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


		 int dec = sc.nextInt();
 	 	 int n = sc.nextInt();
 	 	String base36 = Integer.toString(dec, n);
		System.out.println(base36.length());





	}
}


Measured memory_bytes: 23764
#include <stdlib.h>
#include <stdio.h>
int cmpfunc(const void* a,const void * b){

    return (*(int*)a-*(int*)b);
}
int main(){
    int n,i,j;
    int count =0;
    int k;
    int sum=0;
    scanf("%d",&n);
    scanf("%d",&k);
    if(k > 1000 || n > 1000)return 0;
    if(n < 0 || k < 0)return 0;
    int buf[n];
    for(i=0;i < n;++i){
        scanf("%d",&buf[i]);     
    
    }
        if(n < k){
            return 0;
        }
        qsort(buf,n,sizeof(int),cmpfunc);
        for(j=0;j<k;++j){
            sum +=buf[j];
    }
    printf("%d",sum);


    return 0;
}


Measured memory_bytes: 1724
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,X,Y,Z;

signed main(){
	cin>>N;
	for(int x=1;x<=3500;x++){
		for(int y=1;y<=3500;y++){
			int s=N*x*y;
			int t=4*x*y-N*x-N*y;
			if(t==0)continue;
			if(s%t==0&&s/t>0){
				cout<<x<<" "<<y<<" "<<s/t<<endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public struct Exam
	{
		public int Middle;
		public int End;
		public int Retry;
	}

	public class Question
	{
		public void Exec()
		{
			Exam exam = new Exam();
			List<string> results = new List<string>();
			Func<Exam, bool> checker = (e) => e.Middle == -1 && e.End == -1 && e.Retry == -1;
			while (checker.Invoke(exam) == false) {
				int[] mfr = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
				exam.Middle = mfr[0];
				exam.End = mfr[1];
				exam.Retry = mfr[2];
				if (checker.Invoke(exam)) {
					break;
				}

				string result = "";
				if (exam.Middle == -1 || exam.End == -1) {
					result = "F";
				} else if (exam.Middle + exam.End >= 80) {
					result = "A";
				} else if (exam.Middle + exam.End >= 65) {
					result = "B";
				} else if (exam.Middle + exam.End >= 50) {
					result = "C";
				} else if (exam.Middle + exam.End >= 30) {
					if (exam.Retry >= 50) {
						result = "C";
					} else {
						result = "D";
					}
				} else {
					result = "F";
				}

				results.Add(result);
			}

			foreach (var item in results) {
				Console.WriteLine($"{item}");
			}

			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 18376
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;
LL solve(LL L, LL R, auto &data, auto &dp, LL idx) {
    if (~dp[L][R]) return dp[L][R];
    if (idx == data.size()) return 0;
    dp[L][R] = max(
        solve(L + 1, R, data, dp, idx + 1) + abs(data[idx].S - L) * data[idx].F,
        solve(L, R - 1, data, dp, idx + 1) + abs(data[idx].S - R + 1) * data[idx].F
    );
    return dp[L][R];
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    LL n; cin >> n;
    vector<pii> data;
    for (LL i = 0 ; i < n ; i++) {
        LL v; cin >> v;
        data.push_back({v, i});
    }
    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());
    vector<vector<LL> > dp(n + 1, vector<LL>(n + 1, -1));
    cout << solve(0, n, data, dp, 0) << '\n';
}


Measured memory_bytes: 34880
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
#define double long double
vector<pair<char, pair<double, double>>> pts;
double f(double move){
    double xMax, xMin, yMax, yMin;
    xMax = yMax = INT_MIN;
    xMin = yMin = INT_MAX;
    for(auto p: pts){
        if(p.first == 'U')p.second.second += move;
        else if(p.first == 'D')p.second.second -= move;
        else if(p.first == 'L')p.second.first -= move;
        else if(p.first == 'R')p.second.first += move;
        xMax = max(xMax, p.second.first);
        xMin = min(xMin, p.second.first);
        yMax = max(yMax, p.second.second);
        yMin = min(yMin, p.second.second);
    }
//    cout << move << " " << (yMax - yMin)*(xMax - xMin) <<endl;
    return (yMax - yMin)*(xMax - xMin);
}
double ternary_search(double l, double r) {
    int iter = 0;
    double eps = 1e-14;              //set the error limit here
    while (r - l > eps) {
        double m1 = l + (r - l) / 3;
        double m2 = r - (r - l) / 3;
        double f1 = f(m1);      //evaluates the function at m1
        double f2 = f(m2);      //evaluates the function at m2
        if (f1 > f2)
            l = m1;
        else
            r = m2;
        iter++;
//        debug(iter);
        if(iter == 200)break;
    }
    return min(f(l), f(r));                    //return the maximum of f(x) in [l, r]
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;cin >> n;
    pts.resize(n);
    FOR(i, n){
        cin >> pts[i].second.first >> pts[i].second.second >> pts[i].first;
    }
    double ans = ternary_search(0, 1e9);
    printf("%0.20Lf\n", ans);
//    cout << setprecision(20) << ternary_search(0, 1e9) <<endl;
}




Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int w,h;
int c[100][100];
bool notsearched[100][100];
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,1,-1};
int ans;

bool inrange(int x, int y){
  if(x<0||y<0||x>=h||y>=w){ 
	//cout << "false" <<endl;
	return false;
  }else{ 
	//cout << "true" << endl;
	return true;
  }
}

void search(int x, int y){

  if((notsearched[x][y])&&(c[x][y] == 1)&&(inrange(x,y))){
	notsearched[x][y]=false;

	REP(i,8) search(x+dx[i],y+dy[i]);
  }
}


int main(){
  while(1){

	REP(i,100){
	  REP(j,100){
		notsearched[i][j]=true;
	  }
	}

	cin >> w >> h;
	if (w==0&&h==0) break;
	ans=0;
	REP(i,h){
	  REP(j,w){
		cin >> c[i][j];

	  }
	}

	REP(i,h){
	  REP(j,w){
		if((notsearched[i][j])&&(c[i][j] == 1)&&(inrange(i,j))) ans++; 
		search(i,j);
	  }
	}
	cout << ans << endl;
  }
 
}

Measured memory_bytes: 1260
import Text.Printf

main = interact main'
main' = printf "%.10f" . f . read

f :: Integer -> Double
f x = a / b
	where 
    	a = fromIntegral $ length $ filter isOdd [1..x]
    	b = fromIntegral $ length $ [1..x]
        isOdd x = x `mod` 2 == 1

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl P(N);
    rep(i, N){
        cin >> P[i];
        P[i]--;
    }

    ll ans = 0;
    rep(i,N){
        if(P[i]==i){
            if(i==0){
                swap(P[i], P[i + 1]);
                ans++;
            }
            else if(i==N-1){
                swap(P[i - 1], P[i]);
                ans++;
            }
            else{
                swap(P[i], P[i + 1]);
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll k,n;
  cin >> k >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = k;
  rep(i,n-1) ans = min(ans, k - (a[i+1] - a[i]));
  ans = min(ans, k - (k+a[0]-a[n-1]));
  cout << ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

pll solve(ll lhs, ll rhs) {
  if(lhs%2 == 0 || rhs%2 == 0) {
    ll area = (lhs*rhs)/2;
    return pll(area, area);
  }
  ll best = max((lhs/2)*rhs, (rhs/2)*lhs);
  return pll(best, lhs*rhs-best);
}

int main() {
  ll a, b;
  scanf("%lld%lld", &a, &b);
  ll ret = (ll)1e18;
  for(int i = 1; i < a; i++) {
    ll odd = i * b;
    pll other = solve((a-i), b);
    ll rhs = max(odd, other.second);
    ll lhs = min(odd, other.first);
    ret = min(ret, rhs - lhs);
  }
  for(int i = 1; i < b; i++) {
    ll odd = a * i;
    pll other = solve(a, (b-i));
    ll rhs = max(odd, other.second);
    ll lhs = min(odd, other.first);
    ret = min(ret, rhs - lhs);
  }
  printf("%lld\n", ret);
}


Measured memory_bytes: 256
# Can't Wait for Holiday

S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

Measured memory_bytes: 8996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vl;
typedef vector<pii> vpii; typedef vector<pll> vpll;
#define FOR(n) for(int i=0;i<n;++i)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll gcd(ll a, ll b) { return a % b ? gcd(b, a % b) : b; }
const ll inf = 0x3f3f3f3f;
map<ll, int>ha;
ll cnt=-1, ans;
vector<ll>sum(1, 0);
signed main() {
	ll n, x, m;
	cin >> n >> x >> m;
	ha[x] = 1;
	sum.push_back(x);
	ll i;
	for (i = 2; i <= n; ++i) {
		x *= x;
		x %= m;
		sum.push_back(sum[i - 1] + x);
		if (ha[x]) {
			cnt = i - ha[x];
			break;
		}
		ha[x] = i;
	}
	if (cnt < 0) {
		cout << sum[i - 1] << endl;
		return 0;
	}
	ans = sum[i];
	ll tempsum = sum[i] - sum[ha[x]];
	ll time = (n - i) / cnt;
	ans += time * tempsum;
	i += cnt * time;
	for (i++; i <= n; ++i) {
		x *= x;
		x %= m;
		ans += x;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6708
#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>;

vector<int64_t> make_divisors(int64_t n) {
    vector<int64_t> divisors;
    for (int64_t i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            divisors.push_back(i);
            if(i!=1 && i*i!=n)
				divisors.push_back(n/i);
        }
    }
    sort(divisors.begin(), divisors.end());
    if (n != 1) divisors.push_back(n);
    return divisors;
}

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> divs = make_divisors(n);
    int s = divs.size();
    int m = (s + 1) / 2;
    int64_t ans = n+1;
    rep(i,m) {
        int64_t x = divs[i];
        int64_t y = divs[s-i-1];
        ans = min(x+y-2, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){

  int a, b; cin >> a >> b;
  cout << max(0, a - 2 * b) << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    _ = int(input())
    p = [int(s) for s in input().split()]
    print(solve(p))

def solve(p):
    cnt = 0
    for a, b, c in zip(p, p[1:], p[2:]):
        if (a < b < c) or (c < b < a):
            cnt += 1
    return cnt

main()


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

int main() {
    int n;
    cin>>n;
    long long int ans=0;
    for(int i=1;i<=n;i++)
    if(i%3==0 || i%5==0)
    continue;
    else ans+=i;
    cout<<ans;
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  string s,t;
  cin>>n>>m>>s>>t;
  Int ans=0;
  auto dp=make_v<Int>(2,n+1,m+1);
  fill_v(dp,-1);
  
  function<Int(Int,Int,Int)> dfs=[&](Int f,Int a,Int b){
    Int &res=dp[f][a][b];
    if(~res) return res;
    res=0;
    
    if(a<n&&s[a]=="IO"[f]) chmax(res,1+dfs(!f,a+1,b));
    if(b<m&&t[b]=="IO"[f]) chmax(res,1+dfs(!f,a,b+1));
    
    chmax(ans,(res&1)?res:res-1);
    return res;
  };

  for(Int i=0;i<=n;i++)
    for(Int j=0;j<=m;j++)
      dfs(0,i,j);
  
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 97404
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N; cin >> N;
  vector<int64_t> A(N); for (auto &a : A) cin >> a;
  auto ans = 0LL;
  for (int k = 0; k < 60; ++k)
    {auto z = 0LL; for (auto a : A) if (!(a >> k & 1)) ++z;
    auto s = z * (N - z);
    if (s) for (int i = 0; i < k; ++i) s = s * 2 % 1000000007;
    ans = (ans + s) % 1000000007;}
  cout << ans << endl;}

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

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

    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <sstream>
#include <array>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stack>

template <typename T, typename U>
inline std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <typename T, typename U>
inline std::istream& operator>>(std::istream& os, std::pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    if (v.empty()) {
        return os;
    }
    if (v.begin() != v.end()) {
        os << v.front();
    }
    for (auto it = ++v.begin(); it != v.end(); ++it) {
        os << ' ' << *it;
    }
    return os;
}
template <typename T>
inline std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& i : v) {
        is >> i;
    }
    return is;
}

void Solve(std::istream& is, std::ostream& os) {
    const int MAX_N = 51;
    int64_t dp[MAX_N][MAX_N * MAX_N] = {};
    dp[0][0] = 1;

    int input_size, average;
    is >> input_size >> average;
    std::vector<int> input(input_size);
    is >> input;

    for (int elem : input) {
        for (int i = input_size; i > 0; --i) {
            for (int j = elem; j < MAX_N * MAX_N; ++j) {
                dp[i][j] += dp[i - 1][j - elem];
            }
        }
    }

    int64_t answer = 0;
    for (int i = 1; i <= input_size; ++i) {
        answer += dp[i][average * i];
    }
    os << answer << '\n';
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Solve(std::cin, std::cout);
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>

using namespace std;

int main(){

	int S, h , m, s;

	cin >> S;

	h = S / 3600;
	m = (S % 3600) / 60;
	s = (S % 3600) % 60;

	cout << h << ":" << m << ":" << s << "\n";
}

Measured memory_bytes: 1164
n = gets.to_i
as = gets.chomp.split.map(&:to_i).sort
max_cnt = 0
dp = Array.new(as[-1]+2,0)
as.each do |a|
  dp[a] += 1
end
as[0].upto(as[-1]) do |i|
  cnt = dp[i-1] + dp[i] + dp[i+1]
  max_cnt = cnt if max_cnt < cnt
end
puts max_cnt


Measured memory_bytes: 10292
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;

    int[,,] dp;
    string S;
    void solve()
    {
        S = ReadLine();
        int K = cin.nextint;
        dp = new int[S.Length, S.Length, K + 1];//少なくとも1以上になる
        WriteLine(calc(0, S.Length - 1, K));

    }
    int calc(int l, int r, int k)
    {
        if (dp[l, r, k] > 0) return dp[l, r, k];

        int res = 0;
        if (l == r) return 1;
        else if (l + 1 == r)
        {
            if (S[l] == S[r] || k > 0) res = 2;
            else res = 1;
        }
        else
        {
            res = Math.Max(res, calc(l + 1, r, k));
            res = Math.Max(res, calc(l, r - 1, k));

            if (S[l] == S[r]) res = Math.Max(res, calc(l + 1, r - 1, k) + 2);
            if (k > 0) res = Math.Max(res, calc(l + 1, r - 1, k - 1) + 2);
        }

        return dp[l, r, k] = res;
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

int we[110], v[110], dp[100100];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, w;
    cin >> n >> w;
    fill(dp + 1, dp + 100010, 2e9);
    for (int i = 1; i <= n; ++i) {
        cin >> we[i] >> v[i];
        for (int j = 100000; j >= 1; --j) {
            if (j - v[i] >= 0) {
                dp[j] = min(0LL + dp[j], 0LL + dp[j - v[i]] + we[i]);
               // cout << j << " " << dp[j] << '\n';
            }
        }
    }
    for (int i = 100000; i >= 1; --i) {
        if (dp[i] <= w) {
            cout << i;
            return 0;
        }
    }
}

Measured memory_bytes: 4044
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = sc.nextInt();
        int o = 0, e = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if(x % 2 == 0){
                e++;
            }else{
                o++;
            }
        }
        BigDecimal ans = new BigDecimal(0);
        for (int i = p; i <= o; i+=2) {
            for (int j = 0; j <= e; j++) {
                BigDecimal t = new BigDecimal(1).multiply(comb(o, i)).multiply(comb(e, j));
                ans = ans.add(t);
            }
        }
        System.out.println(ans);
        sc.close();

    }

    private static BigDecimal comb(int n, int r){
        BigDecimal ret = new BigDecimal(1);
        for (int i = 0; i < Math.min(r, n-r); i++) {
            ret = ret.multiply(new BigDecimal(n-i));
        }
        for (int i = 1; i <= Math.min(r, n-r); i++) {
            ret = ret.divide(new BigDecimal(i));
        }
        return ret;
    }

}



Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;

#define what_is(x) cerr << #x << " is " << x << endl;

const ll LMAX = (1LL<<61);
const int IMAX = (1<<29);
const int BIG = 104206970;
const int PRIME = 104206969;

const int N = 9;
const ll MOD = 1e9+7;

int n, cat[N];

void categorize (int x) {
	if (x/400 > 7)
		cat[8]++;
	else
		cat[x/400]++;
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// cout.precision(9); cout << fixed;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x; cin >> x; categorize(x);
	}

	int min_ans = 0, z = 0;
	for (int i = 0; i < N-1; i++) {
		if (cat[i] == 0)
			z++;
		else
			min_ans++;
	}

	cout << (min_ans == 0 ? 1 : min_ans) << ' ' << min_ans+cat[8] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch NumberOfMultiples | diff NumberOfMultiples.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address NumberOfMultiples.cpp && ./a.out

/*

 7/11/2020

 5:00-

 */

int D,L,R;

void solve() {
  int res=0;
  FORE(x,L,R) res+=(x%D==0);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>L>>R>>D;
  solve();

  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while (true) {
			int H = sc.nextInt(), W = sc.nextInt();
			if (H == 0 && W == 0) {
				break;
			}
			for (int h = 0; h < H; h++) {
				for (int w = 0; w < W; w++) {
					pr((h == 0 || h == H - 1 || w == 0 || w == W - 1) ? "#"
							: ".");

				}
				ln();
			}
			ln();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

ll counter[200001];
ll ans[200001]={0,};
unordered_map<int, vector<int> > mp;

int main() {
    ios::sync_with_stdio(false);
    int N,Q,A,B,last=-1;
    cin>>N>>Q;
    REP(i,0,N-1){
        cin>>A>>B;
        last=max(last,A);
        last=max(last,B);
        mp[A].push_back(B);
        mp[B].push_back(A);
    }
    REP(i,0,Q){
        cin>>A>>B;
        counter[A]+=B;
    }
    int visit[200001]={0,};
    deque<pair<int, ll> > dq;
    dq.push_back(make_pair(1,counter[1]));
    while(!dq.empty()) {
        pair<int, ll> now = dq.front();
        dq.pop_front();
        ans[now.first] = now.second;
        visit[now.first]=1;
        for(int next : mp[now.first]){
            if(visit[next]==1)continue;
            dq.push_back(make_pair(next,now.second+counter[next]));
        }
    }
    REP(i,1,last+1){
        cout<<ans[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 26812
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    a, b, k = list(map(int, readline().split()))
    res = []
    for i in range(a, min(a + k, b + 1)):
        if i not in res:
            res.append(i)
    for i in range(b, max(b - k, a - 1), -1):
        if i not in res:
            res.append(i)
    res.sort()
    print(*res, sep="\n")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define nn 100008
#define ll long long
vector<int> v[nn];
vector<int> cir;int pa[nn];
int siz[nn];int dep[nn];
int n,m;ll ans;
int c0,c1;

int vis[nn];int tag[nn];
void dfs(int x,int p)
{
	pa[x]=p;vis[x]=1;
	for(int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		if(y==p) continue;
		if(!vis[y]) dfs(y,x);
		else if(!cir.size())
		{
			int xx=x;
			while(xx!=y) cir.push_back(xx),xx=pa[xx];
			cir.push_back(y);
		}
	}
}
void efs(int x)
{
	siz[x]=tag[x];if(tag[x]<0) c0++;else c1++;
	for(int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		if(!tag[y]) 
			tag[y]=-tag[x],efs(y),siz[x]+=siz[y];
	}
}



void makeit(int x)
{
	for(int i=0;i<cir.size();i++)
	{
		ans+=abs(x);
		x=siz[cir[i]]-x;x=-x;
	}
	printf("%lld\n",ans);		
}
int main()
{
	tag[0]=1;
	#define err return 0*puts("-1");
	#define output return 0*printf("%lld\n",ans);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		v[x].push_back(y);v[y].push_back(x);
	}
	
	if(m<n)
	{
		tag[1]=1;efs(1);
		if(c0!=c1) err;
		for(int i=1;i<=n;i++) ans+=abs(siz[i]);
		output;
	}
	else
	{
		dfs(1,0);memset(vis,0,sizeof vis);
		int tot=0;
			
		for(int i=0;i<cir.size();i++) tag[cir[i]]=(i%2==0)*2-1;
		for(int i=0;i<cir.size();i++) efs(cir[i]),tot+=siz[cir[i]],ans-=abs(siz[cir[i]]);
		for(int i=1;i<=n;i++) ans+=abs(siz[i]);
			
		if(cir.size()%2==1)
		{
			if(tot%2) err;
			
			makeit(tot/2);
		}
		else
		{
			if(tot) err;
			
			int x=0,y=-1;vector<int> all;
			for(int i=0;i<cir.size();i++)
			{
				all.push_back(x*y);
			//	y=-y;
				x=siz[cir[i]]-x;
				x=-x;
			}
			
			sort(all.begin(),all.end());
			makeit(all[all.size()/2]);	
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 14712
#include<cstdio>
int main()
{
	int t;
	scanf("%d",&t);
	int ans=0;
	for(int i=1;i<=t;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		ans+=(b-a)+1;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>

using namespace std;

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

  int N;
  int v[4] = {0};  // NONE, a, b, c
  cin >> N >> v[1] >> v[2] >> v[3];

  int l[8] = {0};
  for (int i = 0; i < N; ++i) {
    cin >> l[i];
  }

  int choices = 1;
  for (int i = 0; i < N; ++i) choices *= 4;

  auto valid = [](const int* a) {
    for (int j = 1; j < 4; ++j) {
      if (a[j] == 0) return false;
    }
    return true;
  };

  int ans = numeric_limits<int>::max();
  // Skip i = 0 as it is obviously false
  for (int i = 1; i < choices; ++i) {
    int freq[4] = {0};

    int assignment[8] = {0};
    int x = i;
    for (int j = 0; j < N; ++j) {
      // each 2-bit corresponds to a choice for l_i.
      const int c = x & 0x3;
      x >>= 2;
      assignment[j] = c;
      freq[c]++;
    }

    if (!valid(freq)) continue;

    int sum[4] = {0};
    for (int j = 0; j < N; ++j) {
      sum[assignment[j]] += l[j];
    }

    int mp = 0;
    for (int i = 1; i < 4; ++i) {
      mp += abs(sum[i] - v[i]) + 10 * (freq[i] - 1);
    }

    ans = min(ans, mp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i

def gcd(a, b)
  (a, b) = [[a, b].min, [a, b].max]
  return (a == 0) ? b : gcd(b % a, a)
end

def lcm(a, b)
  (a * b) / gcd(a, b)
end

x = gets.chomp.to_i
(n - 1).times do
  t = gets.chomp.to_i
  x = lcm(x, t)
end
puts x.to_s

Measured memory_bytes: 1916
s = input()
if s == "SUN":
    print("7")

elif s == "MON":
    print("6")

elif s == "TUE":
    print("5")

elif s == "WED":
    print("4")

elif s == "THU":
    print("3")

elif s == "FRI":
    print("2")

else: print("1")


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

int main() {
    int a,b; cin >> a >> b;
    int ans = -1;
    rep(i,1001) {
        if((int)((double)i*0.08) == a && (int)((double)i*0.1) == b) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 0;
		int fib0 = 0;
		int fib1 = 1;
		int fib = 0;
		
		for(i=0;i<n;i++) {
			fib = fib0 + fib1;
			fib0 = fib1;
			fib1 = fib;
		}
		System.out.println(fib);
		sc.close();
	}

}



Measured memory_bytes: 26188
import collections
n = int(input())
d_list = list(map(int, input().split()))
m = int(input())
t_list = list(map(int, input().split()))

if m > n:
    print("NO")
    exit()

d_c = collections.Counter(d_list)
t_c = collections.Counter(t_list)

for i in t_c:
    if t_c[i] <= d_c[i]:
        continue
    else:
        print("NO")
        exit()

print("YES")

Measured memory_bytes: 57200