akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

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

#define endl '\n'

int main() {
  fast_io;
  int n;
  cin >> n;
  int cx, cy, ct;
  cx = cy = ct = 0;
  for (int i = 0; i < n; i++) {
    int nx, ny, nt;
    cin >> nt >> nx >> ny;
    if (abs(nx - cx) + abs(ny - cy) <= nt - ct &&
        ((nt - ct) % 2 == (abs(nx - cx) + abs(ny - cy)) % 2))
      ;
    else {
      return 0 * puts("No");
    }
    cx = nx;
    cy = ny;
    ct = nt;
  }
  return 0 * puts("Yes");
}


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

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


char s[1015][1015];
struct node{ int x,y,step; };
queue<node> q;
int ans;

void bfs() {
    while (!q.empty()) {
        node now = q.front(); q.pop();
        ans=max(ans,now.step);
        for (int i=0;i<4;i++) {
            node nex = node{now.x+dx[i],now.y+dy[i],now.step+1};
            if (s[ nex.x ][ nex.y ]=='.') {
                s[ nex.x ][ nex.y ]='#';
                q.push(nex);
            }
        }
    }
}

int main () {
    int n,m;
    cin >> n >> m;
    
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) {
            cin >> s[i][j];
            if (s[i][j]=='#')
                q.push(node{i,j,0});
        }
    
    bfs();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13328
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

int main(){
	IOS;
	int n;
	cin >> n;
	int t,a;
	long long int l=0,r=0;
	for(int i=0;i<n;i++){
		cin >> t >> a;
		if(i==0) l=t,r=a;
		else{
			long long int tl=l/t,tr=r/a;
			if(l%t!=0) tl++;
			if(r%a!=0) tr++;
			if(tl>=tr){
				l=tl*t;
				r=tl*a;
			}
			else{
				l=tr*t;
				r=tr*a;
			}
		}
	}
	cout << l+r << '\n';
	return 0;
}


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

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

    string s;
    cin>>s;

    int k;
    cin>>k;

    for (char &c: s) {
        if (c == 'a')   continue;
        int need = 'z'-c+1;
        if (need <= k)    k-=need, c='a';
    }

    s.back() = 'a' + (s.back()-'a'+k)%26;

    cout<<s<<endl;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
int top,S[1000];
void push(int x){
    S[++top]=x;
}
int pop(){
    top--;
    return S[top+1];
}
int main(void){
    int a,b;
    top=0;
    char s[100];
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(s[0]=='-'){
            b=pop();
            a=pop();
            push(a-b);
        }
        else if(s[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);
        }
        else{
            push(atoi(s));
        }
    }
    printf("%d\n",pop());
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    string ans = "";
    if (n == 0) {
      cout << 0 << endl;
      return 0;
    }
    while (n != 0) {
      int r = n % 2 < 0 ? n % 2 + 2 : n % 2;
      ans.pb('0'+r);
      n = (n - r) / (-2);
    }
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll 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;
    }
};

int main(){
    ll n;
    cin >> n;
    vector<ll> c(n);
    rep(i, n) {
        cin >> c[i];
    }
    sort(c.begin(), c.end());
    mint ans(0);
    rep(i, n) {
        mint v(4);
        v = v.pow(n-1);
        v *= mint(c[i]);
        v *= mint(n-i+1);
        ans += v;
    }
    
    
    cout << ans.x << endl;
    return 0;
}


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

char q[4]="-++";
int main()
{
    string n;
    cin>>n;
    int a=n[0]-'0';
    int b=n[1]-'0';
    int c=n[2]-'0';
    int d=n[3]-'0';

    for(int i=-1;i<=1;i+=2)
    {
        for(int j=-1;j<=1;j+=2)
        {
            for(int k=-1;k<=1;k+=2)
            {
                if(a + i*b + j*c + k*d == 7)
                {
                    return printf("%d%c%d%c%d%c%d=7",a, q[i+1] ,b,q[j+1] ,c,q[k+1] ,d),0;
                }
            }
        }
    }
    return 0;
}


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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  while(true){
    int n,m,t,p;
    cin>>n>>m>>t>>p;
    if(n==0&&m==0&&t==0&&p==0)return 0;
    vector<int>d(t),c(t),x(p),y(p);
    for(int i=0;i<t;i++)cin>>d[i]>>c[i];
    for(int i=0;i<p;i++)cin>>x[i]>>y[i];
    //n -, m |
    vector<vector<int>>paper(n,vector<int>(m,1));
    for(int i=0;i<t;i++){
      /*
      cout<<"#----------------------"<<endl;
      for(int y=0;y<m;y++){
        for(int x=0;x<n;x++){
          cout<<paper[x][y]<<" ";
        }
        cout<<endl;
      }
      cout<<"#----------------------"<<endl;
      */
      int C=c[i];
      // |
      if(d[i]==1){
        vector<vector<int>>fold(C,vector<int>(m));
        for(int i=0;i<C;i++){
          for(int j=0;j<m;j++){
            fold[i][j]=paper[i][j];
          }
        }

        vector<vector<int>>copy=paper;
        for(int i=0;i<n;i++){
          for(int j=0;j<m;j++){
            if(i+C<n)paper[i][j]=copy[i+C][j];
            else paper[i][j]=0;
          }
        }

        for(int i=0;i<C;i++){
          for(int j=0;j<m;j++){
            paper[i][j]+=fold[(C-1)-i][j];
          }
        }
      }
      // -
      else if(d[i]==2){
        vector<vector<int>>fold(n,vector<int>(C));
        for(int i=0;i<n;i++){
          for(int j=0;j<C;j++){
            fold[i][j]=paper[i][j];
          }
        }

        vector<vector<int>>copy=paper;
        for(int i=0;i<n;i++){
          for(int j=0;j<m;j++){
            if(j+C<m)paper[i][j]=copy[i][j+C];
            else paper[i][j]=0;
          }
        }

        for(int i=0;i<n;i++){
          for(int j=0;j<C;j++){
            paper[i][j]+=fold[i][(C-1)-j];
          }
        }
      }
    }

    /*
    cout<<"-----------------------"<<endl;
    for(int y=0;y<m;y++){
      for(int x=0;x<n;x++){
        cout<<paper[x][y]<<" ";
      }
      cout<<endl;
    }
    cout<<"-----------------------"<<endl;
    */

    for(int i=0;i<p;i++){
      int X=x[i];
      int Y=y[i];
      cout<<paper[X][Y]<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3160
using System;
using System.Collections.Generic;
using System.Linq;
class P{
    static void Main(){
        string s = Console.ReadLine();
        int n = s.Length;
        List<int> l = new List<int>();
        for (int i = 0;i < n - 2;i++)
            l.Add(Math.Abs(MakeNum(s[i],s[i+1],s[i+2])-753));
        Console.WriteLine(l.Min());
    }
    static int MakeNum(char a,char b,char c){
        return (int)(100 * Char.GetNumericValue(a) + 10 * Char.GetNumericValue(b) + Char.GetNumericValue(c));
    }
}

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

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

    int n;
    cin >> n;
    vector<int> as = {111,222,333,444,555,666,777,888,999};
    for (int a : as) {
        if (a >= n) {
            cout << a << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>

#define NUM 101

int main() {
    int i, j, r, c, data[NUM][NUM];
    
    scanf("%d%d", &r, &c);
    for (i = 0; i <= r; i++) data[i][c] = 0;
    for (i = 0; i <= c; i++) data[r][i] = 0;
    
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            scanf("%d", &data[i][j]);
            data[i][c] += data[i][j];
        }
    }
    
    for (i = 0; i <= c; i++) {
        for (j = 0; j < r; j++) {
            data[r][i] += data[j][i];
        }
    }
    
    for (i = 0; i <= r; i++) {
        for (j = 0; j <= c; j++) {
            printf("%d", data[i][j]);
            if (j != c) printf(" ");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2128
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
ll n, k;
vector<ll> a, sum;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>k;

    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    for(int i=0;i<n;i++){
        ll sumt=0;
        for(int j=i;j<n;j++){
            sumt+=a[j];
            sum.push_back(sumt);
        }
    }
    ll keta=41;
    ll ans=0;
    while(keta>=0){
        ll count=0;
        for(int i=0;i<sum.size();i++){
            if(sum[i]&(ll(1)<<keta)){
                count++;
            }
        }
        if(count>=k){
            ans+=(ll(1)<<keta);
            vector<ll> temp;
            for(int i=0;i<sum.size();i++){
            if(sum[i]&(ll(1)<<keta)){
                temp.push_back(sum[i]);
            }
            }
            sum=temp;/*
            for(int i=0;i<sum.size();i++){
            cout<<sum[i]<<" ";
        }
            cout<<"\n";
            cout<<ans<<"\n";
            cout<<keta<<"\n";
            cout<<(ll(1)<<keta)<<"\n";
            */
            }
        keta--;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 6256
// D - Not Divisible
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

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

	int mx = 0;
	map<int,int> m;
	rep(i, N){
		int a; cin>>a;
		m[a]++;
		mx = max(mx, a);
	}

	int ans = 0;
	vi l(mx+1, 0);
	for(auto x:m){
		int a, c; tie(a, c) = x;
		if(c == 1 && l[a] == 0) ans++;
		for(int i=a; i<=mx; i+=a) l[i] = 1;
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 16240
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong()-1;
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long x = a - (a / c) - (a / d) + (a / lcm(c, d));
		long y = b - (b / c) - (b / d) + (b / lcm(c, d));

		System.out.println(y-x);

		//12345 7910 
		//
	}

	private static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	private static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
		if(n == 0) return m;
		return gcd(n, m % n);
	}
}

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

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while(true){
			/* input from here */
			line = r.readLine();
			//s: num of hot springs, d: num of districts
			int s, d, min=100, minindex=0;
			s = Integer.parseInt(line.split("[ \t]")[0]);
			d = Integer.parseInt(line.split("[ \t]")[1]);
			if(s==0&&d==0){
				break;
			}
			//shortest direct distance from hot springs to each district
			int[] stod = new int[d];
			Arrays.fill(stod, 101);
			for(int i=0;i<s;i++){
				line = r.readLine();
				String[] t = line.split("[ \t]");
				for(int j=0;j<d;j++){
					int distj = Integer.parseInt(t[j]);
					if(distj>0&&distj<stod[j]){
						stod[j] = distj;
						if(distj<min){
							min = distj;
							minindex = j;
						}
					}
				}
			}
			//distance between districts
			int[][] dtod = new int[d][d];
			for(int i=0;i<d-1;i++){
				line = r.readLine();
				String[] t = line.split("[ \t]");
				for(int j=i+1;j<d;j++){
					dtod[i][j] = Integer.parseInt(t[j-i-1]);
				}
				for(int j=0;j<i;j++){
					dtod[i][j] = dtod[j][i];
				}
			}
			for(int j=0;j<d-1;j++){
				dtod[d-1][j] = dtod[j][d-1];
			}
			/* input till here */
			/* processing from here */
			//shortest distance from a hot spring to the district 
			int[] dist = new int[d];
			ArrayList<Integer> doneindex = new ArrayList<Integer>();
			dist[minindex] = min;
			doneindex.add(minindex);
			int restcount = d-1, sum = min;
			while(restcount>0){
				int nextmin = 101, nextminindex = -1;
				for(int i=0;i<d;i++){
					if(doneindex.contains(i)){
						continue;
					}
					if(stod[i]>0&&stod[i]<nextmin&&!doneindex.contains(i)){
						nextmin = Math.min(stod[i],nextmin);
						nextminindex = i;
					}

					for(Integer j : doneindex){
						if(dtod[j][i]>0&&dtod[j][i]<nextmin){
							nextmin = Math.min(dtod[j][i], nextmin);
							nextminindex = i;
						}
					}
				}
				sum += nextmin;
				doneindex.add(nextminindex);
				restcount--;
			}

			/* processing till here */
			/* output */
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 19688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
ll mod = 1000000007;
void secondsort(vector<pair<ll,ll>> &v){
    for(ll i=0;i < v.size();i++){
    swap(v.at(i).first,v.at(i).second);
    }
    sort(v.begin(),v.end());
    for(ll i=0;i < v.size();i++){
    swap(v.at(i).first,v.at(i).second);
    }
}

signed main(){
    ll n,k,cntt=1,ans=0;
    cin >> n >> k;
    vector<bool> v(n,false);//flag
    vector<pair<ll,ll>> u(n);
    vector<ll> s;//二個目以降
    vector<ll> f;

    for (ll i = 0; i < n; i++)
    {
        cin >>u.at(i).fi>>u.at(i).se;
    }
    secondsort(u);
    
    for (ll i = n-1; 0<=i; i--)
    {
        if(v.at(u.at(i).fi-1)==false){
            v.at(u.at(i).fi-1)=true;
            f.pb(u.at(i).se);
        }else{
            s.pb(u.at(i).se);
        }
    }//input

    sort(f.begin(),f.end());
    sort(s.begin(),s.end());
    
    vector<ll> fsum((ll)f.size()),ssum((ll)s.size());
    for (ll i = 0; i < f.size(); i++)
    {
        if(i==0){
            fsum.at(i)=f.at((ll)f.size()-i-1);
        }else{
            fsum.at(i)=fsum.at(i-1)+f.at((ll)f.size()-i-1);
        }
    }

    for (ll i = 0; i < ssum.size(); i++)
    {
        if(i==0){
            ssum.at(i)=s.at((ll)s.size()-i-1);
        }else{
            ssum.at(i)=ssum.at(i-1)+s.at((ll)s.size()-i-1);
        }
    }
    
    if(k-1<(ll)ssum.size()){
        ans=ssum.at(k-1);
    }
    if(k-1<(ll)fsum.size()){
        ans=max(fsum.at(k-1)+(k*k),ans);
    }

    for (ll i = 0; i < (ll)fsum.size(); i++)
    {
        if(0<=k-i-2 && k-i-2< (ll)ssum.size() && i<(ll)fsum.size()){
            ans=max(ans,fsum.at(i)+(i+1)*(i+1)+ssum.at(k-i-2));
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3576
"use strict";
function main(input) {
    const line = input.split("\n");
    const N = parseInt(line[0]);
    const A = line[1].split(" ").map(Number);
    const B = line[2].split(" ").map(Number);
    const C = line[3].split(" ").map(Number);
    let ans = B.reduce((pre, cur) => pre + cur, 0);
    for (let i = 1; i < N; i++) if (A[i] === A[i - 1] + 1) ans += C[A[i - 1] - 1];
    console.log(ans);
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29676
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,cnt[300010] = {},knd = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a; a--;
		if(!cnt[a]) knd++;
		cnt[a]++;
	}
	sort(cnt,cnt + n,greater<int>());
	int pos = 0,sum = 0;
	cout << n << endl;
	for(int i = 1;i < n;i++){
		while(pos < knd && cnt[pos] * (i + 1 - pos) > (n - sum)){
			sum += cnt[pos++];
		}
		cout << (i + 1 - pos == 0 ? 0 : (n - sum) / (i + 1 - pos)) << endl;
	}
}

Measured memory_bytes: 3200
import math

n = int(input())
x = 0
s = [0] * 35
for _ in range(n):
    a = int(input())
    x ^= a
    s[int(math.log2(int((a ^ (a - 1)) + 1))) - 1] = 1
t = [0] * 35
while True:
    if x == 0:
        break
    y = int(math.log2(x))
    t[y] = 1
    x -= pow(2, y)
s.reverse()
t.reverse()
ans = 0
now = 0
for i in range(35):
    if now == t[i]:
        continue
    else:
        if s[i] == 1:
            ans += 1
            now = 1 - now
        else:
            print(-1)
            exit()
print(ans)

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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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



int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string s;
    cin >> s;
    int ans = 0;
    if(s == "RSS"){
        cout << 1 << endl;
    }else if(s == "RSR"){
        cout << 1 << endl;
    }else if(s == "SRS"){
        cout << 1 << endl;
    }else if(s == "SSR"){
        cout << 1 << endl;
    }else if(s == "RRS"){
        cout << 2 << endl;
    }else if(s == "SRR"){
        cout << 2 << endl;
    }else if(s == "RRR"){
        cout << 3 << endl;
    }else{
        cout << 0 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

ll N, W;
vector <ll> w;
vector <ll> v;

vector<vector<ll>> dp;

ll rec(ll idx, ll rem) {
	if (dp[idx][rem] >= 0){
		return dp[idx][rem];
	}
	ll value;
	if (idx == N){
		value = 0;
	} else if(rem < w[idx]) {
		value = rec(idx + 1, rem);
	} else {
		value = max(rec(idx + 1, rem), rec(idx + 1, rem - w[idx]) + v[idx]);
	}

	return dp[idx][rem] = value;
}

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

	for (int ii = 0; ii < N; ++ii){
		ll tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		w.push_back(tmp1);
		v.push_back(tmp2);
	}

	//dpの初期化
	dp.resize(N+1);
	for (int ii = 0; ii < N+1; ++ii){
		dp[ii].assign(W+1, -1);
	}

	ll value = rec(0, W);

	cout << value << endl;

	return 0;
}


Measured memory_bytes: 79488
#include<iostream>
using namespace std;
int solve(int a[],int i,int n,int dp[])
{
    if(i>=n)
    {
        return dp[i]=0;
    }
    else if(dp[i]!=-1)
    {
        return dp[i];
    }
    else
    {
        return dp[i]=min(abs(a[i+1]-a[i])+solve(a,i+1,n,dp),abs(a[i+2]-a[i])+solve(a,i+2,n,dp));
    }
}
int main()
{
    int n,i;
    cin>>n;
    int m[n];
    int dp[100005];
    for(i=0;i<100005;i++)
    {
        dp[i]=-1;
    }
    for(i=0;i<n;i++)
    {
        cin>>m[i];
    }
    cout<<solve(m,0,n-1,dp)<<endl;
}


Measured memory_bytes: 8208
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
//#define x first
//#define y second
#define pb push_back
#define eb emplace_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
 
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
typedef long long LL;
const int MAX_N = 1e5 + 5;
const LL mod = 1e9 + 7;
 
int n, a, b;
 
int f(int x)
{
    int res = 0;
    while(x) {
        res += x%10;
        x /= 10;
    }
    return res;
}
 
int main()
{
#ifdef ANONYM
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
 
    while(cin >> n) {
        if(n % f(n) == 0) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll gcd(ll a, ll b) {
    if (a < b) return gcd(b, a);
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

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

    ll n;
    cin >> n;

    vector<ll> a;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        a.push_back (temp);
    }

    ll t = a[0];
    for (int i = 0; i < n; i++) {
        t = gcd(t, a[i]);
    }

    cout << t << endl;

}

Measured memory_bytes: 1400
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

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

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

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

  int n;
  cin >> n;
  vector<pair<lint, lint>> xy(n);
  rep(i, n) cin >> xy[i].first >> xy[i].second;

  sort(all(xy));
  reverse(all(xy));

  map<pair<lint, lint>, int> cnt;
  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
      cnt[make_pair(xy[i].first - xy[j].first, xy[i].second - xy[j].second)]++;
    }
  }
  int ans = 0;
  for (auto x : cnt) {
    ans = max(ans, x.second);
  }

  cout << n - ans << endl;

  return 0;
}

Measured memory_bytes: 384
N, M = list(map(int, input().split()))
A = [i + 1 for i in range(N)]
mid = N//2
ans = []
for i in range(M+1//2):
    ans.append([A[mid - i], A[mid + 1 + i]])
    ans.append([A[-1 - i], A[1 + i]])
for i in range(M):
    print(*ans[i])

Measured memory_bytes: 31888
import queue
import math
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
n = int(input())
s = input()
a = "No"
if n %2 == 0 and s[:int(n/2)] == s[int(n/2):]:
	a = "Yes"
print(a)

Measured memory_bytes: 4336
#include <cstdio>
#include <algorithm>
#include <stdint.h>

int as[300005];

int main(){
  int N;
  scanf("%d",&N);
  for(int i=0;i<N*3;i++){
    scanf("%d",&as[i]);
  }
  std::sort(as,as+N*3);
  int64_t ans=0;
  for(int i=1;i<=N;i++){
    ans+=as[N*3-2*i];
  }
  printf("%ld\n",ans);
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t S;
  cin >> S;
  int64_t x = S/1000000000 + 1;
  int64_t y = 1000000000 - (S %1000000000);
  if(S %1000000000 == 0){
    x--;
    y = 0;
  }
  cout << 0 << " "<< 0 << " "<< 1000000000 << " "<< y << " "<< 1 << " "<< x << endl;
  //cout << 1000000000*x - y << endl;
}

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

typedef vector<int> vi;

const int INF = 10000;
int H, W, K;
vector<string> S;
vector<vi> C;
vi U, D;

void input_init(void) {
	cin >> H >> W >> K;
	S.resize(H);
	for (int j = 0; j < H; ++j)
		cin >> S[j];
	C.resize(H, vi(W + 1, 0));
	for (int j = 0; j < H; ++j) {
		for (int i = 1; i <= W; ++i) {
			if (S[j][i - 1] == '1')
				C[j][i] = C[j][i - 1] + 1;
			else
				C[j][i] = C[j][i - 1];
		}
	}
}

void make_col(int k) {
	U.clear();
	D.clear();
	U.push_back(0);
	for (int j = 0; j < H; ++j) {
		if ((k & (1 << j)) != 0) {
			D.push_back(j);
			U.push_back(j + 1);
		}
	}
	D.push_back(H - 1);
}

int check_x(void) {
	int cnt_x = 0;
	int pre_x = 0;
	int cur_x = 1;
	for (int x = cur_x; x <= W; ++x) {
		for (int t = 0; t < (int)U.size(); ++t) {
			int sum = 0;
			for (int y = U[t]; y <= D[t]; ++y)
				sum += C[y][x] - C[y][pre_x];
			if (sum > K) {
				if (x - pre_x == 1) {
					cnt_x = INF;
					cur_x = W + 1;
					break;
				}
				pre_x = x - 1;
				cur_x = x;
				++cnt_x;
				break;
			}
		}
	}
	return cnt_x;
}

int solve(void) {
	int min_xy = INF;
	for (int k = 0; k < (1 << (H - 1)); ++k) {
		make_col(k);
		int cnt_y = U.size() - 1;
		int cnt_x = check_x();
		int cnt = cnt_y + cnt_x;
		min_xy = min(cnt, min_xy);
	}
	return min_xy;
}

int main(void) {
	input_init();
	int ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 998244353;
vector<int> fact;
int pw(int a, int b){
    if (b==0) return 1;
    if (b == 1) return a%MOD;
    if (b%2) return (a*pw(a, b-1)) % MOD;
    int rs = pw(a, b/2);
    return (rs*rs)%MOD;
}
int C(int n, int k){
    int X = fact[n];
    int Y = (fact[k] * fact[n-k]) % MOD;
    return (X * pw(Y, MOD-2)) % MOD;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b, k;
    cin >> n >> a >> b >> k;
    fact.push_back(1);
    for (int i=1; i < 5e5; i++) fact.push_back((fact.back() * i)%MOD);
    int ans = 0;
    for (int i=0; i <= n; i++){
        int rest = k-a*i;
        if (rest%b) continue;
        int j = rest / b;
        if (j < 0 || j > n) continue;
        ans += (C(n, i) * C(n, j));
        ans %= MOD;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n<=1000)
  {
    cout<<1000-n;
  }
  else
  {
  int t=1000;

    while(n>t)
      t=t+1000;
   cout<<t-n;
  }
}

Measured memory_bytes: 3632
n=int(input())
d=sorted([int(i) for i in input().split()])
dif=[0]*d[-1]
ruiseki=[0]*d[-1]
for i in d:
    dif[i-1]+=1
for i in range(d[-1]):
    ruiseki[i]=ruiseki[i-1]+dif[i]
SUM=sum(dif)
ans=0
for i in range(n-1):
    S=ruiseki[d[i]-1]
    if S==SUM-S:
        ans+=d[i+1]-d[i]
print(ans)

Measured memory_bytes: 53608
#include <iostream>
#include <algorithm>
#define INF 10e6
using namespace std;

int cost[20][20];

int main(void){
	int n,m;
	char tmp;
	cin >> n >>m; 
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cost[i][j]=INF;
	int a,b,c,d;
	for(int i=0;i<m;i++){
		cin >> a >> tmp >> b >> tmp >> c >> tmp >> d;
		cost[a-1][b-1]=c,cost[b-1][a-1]=d;
	}
	for(int k=0;k<n;k++)
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
	int s,g;
	cin >> s >> tmp >> g >> tmp >> m >> tmp >> c;
	int ans=m-c-cost[s-1][g-1]-cost[g-1][s-1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod int = 1e9 + 7

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	as := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		as[i] = nextInt()
		sum = add(sum, as[i])
	}

	ans := mul(sum, sum)
	for i := 0; i < n; i++ {
		ans = sub(ans, mul(as[i], as[i]))
	}
	ans = div(ans, 2)
	fmt.Println(ans)
}

func pow(n, k int) int {
	if k == 0 {
		return 1
	} else if k%2 == 1 {
		return pow(n, k-1) * n % mod
	} else {
		t := pow(n, k/2)
		return t * t % mod
	}
}

func add(a, b int) int {
	return (a + b) % mod
}

func sub(a, b int) int {
	return (a + mod - b) % mod
}

func mul(a, b int) int {
	return a % mod * b % mod % mod
}

func div(a, b int) int {
	return mul(a, pow(b, mod-2))
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

int main() {
  int n;
  cin >> n;
  vector<string>s(n);
  for (int i = 0; i < n; i++)
    cin >> s.at(i);
  
  int m;
  cin >> m;
  vector<string>t(m);
  for (int i = 0; i < m; i++)
    cin >> t.at(i);
  
  int ans = 0;
  int cnt;
  for (int i = 0; i < n; i++) {
    cnt = 1;
    for (int j = i+1; j < n; j++) {
      if (s.at(i) == s.at(j))
        cnt++;
    }
    for (int j = 0; j < m; j++) {
      if (s.at(i) == t.at(j))
        cnt--;
    }
    ans = max(ans, cnt);
  }
  if (ans < 0)
    ans = 0;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fup(i,a,b) for(int i=a;i<=b;++i)
#define fdw(i,a,b) for(int i=a;i>=b;--i)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define cl(a) memset(a,0,sizeof(a))
#define gcd __gcd
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
//ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;}
//bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;}
//void shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数"
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e-7;
const int N=510;
int c[N][N],rsum[N];
int main()
{
//    #ifdef ONLINE_JUDGE
//    #else
//        freopen("D:\\untitled3\\in","r",stdin);
//    #endif
    sync;
    ll n;
    cin>>n;
    cout<<(n-1)/2+1<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
bool used[10001];

int main(){	
	int N;
	cin >> N;
	int a, b;
	set<int> st[N];
	for (int i=0; i<N-1; i++) {
		cin >> a >> b;
		a--;
		b--;
		st[a].insert(b);
		st[b].insert(a);
	}
	vector<int> c(N);
	for (int i=0; i<N; i++) {
		cin >> c[i];	
	}
	
	queue<int> que;
	// 0からの深さを各頂点につける
	que.push(0);
	used[0] = true;
	vector<int> dep(N);
	while(!que.empty()) {
		int t = que.front();
		que.pop();
		while(!st[t].empty()) {
			int ins = *st[t].begin();
			st[t].erase(ins);
			if (!used[ins]) {
				used[ins] = true;
				que.push(ins);
				dep[ins] = dep[t]+1;
			}
		}
	}

	priority_queue<P> que2;
	rep(i, N) {
		que2.push(P(dep[i], i));
	}

	SORT(c);
	int M = 0;
	vector<int> d(N,-1);
	rep(i, N) {
		int s = que2.top().second;
		que2.pop();
		d[s] = c[i];
		if (i != N-1) M += c[i];
	}

	cout << M << endl;
	rep(i, N) {
		cout << d[i];
		if (i != N-1) cout << " "; else cout << endl;
	}
	return 0;
}


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

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

  int count = 0;
  for(int i = 0; i < 3; ++i) {
    if(S[i] == 'o') {
      ++count;
    }
  }
  cout << 700 + 100 * count << endl;
}

Measured memory_bytes: 256
#from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    a = li()
    acnt = [0 for i in range(100005)]
    for i in a:
        acnt[i]+=1
        acnt[i+1]+=1
        acnt[i+2]+=1
    print(max(acnt))


main()




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

int main()
{
	
  	ll H,W;
  	cin>>H>>W;
  
  	if(H == 1 || W == 1)
      cout<<1<<endl;
  	else
      cout<<((H*W)+1)/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl c, d;
ll id = 1;

void dfs(ll v, ll p = -1) {
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        d[u] = c[id];
        id++;
        dfs(u, v);
    }
}

int main() {
    ll n;
    cin >> n;    

    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    c.resize(n);
    rep(i, n) {
        cin >> c[i];
    }
    sort(rall(c));

    d.resize(n);
    d[0] = c[0];
    dfs(0);

    ll M = 0;
    exrep(i, 1, n-1) {
        M += c[i];
    }

    out(M);
    rep(i, n) {
        cout << d[i] << " ";
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int count = 0, A, B;
      cin >> A >> B;
      for (int i = A; i <= B; i++){
        if (i % 10 == i / 10000 && i % 100 / 10 == i % 10000 /1000)
          count++;
      }
      cout << count << endl;
    }

Measured memory_bytes: 3620
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

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

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int H, W;
	std::vector<std::string> a;

	std::cin >> H >> W;
	a.resize(H);
	for (auto& x : a) {
		std::cin >> x;
	}
	
	std::cout << std::string((size_t)W+2, '#') << "\n";
	for (auto& x : a) {
		std::cout << "#" << x << "#\n";
	}
	std::cout << std::string((size_t)W+2, '#') << "\n";
}


Measured memory_bytes: 384
/************
* 	@Just Another Source code by: ankit.sangwan1999
*	@created on: 25 May 2020
*/
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9+7;
#define endl '\n'

int n;
int t_max;
vector<double> prr;
double dp[3000][3000];
bool vis[3000][3000];

double fun(int ind, int curr_tails){

	if(vis[ind][curr_tails]) {
		return dp[ind][curr_tails];
	}
	vis[ind][curr_tails] = 1;

	double pos1 = 0,pos2 = 0;

	if(curr_tails<t_max){
		pos1 = (1-prr[ind]);
		if(ind-1>=0){
			if(vis[ind-1][curr_tails+1] == 0){
				dp[ind-1][curr_tails+1] = fun(ind-1, curr_tails+1);
			}
			pos1 *= dp[ind-1][curr_tails+1];
		}
	}

	pos2 = prr[ind];
	if(ind-1>=0){
		if(vis[ind-1][curr_tails] == 0){
			dp[ind-1][curr_tails] = fun(ind-1, curr_tails);
		}
		pos2 *= dp[ind-1][curr_tails];
	}
	
	return dp[ind][curr_tails] = pos1 + pos2;
}


signed main(){

    fastio;

    cin>>n;
    for(int i=0;i<3000;i++)
    	for(int j=0;j<3000;j++)
    		vis[i][j] = 0;

    if(n&1) t_max = n/2;
    else t_max = n/2 - 1;
    
    prr = vector<double>(n);

    for(int i=0;i<n;i++) cin>>setprecision(10)>>prr[i];

    cout<<setprecision(10)<<fun(n-1, 0);


    return 0;
}

Measured memory_bytes: 78592
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
using namespace std;

int n,m,a[200005];
ll b[200005], c[200005];
vector<int> v1;
vector<pair<int,int> > v2;

int main()
{
    scanf("%d %d",&n,&m);

    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }

    ll s=0;
    for(int i=1; i<n; i++)
    {
        if(a[i]>a[i-1])
        {
            s+= a[i]-a[i-1];
            v1.pb(a[i-1]);
            v2.pb(mp(a[i],a[i-1]));
        }
        else
        {
            s+= m-a[i-1]+a[i];
            v1.pb(a[i-1]);
            v2.pb(mp(a[i]+m,a[i-1]));
        }
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    for(int i=1,j=0,k=0; i<=m+m; i++)
    {
        b[i]= b[i-1];
        c[i]= c[i-1];
        while(j<v1.size() && i==v1[j])
        {
            b[i]+= i;
            c[i]++;
            j++;
        }

        while(k<v2.size() && v2[k].xx<=i)
        {
            b[i]-= v2[k].yy;
            c[i]--;
            k++;
        }
//        printf("  %d %lld %lld\n",i,b[i],c[i]);
    }

    ll mn= 100000000000000ll;

    for(ll i=1; i<=m; i++)
    {
        ll ans= c[i-1]*(i-1) - b[i-1];
        ans+= c[m+i-1]*(m+i-1) - b[m+i-1];
        ans= s-ans;
        mn= min(mn, ans);
    }
    printf("%lld\n",mn);
}


Measured memory_bytes: 5104
from collections import deque

H, W = map(int, input().split())

inp = []
for h in range(H):
    inp.append(input())

field = []
field.append(["#" for _ in range(W+2)])
for h in range(H):
    field.append(["#"] + list(inp[h]) + ["#"])    
field.append(["#" for _ in range(W+2)])


def bfs():
    que = deque([])
    next_h = [1,0,-1, 0]
    next_w = [0,1, 0,-1]
    
    que.append([0,1,1])
    
    while len(que) != 0:
        dist,h,w = que.popleft()
        if field[h][w] != ".":
            continue
        
        field[h][w] = str(dist)
        
        for i in range(4):
            if field[h+next_h[i]][w+next_w[i]] == ".":
                que.append([dist+1, h+next_h[i], w+next_w[i]])
            
    return field[H][W]
    

points = 0
for field_row in field:
    for point in field_row:
        if point == ".":
            points += 1


min_dist = bfs()

if min_dist == '.':
    print(-1)
else:
    print(points - int(min_dist) - 1)

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <cstdlib>
#include <queue>
#define INF 200000000
#define MAXN 1005
#define MAXM 10005
using namespace std;
int a[MAXM],l,i,j,ans,b[10];
void find(int num)
{
    int n1=0,n2=0;
    int po=1;
    memset(b,0,sizeof(b));
    while(num>0){b[po++]=num-num/10*10;num/=10;}
    sort(b,b+l+1);
    for(i=1;i<=l;i++)n1=n1*10+b[i];
    for(i=l;i>=1;i--)n2=n2*10+b[i];
    a[++j]=n2-n1;

    for(i=0;i<j;i++)
    if(a[i]==a[j]){ans=a[j];return;}
    find(a[j]);

}
int main()
{
    int num;
    while(scanf("%d%d",&num,&l))
    {
        if(num==0&&l==0)break;
        a[0]=num;j=0;
        find(num);
        printf("%d %d %d\n",i,ans,j-i);
    }
    return 0;
}

Measured memory_bytes: 0
### constant

INF = 1 << 30

DXYS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### main

loop do
  w, h = gets.split.map(&:to_i)
  break if (w | h) == 0

  wh = w * h

  tls = wh.times.map{0}
  ndtl = 0
  spos = nil

  for y in (0...h)
    line = gets.strip
    for x in (0...w)
      pos = y * w + x
      case line[x]
      when '*'
        ndtl += 1
        tls[pos] = ndtl
      when 'x'
        tls[pos] = -1
      when 'o'
        spos = pos
      end
    end
  end
  #p tls
  #p spos

  dbits = (1 << ndtl) - 1

  dists = wh.times.map{(dbits + 1).times.map{INF}}
  dists[spos][dbits] = 0
  q = [[spos, dbits]]

  min_dist = INF

  while ! q.empty?
    upos, ubits = q.shift
    ud = dists[upos][ubits]

    if ubits == 0
      min_dist = ud if min_dist > ud
      next
    end

    ux = upos % w
    uy = upos / w

    DXYS.each do |dx, dy|
      vx = ux + dx
      vy = uy + dy
      vpos = vy * w + vx

      if vx >= 0 && vx < w && vy >= 0 && vy < h && tls[vpos] >= 0
        vbits = ubits
        if tls[vpos] > 0
          vbits &= ~(1 << (tls[vpos] - 1))
        end

        vd = ud + 1
        if dists[vpos][vbits] > vd
          dists[vpos][vbits] = vd
          q << [vpos, vbits]
        end
      end
    end
  end

  puts (min_dist >= INF ? -1 : min_dist)
  #p dists
end

Measured memory_bytes: 9188
import java.util.Scanner;

class Main {

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

        long N=stdIn.nextLong();
        long A=stdIn.nextLong();
        long B=stdIn.nextLong();

        long C=N%(A+B);
        if(C>=A){
            C=A;
        }
        

        System.out.println(N/(A+B)*A+C);
        
        
    }

}

Measured memory_bytes: 23764