akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod;
const int MAX = 100010;

int main(){
    int x;
    scanf("%d", &x);
    int a[6];
    rep(i ,6) a[i]=100+i;
    bool dp[x+1];
    rep(i, x+1) dp[i]=false;
    dp[0]=true;
    rep(i, x)if(dp[i]){
        rep(j, 6)if(i+a[j]<=x) dp[i+a[j]]|=dp[i];
    }
    printf("%d\n", dp[x]);
}

Measured memory_bytes: 384
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void join(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb])swap(ra,rb);
        v[rb]=ra;
        sz[ra]+=sz[rb];
        
    }
    bool same(int a,int b){
        //same set
        return (root(a)==root(b));
    }
    int size(int a){
        return sz[root(a)];
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
    int n,a,b;
    cin>>n>>a>>b;
    int ans = n/(a+b)*a + min(a,n%(a+b));
    cout<<ans;
}

Measured memory_bytes: 5992
s=gets.to_i
a=gets.split.map &:to_i
n=a.max
b=a.sort
for i in 0...s
if  b[i]<n/2.0
next
else
$j=i
break
end
end
if b[$j]-n/2.0 < n/2.0-b[$j-1]
r=b[$j]
else
r=b[$j-1]
end
print("#{n} #{r}")

Measured memory_bytes: 12032
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		StringBuilder edit = new StringBuilder();
		int j = 0;
		for(int i=0; i<str.length(); i++){
			if(str.charAt(i)!='B'){
				edit.append(str.charAt(i));
				j++;
			}else{
				j--;
				if(j>=0){
					edit.deleteCharAt(j);
				}else{
					j = 0;
				}
			}
		}
		System.out.println(edit);
	}
}

Measured memory_bytes: 9812
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(accumulate(map(int, input().split())))
    b = tuple(accumulate(map(int, input().split())))
    r = bisect(b, k)

    for i1, ae in enumerate(a):
        if k < ae:
            break
        r = max(r, bisect(b, k - ae) + i1 + 1)
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 48312
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, ans;
	vector<int> p;
	
	cin>>N;
	
	p.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>p[i];
	}
	
	p.push_back(-1);
	
	for(int i = 0, con = 0; i <= N; i++){
		if(p[i] == i+1){
			con++;
		} else {
			if(con) ans += (con+1)/2;
			con = 0;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    int n;
    cin >> n;
    cout << n * n * n << endl;
}

Measured memory_bytes: 768
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    int sum=0;
    for(int i=1;i<=min(n,k);i++){
        sum+=a[i];
    }
    cout<<sum<<endl;

    return 0;
}




Measured memory_bytes: 3564
# 入力（文字だからchompつける）
s = gets.chomp

# nの数字を見つける
week = ["MON","TUE","WED","THU","FRI","SAT","SUN"]
n = week.index(s)

# 日曜日の答えを7にする処理
if n == 6
  puts 7
else
 puts 6-n
end

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong a[200005];

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

    bool f = true;
    sort(a, a + n);
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) f = false;
    }

    if (f) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 1792
//ATabc125_d
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fst first
#define scd second
using namespace std;
inline ll read() {
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int MAXN=1e5+5;
ll n,a[MAXN],dp[MAXN][2];
int main() {
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);/*syn加速*/
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	memset(dp,0xcf,sizeof(dp));
	dp[1][0]=a[1];
	for(int i=2;i<=n;++i) {
		dp[i][0]=max(dp[i-1][1],dp[i-1][0])+a[i];
		dp[i][1]=max(dp[i-1][0]-a[i-1]-a[i-1],dp[i-1][1]+a[i-1]+a[i-1])-a[i];
	}
	cout<<max(dp[n][0],dp[n][1])<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
using namespace std;

int main()
{
	int n;
	int day[100] = {0};
	
	day[0] = 0;
	day[1] = day[2] = 1;
	
	for(int i = 3; i < 50; i++){
		day[i] = day[i-1] + day[i-2] + day[i-3];
	}
	
	while(scanf("%d", &n), n != 0){
		int year;
		
		year = day[n+1] / 10 / 365;
		
		printf("%d\n", year + 1);
	}
	return(0);
}

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

int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int ans=0;
  if(a+b>=2*c){
    ans=2*c*min(x,y);
    if(a>=2*c && x>y){
      ans=ans+2*c*(x-y);
    }else if(b>=2*c && y>x){
      ans=ans+2*c*(y-x);
    }else{
      if(x>y) ans=ans+a*(x-y);
      else ans=ans+b*(y-x);
    }
  }else{
    ans=a*x+b*y;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3556
#include<stdio.h>
#include<map>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
char p[10];
int main(){
    map<char,bool>l;
    l.clear();
   scanf("%s",p);
   int s=0;
   for(int i=0;i<4;i++){
    if(!l[p[i]])
        l[p[i]]=true,s++;
   }
   if(s==2)
    printf("Yes\n");
   else
    printf("No\n");
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String S = in.next();
        int zero = 0; // 赤の個数
        int one = 0; // 青の個数
        for (int i = 0; i < S.length(); i++) { // 個数を数える
            if (S.charAt(i) == '0') zero++;
            else one++;
        }
        System.out.println(Math.min(zero, one) * 2);
    }
}


Measured memory_bytes: 26220
import java.util.Scanner;
public class Main {
	public static void main(String[] a) {
		Scanner stdIn = new Scanner(System.in);
		int b = stdIn.nextInt()*100+stdIn.nextInt()*10+stdIn.nextInt();
		if(b==110||b==1) System.out.println("Open"); else System.out.println("Close");
	}
}

Measured memory_bytes: 17360
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;





int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	
//	int a,b,c;
//	cin>>a>>b>>c;
//	if(b<a)swap(a,b);
//	if(a<=c&&c<=b)fin("Yes");
//	else fin("No");
//	
	
	int n,i,k;
	string s;
	cin>>n>>s>>k;
	char c;
	c=s[k-1];
	rep(i,n){
		if(s[i]!=c)s[i]='*';
	}
	fin(s)<<endl;
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int a,b,x; cin>>a>>b>>x;
    if(a==0) cout<<b/x+1<<endl;
    else cout<<b/x-(a-1)/x<<endl;
}


Measured memory_bytes: 256
n = list(input())
d = len(n)-1
anslist = [ None for i in range(2**d)]
for i in range(2**d):
	x = bin(i)[2:].zfill(d)
	
	s = n[0]
	for j in range(d):
		if x[j] == "1":
			s += "+" 
		s += n[j+1]
	anslist[i] = s


anslist = list(map(eval, anslist))
print(sum(anslist))

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
 
int main() {
	double r;
	cin >> r;
	cout << setprecision(20) << r*r*acos(-1) << " " << setprecision(20) << 2*r*acos(-1) << endl;
 
	return 0;
}

Measured memory_bytes: 3216
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int aaa(int t) {
	int ret;
	if (t == 1)ret = 6000;
	if (t == 2)ret = 4000;
	if (t == 3)ret = 3000;
	if (t == 4)ret = 2000;
	return ret;
}

int main() {
	rep(i, 4) {
		int t, n; cin >> t >> n;
		cout << aaa(t)*n << endl;
	}
}


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

string s;

int main() {
    cin >> s;
    int n = s.size();
    vector<int> r(n, 1), l(n, 1);

    for(int i = 0; i < n-1; i++)
        if(s[i] == 'R' && s[i+1] == 'R')  r[i+2] += r[i], r[i] = 0;

    reverse(s.begin(), s.end());
    for(int i = 0; i < n-1; i++)
        if(s[i] == 'L' && s[i+1] == 'L')  l[i+2] += l[i], l[i] = 0;
    reverse(l.begin(), l.end());

    for(int i = 0; i < n; i++)  cout << l[i] + r[i] - 1 << " \n"[i == n-1];
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    int ans = -1;
    rep(i, 5) {
        int p;
        cin >> p;
        if (p != i+1) {
            ans = i+1;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>

int main()
{
    char s[100];
    scanf("%s", s);
    int len = strlen(s);
    for (int i = 0; i < (len - 1) / 2; i++)
    {
        if (!(s[i] == s[len - i - 1]))
        {
            printf("No");
            return 0;
        }
    }
    int newlen = (len - 1) / 2;
    for (int i = 0; i < newlen / 2; i++)
    {
        if (!(s[i] == s[newlen - i - 1]))
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}




int main() {
	int a,b,k; cin >> a >> b >> k;
	
	vector<int> num;

	for (int i = 1; i <= k; i++) {
		if(a + i - 1<=b) num.push_back(a + i-1);
		if (b - i + 1 >= a) num.push_back(b - i+1);
	}
	sort(num.begin(), num.end());
	num.erase(unique(num.begin(), num.end()), num.end());

	printVec(num);

	return 0;
}

Measured memory_bytes: 256
eval'K,X,Y='+`dd`.split*",U="
l=1
x,y,*s=X.abs,Y.abs
d=x+y
x,y=y,x if f=x<y
K%2-d%2<0&&p(-1)+exit
d!=K&&(l+=[~-d/K,1].max
l+=1&d-K*l
v=K>(t=K*l-d>>1)?0:t-t=K
a=K-t
2.upto(l){s<<(u=f ?-t:a)<<a-t-u
a+=q=[x+v-a,K].min
t-=K-q})
puts l,s.map{|a|-a*=0.1<=>U=X+Y-U},X,Y

Measured memory_bytes: 10632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;cin>>S>>T;
  int SL=S.size();
  int TL=T.size();
  int m=99999999;
  for(int i=0;i<=SL-TL;i++){
    int c=0;
    for(int j=0;j<TL;j++){
      if(S[i+j]!=T[j])c++;
    }
    m=min(c,m);
  }
  cout<<m<<endl;
}


Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt();
    int a = sc.nextInt();
    double[]H = new double[n];
    double[]ans = new double[n];
    
    for(int i=0; i<n; i++) {
    	int h = sc.nextInt();
    	double x = a-(t-h*0.006);
    	x = Math.abs(x);
    	H[i] = x; 
    	ans[i] = x;
    } 	
    Arrays.sort(H);
    for(int i=0; i<n; i++) {
    if(H[0]==ans[i]) {
        	System.out.println(i+1);
      }
}
}
}

Measured memory_bytes: 38504
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <math.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;


int main() {

	// 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);

	int A, B;
	cin >> A >> B;

	int res = 0;
	int sum = 1;

	while (sum < B) {
		++res;
		sum = sum + A - 1;
	}

	cout << res << endl;
}


Measured memory_bytes: 760
<?php
fscanf(STDIN, "%d %d", $k, $n);
$single_line_input = trim(fgets(STDIN));
$single_line_input = str_replace(array("\r\n","\r","\n"), '', $single_line_input);
$A = explode(" ", $single_line_input);

$p = array();
for($i=0; $i<$n; $i++){
    if($i == $n - 1){
        $p[] =  ($k - $A[$i]) + $A[0];
    }else{
        $p[] =  $A[$i + 1] - $A[$i];
    }
}
arsort($p);
array_shift($p);
$res = array_sum($p);
echo($res);

?>

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

signed main(){
	ll n,a,b;
	cin>>n>>a>>b;


	if((b-a)%2==0){
		cout<<(b-a)/2<<endl;
	}else{
		if(a-1<n-b){
			b=b-a;
			cout<<a+(b-1)/2<<endl;
		}else{
			a=a+(n-b)+1;
			cout<<(n-a)/2+(n-b+1)<<endl;
		}
	}


	return 0;
}


Measured memory_bytes: 256
// https://serhatgiydiren.github.io

#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(char c) {
  return to_string(string(1,c));
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define D(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define D(...) 404
#endif

void solve(const int &test_id)
{
 string s;
 cin >> s;
 for(auto &e:s) if (e=='?') e='D';
 cout << s << endl;
}
            
void solve_cases()
{
 int test_cases=1;
 //cin >> test_cases;
 for(int i=1;i<=test_cases;i++) solve(i);
}

void fast_io()
{
 ios::sync_with_stdio(false);
 srand(time(NULL));
 cin.tie(0);
 cout.tie(0);
 cout << fixed << setprecision(15);
 cerr << fixed << setprecision(15);
}

int main()
{
 fast_io();
 solve_cases();
 return EXIT_SUCCESS;
}



Measured memory_bytes: 3776
import java.io.*;
import java.util.*;
import java.util.stream.*;

class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		long n = saori.saorihayami();
		long ans = 0;
		for(long i = 1;i <= n;i++){
			if(i%3 == 0||i % 5 == 0){

			} else {
				ans+=i;
			}
		}

		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 32580
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    string str;
    int count = 0;
    cin >> str;
    for (int i = 0; i < 3; i++){
        if (str[i] == '1') {
          count += 1;
        }
    }

    cout << count << endl;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))

typedef long long lint;
typedef pair<int, int> pii;

int N;
int M[110], L[110];
int S[110][20], E[110][20];

int T[110];
lint dp[2][(1<<17)];

void solve() {
	for_(i,0,N) {
		int t = 0;
		for_(j,0,M[i]) {
			int s = S[i][j], e = E[i][j];
			s -= 6; e -= 6;
			for_(k,s,e) t |= 1 << k;
		}
		T[i] = t;
	}
	
	minit(dp, -1);
	dp[0][0] = 0;
	
	for_(i,0,N) {
		int nw = i % 2, nx = (i + 1) % 2;
		int t = T[i];
		
		for_(j,0,(1<<17)) {
			if (dp[nw][j] < 0) continue;
			
			dp[nx][j] = max(dp[nx][j], dp[nw][j]);
			
			int ands = j & t;
			if (ands != 0) continue;
			
			int ors = j | t;
			dp[nx][ors] = max(dp[nx][ors], dp[nw][j] + (lint)L[i]);
		}
	}
	
	lint ans = 0;
	for_(i,0,(1<<17)) ans = max(ans, dp[N % 2][i]);
	cout << ans << endl;
}

int main() {
	while (cin >> N, N) {
		for_(i,0,N) {
			cin >> M[i] >> L[i];
			for_(j,0,M[i]) {
				cin >> S[i][j] >> E[i][j];
			}
		}
		solve();
	}
	return 0;
}

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

#define limit (int)(1e5 + 5)
// #define mod (int)(1e9 + 7)
#define pb push_back
#define fi first
#define se second

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;


lli a[limit],cou[limit] = {0};
int main() {

	lli n,s=0;
	cin >> n;

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

	lli q,b,c,t;
	cin >> q;

	for (int i = 0; i < q; ++i)
	{
		cin >> b >> c;

		t = cou[b];
		cou[b] = 0;
		cou[c] += t;

		s += (c-b)*t;

		cout << s << "\n";
	}
	return 0;
}

Measured memory_bytes: 5180
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;

int f[31][31][31][31];

int main()
{
	int w, h;

	while (cin >> w >> h && w){
		clr(f);
		rep(i, h){
			rep(j, w - 1){
				int t;
				cin >> t;
				if (t){
					f[i][j][i][j + 1] = 1;
					f[i][j + 1][i][j] = 1;
				}
			}
			if (i != h - 1)
				rep(j, w){
				int t;
				cin >> t;
				if (t){
					f[i][j][i + 1][j] = 1;
					f[i + 1][j][i][j] = 1;
				}
			}
		}
		queue<P> q;
		q.push(P(0, 0));
		int d[31][31]; clr(d);
		d[0][0] = 1;

		int ans = 0;
		while (q.size()){
			P t = q.front(); q.pop();
			int x = t.first;
			int y = t.second;

			rep(i, 4){
				int tx = x + dx[i];
				int ty = y + dy[i];

				if (cheak(tx, ty, w, h) && !f[y][x][ty][tx] && !d[ty][tx]){
					q.push(P(tx, ty));
					d[ty][tx] = d[y][x] + 1;
				}
			}
		}
		cout << d[h-1][w-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 4828
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#define MX1 200
#define MOD 1000003
#define SIZE 100005

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

ll inv[MOD],fac[MOD],finv[MOD];
void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<MOD;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll mpow(ll x,ll t)
{
	if(t==0) return 1;
	ll ret=mpow(x,t/2);
	ret=ret*ret%MOD;
	if(t%2==1) ret=ret*x%MOD;
	return ret;
}
void solve()
{
	int x,d,n;
	scanf("%d %d %d",&x,&d,&n);
	if(d==0)
	{
		printf("%lld\n",mpow(x,n));
		return;
	}
	ll f=(ll) x*inv[d]%MOD;
	ll ret=mpow(d,n);
	if(f+n-1>=MOD)
	{
		puts("0");
		return;
	}
	ret=ret*fac[f+n-1]%MOD;
	if(f>0) ret=ret*finv[f-1]%MOD;
	printf("%lld\n",ret);
}
int main()
{
	make();
	int Q;
	scanf("%d",&Q);
	while(Q--) solve();
	return 0;
}


Measured memory_bytes: 24192
a=int(input())
b=list(map(int,input().split(" ")))

def bubbleSort(lst,N):
    flag=1
    i=0
    cnt=0
    while flag:
        flag=0
        for j in range(N-1,i,-1):
            if lst[j]<lst[j-1]:
                lst[j],lst[j-1]=lst[j-1],lst[j]
                cnt+=1
                flag=1
        i+=1
    return lst,cnt
ans=bubbleSort(b,a)
print(" ".join(list(map(str,ans[0]))),ans[1],sep="\n")


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long ll;

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

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

	vector<int> l(n * 2);

	REP(i, n * 2) cin >> l[i];

	sort(ALL(l));

	int sum = 0;

	for (int i = 0; i < (n * 2); i += 2){
		sum += l[i];
	}

	cout << sum << endl;


}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int N,x,y,b,p;
  int result,min_result;

  scanf("%d",&N);
  while(N-->0){
    scanf("%d %d %d %d",&x,&y,&b,&p);
    min_result=x*b+y*p;
    if(b>=5 || p>=2){
      while(b<5){ b++; } while(p<2){ p++; }
      result=(x*b+y*p)*0.8;
      if(min_result>result) min_result=result;
    }
    printf("%d\n",min_result);
  }
  return 0;
}



Measured memory_bytes: 2140
import numpy as np

N,M=map(int,input().split())
P = []
Y = []
for i in range(M):
  p,y = map(int,input().split())
  P.append(p)
  Y.append(y)

order = (np.array(Y)).argsort()
n_list = [0]*N
m_list = [0]*M
for i in order:
  n_list[P[i]-1]+=1
  m_list[i] = n_list[P[i]-1]
  
for i in range(M):
  l = len(str(P[i]))
  pi = "0"*(6-l)+str(P[i])
  lx = len(str(m_list[i]))
  x = "0"*(6-lx)+str(m_list[i])
  print(pi+x)

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

int main() {
  
  int a, b;
  cin >> a >> b;
  
  if (0.5 * (a + b) == ((a+b)/2)*1.0 )
    cout << (a+b)/2 << endl;
  else
    cout << (a+b)/2 + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

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

   vector<char> ans;
   for(int i = 0; i < s.size(); i++){
      if(i % 2 == 0){
         ans.push_back(s[i]);
      }
   }

   for(auto ans_ : ans){
      cout << ans_;
   }
   cout << endl;

   return 0;
}

Measured memory_bytes: 640
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let d: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    // ソートしたdの中央付近の値の差が解
    let x = {
        let mut x = d.clone();
        x.sort();
        x
    };
    let ans = x[N / 2] - x[N / 2 - 1];

    println!("{}", ans);
}


Measured memory_bytes: 6396
n,m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
PR = 1000000007

dp = [[0 for j in range(m+1)] for i in range(n+1)]

for i in range(n+1):
	dp[i][0] = 1

for j in range(m+1):
	dp[0][j] = 1 

for i in range(n):
	for j in range(m):
		#aa
		sumI = 0
		sumI = dp[i+1][j]
#		for jj in range(0,j):
#			if s[i] == t[jj]:
#				sumI=(sumI + dp[i][jj]) % PR
		
		sumJ = 0
		sumJ = dp[i][j+1]
#		for ii in range(0,i):
#			if t[j] == s[ii]:
#				sumJ=(sumJ + dp[ii][j]) % PR
		
		if s[i] == t[j]:
			dp[i+1][j+1] = (sumI + sumJ) % PR
		else:
			dp[i+1][j+1] = (sumI + sumJ - dp[i][j]) % PR
#		print("i: %d j: %d  sumI: %d sumJ:%d dp[i][j]:%d" % (i+1,j+1,sumI,sumJ,dp[i+1][j+1]))

#print(dp)
print(dp[n][m])


Measured memory_bytes: 74204
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<math.h>
#include<utility> 
using namespace std;
int n;
int x[100032],y[100032];
int fa[100032],rk[100032];
pair<int,int> dot[100032];
vector<pair<long long,pair<int,int> > > ve;
long long ans;
int GetFather(int x){
	while(x!=fa[x]) x=fa[x];
	return x;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	for(int i=0;i<n;i++){
		dot[i].first=x[i];
		dot[i].second=i;
	}
	sort(dot,dot+n);
	for(int i=0;i<n-1;i++){
		int u=dot[i].second;
		int v=dot[i+1].second;
		int w=min(abs(x[u]-x[v]),abs(y[u]-y[v]));
		ve.push_back(make_pair(w,make_pair(u,v))); 
	}
	for(int i=0;i<n;i++){
		dot[i].first=y[i];
		dot[i].second=i;
	}
	sort(dot,dot+n);
	for(int i=0;i<n-1;i++){
		int u=dot[i].second;
		int v=dot[i+1].second;
		int w=min(abs(x[u]-x[v]),abs(y[u]-y[v]));
		ve.push_back(make_pair(w,make_pair(u,v))); 
	}
	ve.erase(unique(ve.begin(),ve.end()),ve.end()); 
	sort(ve.begin(),ve.end());
	int s=0;
	for(int i=1;i<=n;i++) fa[i]=i,rk[i]=1;
	for(int i=0;i<ve.size()&&s<n;i++){
		int u=ve[i].second.first;
		int v=ve[i].second.second;
		int uf=GetFather(u);
		int vf=GetFather(v);
		if(uf==vf) continue;
		s++;
		if(rk[uf]<rk[vf]) fa[uf]=vf;
		else if(rk[uf]>rk[vf]) fa[vf]=uf;
		else{
			fa[uf]=vf;
			rk[vf]++;
		}
		ans+=ve[i].first;
	} 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7792
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    A.sort()
    return A[-1] - A[0]


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 38256
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
sum = 0
N.times do |i|
    if B[i] <= A[i] then
        sum += B[i]
        A[i] -= B[i]
    else
        sum += A[i]
        rest = B[i] - A[i]
        A[i] = 0
        if rest <= A[i+1] then
            sum += rest
            A[i+1] -= rest
        else
            sum += A[i+1]
            A[i+1] = 0
        end
    end
end
puts sum

Measured memory_bytes: 15500
import java.awt.geom.Line2D;
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0; i < n; i++){
			int [][] tri = new int [4][2];
			for(int j=0; j < 3; j++){
				tri[j][0] = sc.nextInt();
				tri[j][1] = sc.nextInt();
			}
			tri[3][0] = tri[0][0];
			tri[3][1] = tri[0][1];
			int manX = sc.nextInt();
			int manY = sc.nextInt();
			int womanX = sc.nextInt();
			int womanY = sc.nextInt();
			Line2D.Double mAndw = new Line2D.Double(manX, manY, womanX, womanY);
			int intersectCount = 0;
			for(int j=0; j < 3; j++){
				Line2D.Double triLine = new Line2D.Double(tri[j][0], tri[j][1], tri[j+1][0], tri[j+1][1]);
				boolean result = mAndw.intersectsLine(triLine);
				if(result)
					intersectCount++;
			}
			if((intersectCount & 1) == 0)
				System.out.println("NG");
			else
				System.out.println("OK");
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}

}

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

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

using ll = long long;
using namespace std;

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

    int answer = 0;
    int base = 1;
    vector<int> a(n, -1);
    rep (m, _) {
      int s, c;
      cin >> s >> c;
      int j = n - s;
      if ( a[j] != -1 && a[j] != c ) {
        answer = -1;
        goto answer;
      }
      a[j] = c;
    }
    rep (n, i) {
      if ( a[i] == -1 ) {
        if ( i == n - 1 && i != 0 ) a[i] = 1; else a[i] = 0;
      }
    }
    if ( n != 1 && a[n - 1] == 0 ) {
      answer = -1;
      goto answer;
    }
    rep (n, i) {
      answer += a[i] * base;
      base *= 10;
    }

answer:
    cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

const int _maxe = 1e5;
const int _maxv = 1e5;
const long long INF = 1LL << 50;
long long ans = 0;
bool negative[_maxv];

struct edge
{
    long long from, to, cost;
};
edge es[_maxe];
long long d[_maxv];
int V, E;

void shortest_path(int s)
{
    REP(i, V)
    {
        d[i] = INF;
    }
    d[s] = 0;
    for (int loop = 0; loop < V; loop++)
    {
        REP(i, E)
        {
            edge e = es[i];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)
            {
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
}

bool find_negative_loop()
{
    //memset(d, 0, sizeof(d));
    REP(i, V)
    {
        REP(j, E)
        {
            edge e = es[j];
            if (d[e.from] == INF)
            {
                continue;
            }
            if (d[e.to] > d[e.from] + e.cost)
            {
                d[e.to] = d[e.from] + e.cost;
                negative[e.to] = true;
            }
            if (negative[e.from])
            {
                negative[e.to] = true;
            }
        }
    }
    return false;
}

int main(void)
{
    cin >> V >> E;
    REP(i, E)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        es[i].from = a;
        es[i].to = b;
        es[i].cost = -c;
    }
    shortest_path(0);
    REP(i, V)
    {
        negative[i] = false;
    }
    ans = -d[V - 1];
    find_negative_loop();
    if (negative[V - 1])
    {
        cout << "inf" << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back

#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const double pi=acos(-1);
const int N=2e3+10;
int n;

struct node{
    ll w;
    int id;
}a[N];
bool cmp(node a,node b)
{
    return a.w>b.w;
}

ll dp[N][N];
ll dfs(int pos,int  l,int r)
{
    if(pos>n) return 0;
    if(dp[l][r]!=-1) return dp[l][r];
    ll &ans=dp[l][r];

    ll t1=a[pos].w*abs(a[pos].id-r);
    ll t2=a[pos].w*abs(a[pos].id-l);
    t1+=dfs(pos+1,l,r-1);
    t2+=dfs(pos+1,l+1,r);
    ans=max(t1,t2);
    return dp[l][r];
}
int main()
{
	cin>>n;
	rep(i,1,n)
	{
	    cin>>a[i].w;
	    a[i].id=i;
	}
    sort(a+1,a+1+n,cmp);
    mem(dp,-1);
    //rep(i,1,n) printf("%d ",a[i].w);
    //puts("");

	ll ans=dfs(1,1,n);
	printf("%lld\n",ans);
}


Measured memory_bytes: 35456
import queue

def solve(maze, start):
    if maze[start[0]][start[1]] == '#':
        return 0

    q = queue.Queue()
    q.put((start, 0))

    h = len(maze)
    w = len(maze[0])

    memo = [[False] * w for _ in range(h)]
    memo[start[0]][start[1]] = True

    ans = 0

    while not q.empty():
        p, i = q.get()
        ans = i

        if p[0] < h-1 and not memo[p[0] + 1][p[1]] and maze[p[0] + 1][p[1]] == '.':
            q.put(((p[0] + 1, p[1]), i + 1))
            memo[p[0] + 1][p[1]] = True

        if p[0] > 0 and not memo[p[0] - 1][p[1]] and maze[p[0] - 1][p[1]] == '.':
            q.put(((p[0] - 1, p[1]), i + 1))
            memo[p[0] - 1][p[1]] = True

        if p[1] < w-1 and not memo[p[0]][p[1] + 1] and maze[p[0]][p[1] + 1] == '.':
            q.put(((p[0], p[1] + 1), i + 1))
            memo[p[0]][p[1] + 1] = True

        if p[1] > 0 and not memo[p[0]][p[1] - 1] and maze[p[0]][p[1] - 1] == '.':
            q.put(((p[0], p[1] - 1), i + 1))
            memo[p[0]][p[1] - 1] = True

    return ans


h, w = map(int, input().split())

maze = []
for i in range(h):
    s = list(input())
    maze.append(s)

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, solve(maze, (i, j)))

print(ans)


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

int main() {
    string S;
    cin >> S;
    int N = S.size();

    int cnt[2][2] = {{0, 0}, {0, 0}};
    for(int i = 0; i < N; i++) {
        int idx1 = S[i] - 0x30;
        int idx2 = i % 2;
        cnt[idx1][idx2] += 1;
    }
    int cnt0o1e = cnt[0][0] + cnt[1][1];
    int cnt0e1o = cnt[0][1] + cnt[1][0];

    cout << min(cnt0o1e, cnt0e1o) << endl;
}


Measured memory_bytes: 512
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A[3];
	rep(i, 0, 3)
	{
		cin >> A[i];
	}

	sort(A, A + 3);

	cout << A[0] + A[1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll d, g;
ll p[11], c[11];
int main() {
    cin>>d>>g;
    REP(i, 0, d) cin>>p[i]>>c[i];

    vector<ll> v(d);
    ll ans=inf;
    iota(v.begin(), v.end(), 0);
    do{
        ll cnt=0, sum=0;
        for(auto x : v){
            if(sum + 100*(x+1)*p[x] + c[x] >= g){
                if(sum + 100*(x+1)*(p[x]-1) >= g){
                    ll tmp=(g-sum + 100*(x+1) - 1)/(100*(x+1));
                    ans=min(ans, cnt+tmp);
                }
                else{
                    ans=min(ans, cnt+p[x]);
                }
                break;
            }
            else{
                sum+=100*(x+1)*p[x] + c[x];
                cnt+=p[x];
            }
        }
    } while(next_permutation(v.begin(), v.end()));

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

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  int a, b, c, d;
  int x, y, z, w;
  cin >> a >> b >> c >> d;
  cin >> x >> y >> z >> w;
  cout << max(a+b+c+d, x+y+z+w) << '\n';
  return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>

int main(){
  int i, j, n, sum, count;

  while(1){
    scanf("%d", &n);
    if(n == 0) break;

    for(i=1, count=0; i<=n/2; i++){
      for(j=i, sum=0; j<=n; j++){
	sum += j;
	if(sum == n){
	  count++;
	  break;
	}else if(sum > n){
	  break;
	}
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main() {
	int N;
	int tmpCnt = 0;
	int resCnt = 0;
	int i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; i=i+2) {
		tmpCnt = 0;
		for (j = 1; j <= i; j++) {
			if (i % j == 0) {
				tmpCnt++;
			}
		}
		if (tmpCnt == 8) {
			resCnt++;
		}
	}
	printf("%d\n",resCnt);
	return 0;
}


Measured memory_bytes: 128