akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <chrono>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	LL N;
	cin >> N;
	vector<LL> v(0);
	LL sum = 0;
	bool flag = false;
	REP(i, N) {
		LL a;
		cin >> a;
		if (a % 10 != 0) {
			flag=true;
		}
		v.push_back(a);
		sum += a;
	}
	SORT(v);
	if (flag) {
		if (sum % 10 == 0) {
			REP(i, v.size()) {
				if (v[i] % 10 != 0) {
					cout << sum - v[i] << endl;
					break;
				}
			}
		}
		else {
			cout << sum << endl;
		}
	}
	else {
		cout << 0 << endl;
	}
	
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int nax=(int)1e5+7;
int n,m;
int sol;
vector <int> bs[nax];

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

        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
                int a,b;
                cin>>a>>b;
                a=m-a+1;
                if(a>=0)
                        bs[a].push_back(b);
        }

        priority_queue <int> q;
        for(int i=m;i>=1;i--)
        {
                for(auto &b : bs[i])
                        q.push(b);
                if(!q.empty())
                {
                        sol+=q.top();
                        q.pop();
                }
        }
        cout<<sol<<"\n";

        /// toate devin valide de atunci, iau una pe zi

        return 0;
}
/**

**/


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

int main() {
  ll l;
  cin >> l;
  ll r=0;
  while(mpow(2,r+1)<=l) r++;
  vec a,b,c;
  for(ll i=1;i<=r;i++) {
    a.push_back(i);
    b.push_back(i+1);
    c.push_back(0);
    a.push_back(i);
    b.push_back(i+1);
    c.push_back(mpow(2,i-1));
  }
  for(ll i=r;i;i--) {
    if(l-mpow(2,i-1)>=mpow(2,r)) {
      a.push_back(i);
      b.push_back(r+1);
      c.push_back(l-mpow(2,i-1));
      l-=mpow(2,i-1);
    }
  }
  cout << r+1 << " " << a.size() << endl;
  for(ll i=0;i<a.size();i++) {
    cout << a[i] << " " << b[i] << " " << c[i] << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
#define eps (1e-10)
struct point{
    double x,y;
    point(double x=0,double y=0):x(x),y(y){}
    point operator +(point a){
        return point(x+a.x,y+a.y);
    }
    point operator -(point a){
        return point(x-a.x,y-a.y);
    }
}p[5];
typedef point vector;
double cross(vector a,vector b){
    return a.x*b.y-a.y*b.x;
}
double dot(vector a,vector b){
    return a.x*b.x+a.y*b.y;
}
double norm(vector a){
    return a.x*a.x+a.y*a.y;
}
int ccw(point p1,point p2,point p3){
    vector a=p2-p1,b=p3-p1;
    if(cross(a,b)>eps) return 1;
    if(cross(a,b)<-eps) return -1;
    if(dot(a,b)<-eps) return 2;
    if(norm(a)<norm(b)) return -2;
    return 0;
}
bool intersect(point p1,point p2,point p3,point p4){
    return (((ccw(p1,p2,p3)*ccw(p1,p2,p4))<=0)&&((ccw(p3,p4,p1)*ccw(p3,p4,p2))<=0));
}
int main(){
    int n;
    double x,y;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        for(int j=1;j<=4;++j){
            scanf("%lf%lf",&x,&y);
            p[j]=point(x,y);
        }
        if(intersect(p[1],p[2],p[3],p[4])) printf("1\n");
        else printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 2736
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    set<int> ans;
    vector<vector<int>> check(n + 1);

    int back = n / 2 + 1;
    for (int i = back; i <= n; i++) {
        if (a[i]) {
            ans.insert(i);
        }
    }

    for (int i = 1; i < back; i++) {
        int count = n / i;
        for (int k = 1; k <= count; k++) {
            check[i].push_back(i * k);
        }
    }
    for (int i = back - 1; i >= 1; i--) {
        int ball = 0;
        for (auto e : check[i]) {
            if (ans.count(e) == 1) {
                ball++;
            }
        }

        if (ball % 2 != a[i]) {
            ans.insert(i);
        }
    }

    cout << ans.size() << endl;
    for (auto e : ans) {
        cout << e << ' ';
    }

    return 0;
}


Measured memory_bytes: 24436
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
const int N=505;
int a[N],n,res;
int main(){
	scanf("%d",&n);
	fp(i,1,n<<1)scanf("%d",&a[i]);
	sort(a+1,a+1+(n<<1));
	fp(i,1,n)res+=a[(i<<1)-1];
	printf("%d\n",res);
	return 0;
}

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

int main(){
	int A, B;
	cin >> A >> B;
	if(A >= 13){
		cout << B;
	}else if(A <= 12 and A >= 6){
		cout << B/2;
	}else{
		cout << 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main(){
	vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    int num=0, ans =0;
    for(int i = 0; i < 3; ++i){
if(a[i]%2==1){++num;}
}
if(num==1){++ans;
    for(int i = 0; i < 3; ++i){
if(a[i]%2==1){--a[i];}
}
}
if(num==2){++ans;
for(int i = 0; i < 3; ++i){
if(a[i]% 2==0){--a[i];}
}
}

    ans += (a[2]-a[0])/2;
    
    ans += (a[2]-a[1])/2;
    
	cout << ans << endl;
    return 0;
}

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

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

  ll c = min(b - 1, n);
  if (c == 0) {
    cout << 0 << endl;
  } else {
    cout << a * c / b << endl;
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  long long sumodd = 0;
  long long sumeven = 0;
  long long amax = a[0];
  int max_i = 0;
  for (int i=0; i<N/2; i++){
    sumodd += max(a[2*i],(long long)0);
    if (amax<a[2*i]){
      amax = a[2*i];
      max_i = 2*i;
     }
    sumeven += max(a[2*i+1],(long long)0);
    if (amax<a[2*i+1]){
      amax = a[2*i+1];
      max_i = 2*i+1;
     }
  }
  if (N%2 == 1) {
    sumodd += max(a[N-1],(long long)0);
    if (amax < a[N-1]) {
      amax = a[N-1];
      max_i = N-1;
    }
  }
  if (amax < 0){
    cout << amax << endl;
    cout << N-1 << endl;
    for (int i=N-1; i>max_i; i--) cout << i+1 << endl;
    for (int i=0; i<max_i; i++) cout << 1 << endl;
    return 0;
  }
  cout << max(sumeven, sumodd) << endl;
  vector<int> manu;
  int i = 0;
  int count = 0;
  if (sumodd < sumeven){
    manu.push_back(1);
    i++;
    count++;
  }
  while (a[i] < 0){
    manu.push_back(1);
    manu.push_back(1);
    i += 2;
    count += 2;
  }
  while(i<N-1){
    if (i+2 > N-1){
      manu.push_back(2);
      i += 2;
      count++;
    } else if (i+2 == N-1){
        if (a[i+2] >= 0){
          manu.push_back(2);
          count++;
          i += 2;
        }
        else {
          manu.push_back(3);
          manu.push_back(2);
          count += 2;
          i += 2;
        }
    } else if (a[i+2] < 0){
      manu.push_back(3);
      i += 2;
      count++;
    } else {
      manu.push_back(2);
      i += 2;
      count++;
    }
  }
  cout << count <<endl;
  for (int x:manu){
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
//#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e9;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}


int inf=pow(2,31)-1;
int size=1;
vector<int> tree;
void init(int n){
  while(size<n)size*=2;
  tree.assign(size*2,0);
}

//Range add Query
void add(int l,int r,int x){
  l+=size,r+=size;
  for(;l<r;l/=2,r/=2){
    if(l%2==1)tree[l++]+=x;
    if(r%2==1)tree[--r]+=x;
  }
  return ;
}

int getvalue(int i){
  i+=size;
  int res=tree[i];
  while(i/=2){
    res+=tree[i];
  }
  return res;
}


int main(){
  int n,q;
  cin>>n>>q;
  init(n);
  rep(i,q){
    int t;
    cin>>t;
    if(t){
      int u;
      cin>>u;
      u--;
      cout<<getvalue(u)<<endl;
    }else{
      int s,t,x;
      cin>>s>>t>>x;
      s--;
      add(s,t,x);
    }
  }
 return 0;
}



Measured memory_bytes: 3888
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include <numeric>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int A, B;
    cin >> A >> B;

    if(A*B%2==0){
        p("No");
    }else{
        p("Yes");
    }
    
    return 0;
}

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

using namespace std;

int num = 0;

void Show(vector<vector<int>> &data, vector<list<int>> &ans, int a, int b, int c, int d) {
	if (data[a][b] & 1) {
		ans[0].push_back(a);
		ans[1].push_back(b);
		ans[2].push_back(c);
		ans[3].push_back(d);
		data[c][d]++;
		num++;
	}
	return;
}

int main(void) {
	int h, w, i, j;
	cin >> h >> w;
	h++; w++;
	vector<vector<int>> d(h, vector<int>(w, 0));
	vector<list<int>> ans(4);
	for (i = 1; i < h; i++) {
		for (j = 1; j < w; j++) {
			scanf("%d", &d[i][j]);
		}
	}
	for (i = 1, j = 1; i < h; i++) {
		for (; j < w - 1; j++)
			Show(d, ans, i, j, i, j + 1);
		if (i == h - 1)
			break;
		Show(d, ans, i, j, i + 1, j);
		i++;

		for (; j > 1; j--)
			Show(d, ans, i, j, i, j - 1);
		if (i == h - 1)
			break;
		Show(d, ans, i, j, i + 1, j);
	}
	cout << num << "\n";
	auto i0 = ans[0].begin();
	auto i1 = ans[1].begin();
	auto i2 = ans[2].begin();
	auto i3 = ans[3].begin();
	for (; i0 != ans[0].end(); i0++, i1++, i2++, i3++)
		printf("%d %d %d %d\n", *i0, *i1, *i2, *i3);
	return 0;
}

Measured memory_bytes: 18816
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll  long long
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// using ll = long long;
bool fun(ll int n,vector<ll int>digits)
{
    while(n>0)
    {
        int rem = n%10;
        for(int i=0;i<digits.size();i++)
        {
            if(rem == digits[i])
            return 0;
        }
        n /=10;
    }
    return 1;
}
int main()
{
    ll int n,m;
    cin >> n >> m;
    std::vector<ll int>digits(m);
    for(int i=0;i<m;i++)
    cin >> digits[i];
    while(1)
    {
        if(fun(n,digits))
        break;
        n++;
    }
    cout << n;
}

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

int n;
std::vector<ll> vec;
std::vector<ll> n2;

int main() {
    std::cin >> n;
    vec.assign(n-1, 0);
    n2.assign(n, -1);
    for (int i = 0; i < n-1; i++) {
        std::cin >> vec[i];
    }
    for (int i = vec.size()-1; i >= 0; i--) {
        if (n2[i+1] == -1 || n2[i+1] > vec[i]) {
            n2[i+1] = vec[i];
        }
        if (n2[i] == -1 || vec[i] < n2[i]) {
            n2[i] = vec[i];
        }
    }
    ll ans = 0;
    for (int i = 0; i < n2.size(); i++) {
        ans += n2[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import sys
input=sys.stdin.readline #文字列入力はするな！！
sys.setrecursionlimit(10**9) #再帰の上限をあげる

n=int(input())
a=list(map(int,input().split()))

z=[0]*(10**6+1)
for i in a:
    z[i]+=1

x=[-1]*(10**6+1) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**6:
    if x[i]==-1:
        x[i]=i
        prime.append(i)
    for j in prime:
        if i*j>10**6 or j>x[i]:break
        x[j*i]=j
    i+=1

ans=0
for i in a:
    f=0
    u=i
    if z[u]>=2:
        f=1
    w=[[1,0]]
    p=x[u]
    cnt=1
    while u>1:
        if p==x[u//p]:
            cnt+=1
            u=u//p
        else:
            w.append([p,cnt])
            cnt=1
            u=u//p
            p=x[u]
    m=len(w)

    def s(d,y):
        global m
        global i
        global f
        if d==m-1:
            p=y
            if p!=i and z[p]>=1:
                f=1
        else:
            for j in range(w[d+1][1]+1):
                s(d+1,y*(w[d+1][0]**j))

    s(0,1)
    if f==0:
        ans+=1
print(ans)


Measured memory_bytes: 121704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int mi = min(A, min(B, C));
    A -= mi, B -= mi, C -= mi;
    int ans = A + B + C;
    if(A == 0)
        ans -= min(B, C) / 2 * 3;
    else if(B == 0)
        ans -= min(A, C) / 2 * 3;
    else
        ans -= min(A, B) / 2 * 3;
    cout << ans << endl;
    return 0;
}


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

#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define REP(i,n) FOR(i,0,n)

#define MOD 10e9+7

using namespace std;

int main(){
int A,B;
cin >> A >> B;
cout << (A<=5 ? 0 : (A<=12 ? B/2:B)) << endl;
return 0;
}


Measured memory_bytes: 3628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<arr.length;i++){
			arr[i] = sc.nextInt();
		}
		int c=0;
		for(int i=0;i<arr.length;i++){
			int mini = i;
			for(int j=i;j<arr.length;j++){
				if(arr[j]<arr[mini])
					mini = j;
			}
			if(i!=mini){
				int tmp = arr[i];
				arr[i] = arr[mini];
				arr[mini] = tmp;
				c++;
			}
		}
		for(int i=0;i<arr.length;i++){
			if(i!=arr.length-1)
				System.out.print(arr[i]+" ");
			else
				System.out.println(arr[i]);
		}
		System.out.println(c);
	}
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

const int N = 1e5 + 5;
 
const int MOD = 1e9 + 7;


int minCost(vector<int> a)
{
    int n = a.size();
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);

    for(int i = 2; i < n; i++)
        dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1]));
    return dp[n - 1];
}
            
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    cout << minCost(a) << endl;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{int k;
 cin >> k;
 
 int ans;
 if(k%2==0) ans = k*k/4;
 if(k%2==1) ans = (k/2) *(k/2 + 1);
 
 cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  int a,b;
  string h[100];
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>h[i];
    cout<<h[i]<<endl;
    cout<<h[i]<<endl;
  }
}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

takahashi = 0
aoki = 0

while A > 0:
  A = A - D
  takahashi += 1

while C > 0:
  C = C - B
  aoki += 1

# print(takahashi)
# print(aoki)

if aoki <= takahashi:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9120
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)

long long M = 1000000007;

int n;
vector<long long> dp,dpz;
vector<vector<int>> G,GG;

long long solve(int u){
    dp[u] = 1;
    for(auto v:G[u]){
        if(dp[v]==-1){
            GG[u].push_back(v);
            dp[u] *= (solve(v) + 1);
            dp[u] %= M;
        }
    }
    return dp[u];
}

void solve2(int u){
    int k = GG[u].size();
    vector<long long> l(k+1,1),r(k+1,1);
    // cout<<u<<endl;
    for(int i=0;i<k;++i){
        l[i+1] = l[i] * (1 + dp[GG[u][i]]);
        l[i+1] %= M;
    }
    for(int i=k-1;i>-1;--i){
        r[i] = r[i+1] * (1 + dp[GG[u][i]]);
        r[i] %= M;
    }
    for(int i=0;i<k;++i){
        dpz[GG[u][i]] *= (dpz[u] + 1);
        dpz[GG[u][i]] *= l[i];
        dpz[GG[u][i]] %= M;
        dpz[GG[u][i]] *= r[i+1];
        dpz[GG[u][i]] %= M;
        // cout<<l[i]<<" "<<r[i+1]<<" "<<dpz[GG[u][i]]<<endl;
        solve2(GG[u][i]);
    }
}

int main(int argc, char const *argv[]) {
    cin>>n>>M;
    G = vector<vector<int>>(n);
    GG = vector<vector<int>>(n);
    dp = vector<long long>(n,-1);
    dpz = vector<long long>(n,1);
    dpz[0] = 0;
    for(int i=0;i<n-1;++i){
        int u,v;cin>>u>>v;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    long long res = 1;
    res = solve(0);
    // cout<<res<<endl;
    solve2(0);
    // cout<<dpz[0]<<endl;
    // for(int i=0;i<n;++i){
    //     cout<<dp[i]%M<<endl;
    // }
    // cout<<endl;
    for(int i=0;i<n;++i){
        cout<<(dp[i] * (dpz[i] + 1 ))%M<<endl;
    }
    return 0;
}

Measured memory_bytes: 23424
#include<stdio.h>
 
int main(void){
    int a, b;
    scanf("%d %d",&a ,&b);
    if(a<b){
        printf("a < b\n");
    }
    else if(a>b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}

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

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int n  = sc.nextInt();
		
		
		int[][] arr = new int[n][3];
		
		for(int i =0 ; i < n ; i++){
			arr[i][0] = sc.nextInt();
			arr[i][1] = sc.nextInt();
			arr[i][2] = arr[i][0]+arr[i][1];
		}
		
		Arrays.sort(arr, (ar1,ar2) -> -Integer.compare(ar1[2],ar2[2]));

		long ans[] = new long[2];
		int now = 0;
		for(int i = 0; i < n ; i++){
			ans[now] += arr[i][now];
			now = 1 - now;
		}
		
		System.out.println(ans[0]-ans[1]);
	}
}


Measured memory_bytes: 94840
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
b_list = []
c_list = []

for i in range(Q):
    b, c = list(map(int, input().split()))
    b_list.append(b)
    c_list.append(c)
data = dict()
for a in A:
    if a in data:
        data[a] += 1
    else:
        data[a] = 1
ans = sum(A)
for i in range(Q):
    if b_list[i] in data:
        ans += (c_list[i] - b_list[i]) * data[b_list[i]]
        num = data.pop(b_list[i])
        if c_list[i] in data:
            data[c_list[i]] += num
        else:
            data[c_list[i]] = num
    print(ans)



Measured memory_bytes: 95936
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		for(int i = 0 ; i < n ; i++) ou.print("ACL");
		ou.println();
		ou.flush();
	}
}

Measured memory_bytes: 35784
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
#include <set>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)

int main() {
    ll ans=0, H, W, M;
    cin >> H >> W >> M;
    vector<ll> h(M), w(M);
    vector<ll> row(H+1), col(W+1);
    rep(i,M) {
        cin >> h[i] >> w[i];
        row[h[i]]++;
        col[w[i]]++;
    }
    auto r = *max_element(begin(row), end(row));
    auto c = *max_element(begin(col), end(col));
    ll mr=0, mc=0;
    rep(i,H+1) {
        if (row[i] == r)
            mr++;
    }
    rep(i,W+1) {
        if (col[i] == c)
            mc++;
    }
    ll d = 0;
    rep(i,M) {
        if (row[h[i]] == r && col[w[i]] == c)
            ++d;
    }
    ans = r + c;
    if (mr * mc == d)
        --ans;
    cout << ans << endl;
}


Measured memory_bytes: 12324
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    string s, t, r;
    cin >> s >> t;
    if(t.length() == s.length()+1){
        if(t.substr(0,s.length()) == s)
        cout << "Yes";
        else
            cout << "No";
    }
    else{
        cout << "No";
    }

    return 0;
}


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

using namespace std;

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, k;

    string s;

    cin >> n >> k >> s;

    s[k-1] = tolower(s[k-1]);

    cout << s;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        int num = 0;
        for (int i = 0; i < 4; i++) {
            char c = s.charAt(i);
            if (c == '+') {
                num++;
            } else {
                num--;
            }
        }
        int result = num;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#define N 44

int Fib(int);

int F[N];

int main()
{
  int x,fib;

  scanf("%d",&x);

  fib = Fib(x);

  printf("%d\n",fib);

  return 0;
}

int Fib(int n)
{
  int fib;

  if(n == 0 || n == 1) return F[n] = 1;

  if(F[n] != 0) return F[n];

  return F[n] = Fib(n-2) + Fib(n-1);
}

  



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

// i --> 0 - 9までの数字
// sum --> 合計値
// cnt --> 和がSとなる組み合わせの数
// total --> 足す数(N個まで足す)
int N, S, cnt;
void dfs( int i, int sum, int total )
{
    //N回を満たしている 且つ 合計がSに達したものをcountする
    if( total == N && sum == S )
    {
        cnt++;
        return;
    }
    //0-9まで探索したら or 足す回数がN回に達したら 終わり
    if( i == 10 || total == N ) return;
    
    //合計に i を足す場合 -> 足す回数を +1 する
    dfs( i + 1, sum + i, total + 1 );
    //合計に i を足さない場合
    dfs( i + 1, sum, total );
}
int main()
{
    while( cin >> N >> S )
    {
        if( N == 0 && S == 0 ) break;
        //合計値の初期化
        cnt = 0;
        //dfs( 数字の0から, 合計値0から, 足す数字0から)
        dfs( 0, 0, 0 );
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
import numpy as np

H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]

def del_blank_row(a):
    del_flg = []
    for row in range(len(a)):
        if a[row].count(".") == len(a[row]):
            del_flg.append(1)
        else:
            del_flg.append(0)
    a = [a[idx] for idx in range(len(a)) if del_flg[idx] == 0]
    return a

a = del_blank_row(a)
a = np.array(a).T.tolist()
a = del_blank_row(a)
a = np.array(a).T.tolist()

for row in range(len(a)):
    print("".join(a[row]))

Measured memory_bytes: 14536
from itertools import product
import copy

h,w,k = map(int, input().split())
cl = []
b_cnt = 0
for _ in range(h):
    row = list(input())
    cl.append(row)
    b_cnt += row.count('#')

# print(b_cnt)

pattern = 2
# ite_h = product(range(pattern),repeat=h)
# ite_w = product(range(pattern),repeat=w)
ite = product(range(pattern),repeat=h+w)
ans = 0

for it in ite:
    curr_it = list(it)
    it_h = curr_it[:h]
    it_w = curr_it[h:]

# for it_h in ite_h:
#     for it_w in ite_w:
    curr_cl = copy.deepcopy(cl)
    cnt = 0
    for hi in range(h):
        if it_h[hi] == 0: continue
        for wi in range(w):
            if curr_cl[hi][wi] == '#':
                curr_cl[hi][wi] = 'r'
                cnt += 1
    for wi in range(w):
        if it_w[wi] == 0: continue
        for hi in range(h):
            if curr_cl[hi][wi] == '#':
                curr_cl[hi][wi] = 'r'
                cnt += 1

    if b_cnt-cnt == k:
        ans += 1
    # print()
    # print(it_h, it_w)
    # print(curr_cl)
    # print(cnt)

print(ans)

Measured memory_bytes: 79596
/****************************
    > File Name: a.cpp
    > Author: caoyu01
  	> Mail: yalecyu@gmail.com 
    > Created Time: 2016年10月29日 星期六 20时22分53秒
*****************************/
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cle(x) memset(x,0,sizeof(x))
#define rep(i,x) for(int i=0;i<x;i++)
#define Rep(i,x) for(int i=1;i<=x;i++)
const int N = 1000+10;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
int n;
string s,t;
int check(int x){
  rep(i,x){
    if(t[i]!=s[n-x+i]){
      return 0;
    }
  }
  return 1;
}
int main()
{
  //freopen("in.txt","r",stdin);
  while(cin>>n>>s>>t){
    int ans=n*2;
    for(int i=n;i>=0;i--){
      if(check(i)){
        ans=ans-i;
        break;
      }
    }
    cout<<ans<<endl;
  }
	return 0;
}


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

int main()
{
	ll n;
    cin>>n;
    string s;
    ll a=0,b=0,c=0,d=0;
    
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        if(s=="AC")
        {a++;}
        if(s=="WA")
        {b++;}
        if(s=="TLE")
        {c++;}
        if(s=="RE")
        {d++;}
        
    }
  cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
   cout<<"WA"<<" "<<"x"<<" "<<b<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<c<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<d<<endl;

    return 0;
}

Measured memory_bytes: 3624
#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 h,w,n;
    cin >> h >> w >> n;
    int k = max(h,w);
    cout << ((n-1)/k+1) << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;

    int ret = 0;
    rep(i, N) {
        int a = A[i];
        int b = B[i];
        int c = C[i];
        if (a == b && b == c) {
            // nothing
        } else if (a == b || b == c || a == c) {
            ret++;
        } else {
            ret += 2;
        }
    }

    cout << ret << endl;

    return 0;
}


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

using namespace std;

int divby3(int x)
{
 if(x%3==0)
   return 1;
 else
   return 0;
}
int divby5(int x)
{
 if(x%5==0)
   return 1;
 else
   return 0;
}


int main()
{
  long long int n=0,sum=0;
  cin>>n;
  
  for(int i=1;i < n+1;i++)
  {
    if(divby3(i) && divby5(i))
      continue;
    else if(divby3(i))
      continue;
    else if(divby5(i))
      continue;
    else
      sum =sum+i;
  }
  cout<<sum;
}

Measured memory_bytes: 3644
p = input().split()
n,x = int(p[0]),int(p[1])
ls = input().split()
s = 0
l = 0
for i in range(n):
    s += int(ls[i])
    if s > x:
        print(i+1)
        l = 1
        break
if l == 0:
    print(n+1)

Measured memory_bytes: 3060
#include<stdio.h>
 
int main(void){
   int x,y,i,j;
   for(;;){
      scanf("%d %d",&y,&x);
      if(x+y==0) break;
      for(i=0;i<y;i++){
         for(j=0;j<x;j++)
            if((i+j)%2==0)
               printf("#");
            else
               printf(".");
         printf("\n");
      }
   printf("\n");
   }
   return 0;
}


Measured memory_bytes: 2052
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

S = I()
K = I()

if len(list(set(str(S)))) == 1:
    print(str(S)[0])
    exit()

first_non_one_number = None
for idx, i in enumerate(str(S)):
    if i != '1':
        first_non_one_number = idx
        break

if K-1 < first_non_one_number:
    print(1)
    exit()
else:
    print(str(S)[first_non_one_number])


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

int main(){
  int k,x;
  cin >> k >> x;
  for(int i=x-k+1; i<=x+k-1; i++){
	cout << i;
    if(i != x+k-1){
	  cout << ' ';
    }
  }
  cout << '\n';
}


Measured memory_bytes: 256
S = input()
def func():
    from collections import Counter as c
    ev,od = [],[]
    for i in range(len(S)):
        ev.append(S[i]) if i%2 == 0 else 0
        od.append(S[i]) if i%2 == 1 else 0
    ev = c(ev).most_common()
    od = c(od).most_common()
    if len(od) == 0:
        return 0
    if ev[0][0] != od[0][0]:
        return len(S)-ev[0][1]-od[0][1]
    else:
        if len(ev) == len(od) == 1:
            return len(S)//2
        else:
            return min(len(S)-ev[0][1]-od[-1][1],len(S)-ev[-1][1]-od[0][1])
print(func())

Measured memory_bytes: 4476
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    string w;
    cin >> w;
    int kai[26] = {};
    for(int i=0; i<w.size(); i++){
        kai[w[i]-'a']++;
    }
    for(int i=0; i<26; i++){
        if(kai[i]%2 == 1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
const int    dx[]={-1,0,0,1};
const int    dy[]={0,-1,1,0};
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N;cin>>N;
  double T,A;cin>>T>>A;

  int ans=0;
  double d=INF;
  for(int i=1;i<=N;i++){
    int h;cin>>h;
    double temp=T-h*0.006;
    double tempd=abs(A-temp);
    if(tempd<d){
      d=tempd;
      ans=i;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))


#define fr(i, n) for(ll i=0; i<n;i++)
#define fr1(i, n) for(ll i=1; i<=n;i++) 

#define readf(f) freopen(f, "r", stdin)
#define writef(f) freopen(f, "w", stdout)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"

template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

typedef long long ll;
typedef pair<int,int> pii;
bool bingo[105];
int main()
{
	// #ifndef LOCAL
 //    readf("in.txt");
 //    writef("out.txt");
 //    #endif

    int n, grid[4][4], x;

    fr(i,3)
    	fr(j,3)
    		cin>>grid[i][j];

    cin>>n;

    fr(i,n){
    	cin>>x;
    	bingo[x] = 1;
    }
    int col[3] =  {0}, row[3] = {0}, dia[2]= {0};

    fr(i,3){
    	fr(j,3){
    		if(bingo[grid[i][j]]){
    			col[j]++;
    			row[i]++;
    			if(i==j)
    				dia[0]++;
    			if((i+j) == 2)
    				dia[1]++;    			
    		}
    	}

    }
    int flg = 0;

    fr(i,3){
    	if(col[i] == 3 or row[i] == 3){
    		flg = 1;
    		break;
    	}
    }
    if(dia[0] == 3 or dia[1] == 3)
    	flg = 1;
    

    if(flg)
    	cout<<"Yes"<<nl;
    else
    	cout<<"No"<<nl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

K = int(input())
q = deque(list(range(1, 10)))
ans = 0
for _ in range(K):
  ans = q.popleft()
  if ans % 10 != 0:
    q.append(ans*10+ans%10-1)
  q.append(ans*10+ans%10)
  if ans % 10 != 9:
    q.append(ans*10+ans%10+1)
print(ans)


Measured memory_bytes: 40816
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
aa=[]

for index,item in enumerate(a):
    for _ in range(item):
        aa.append(index+1)


result=[[0]*w for _ in range(h)]

#aの位置を示す
i=0

for y in range(h):
    for x in range(w):
        #偶数段は左向き、奇数段は右向き
        if y%2==0:
            result[y][x]=aa[i]
        else:
            result[y][w-1-x]=aa[i]
        i+=1

for item in result:
    print(" ".join(map(str,item)))

Measured memory_bytes: 41072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double PI=3.14159265358979323846;

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i].first;
    a[i].second = i+1; 
  }
  sort(a.begin(), a.end());
  for(int i = 0; i < n; i++){
    cout << a[i].second << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {

	public static void main(String[] args){
		int min,max,sum;
		Scanner r = new Scanner(System.in);
		while(true){
			sum=0;
			int n = r.nextInt();
			if(n==0) break;
			max = r.nextInt();
			int s = r.nextInt();
			if(s>max){
				min=max;
				max=s;
			}else min=s;
			for(int i=2;i<n;i++){
				s = r.nextInt();
				if(s>=max) {
					sum +=max; max=s;
				}
				else if(s<=min){
					sum +=min; min=s;
				}
				else sum +=s;

			}
			System.out.println(sum/(n-2));

		}
	}

}

Measured memory_bytes: 19108
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  string s;cin>>s;
  int l[N], r[N];
  CLR(l);
  CLR(r);
  FOR(i,0,N){
    if(i) l[i] = l[i-1];
    if(s[i] == 'W') l[i]++;
  }
  for(int i = N - 1; i >= 0; i--){
    if(i < N - 1) r[i] = r[i + 1];
    if(s[i] == 'E') r[i]++;
  }
  int ans = 1e9;
  FOR(i,0,N){
    int m = 0;
    if(i) m+=l[i-1];
    if(i<N-1) m+=r[i+1];
    ans = min(ans, m);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2964
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#include<bitset>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
int a,b;
signed main(){
    a=read(),b=read();
    printf(abs(a-b)<=1?"Brown\n":"Alice\n");
    return 0;
}



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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;


template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}
bool isPrime(ll N){
	if(N<2)return false;
	if(N<4)return true;
	if((N&1)==0)return false;
	if(N%3==0)return false;
	ll curr=5,s=sqrt(N);
	while(curr<=s){
		if(N%curr==0)return false;
		curr+=2;
		if(N%curr==0)return false;
		curr+=4;
	}
	return true;
}
int gcd(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int x1, y1;
    int d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) {
    g = gcd(abs(a), abs(b), x0, y0);
    if (c % g) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}
int solve(){
 	int n;cin>>n;
 	if(isPrime(n)){
 		cout<<n-1<<endl;return 0;
 	}
 	n*=2;
 	int ans=n-1;
 	for(int i=1;i<=sqrt(n);i++){
 		if(n%i==0){
 			int a=i,b=-n/i;
 			int x0,y0,g;
 			find_any_solution(a,b,1,x0,y0,g);
 			int roots1=a*x0;
 			int roots2=-b*y0;
 			if(roots1>0 && roots2>0){
 				mins(ans,roots2);
 			}
 			find_any_solution(a,b,-1,x0,y0,g);
 			roots1=a*x0;
 			roots2=-b*y0;
 			if(roots1>0 && roots2>0){
 				mins(ans,roots1);
 			}

 		}
 	}
 	cout<<ans<<endl;
 	return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 3700
// Marcin Knapik
#include<bits/stdc++.h>
// #pragma GCC optimize("O3")
using namespace std;

typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
typedef long double             ld;

#define boost                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define szy                     first
#define gi                      second
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define REP(i, a, b)            for (int i = (a); i <= (b); i++)
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define TRAV(i, n)              for(auto&i:n)
#define beg(x)                  (*(x.begin()))
#define re(x)                   int x; cin >>x;   
#define f                       first
#define s                       second

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

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll T = 1 << 18;
const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll  N = (1<<21) + 7;
const int LOG = 21;

ll n, m, k;

signed main(){
    boost;

    cin >> n >> k;
    string w;
    cin >> w;
    ll ans = 0;
    for(int i = 1; i < n; i++){
    	if(w[i] == w[i-1])
    		ans++;
    }
    while(k > 0 && ans < n-1){
    	k--;
    	ans += 2;
    }
    cout << min(n-1, ans);
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int m,i,j,c,n,a[1000][100];
  int b[100];
  while(1){
    c=0;
  scanf("%d %d",&n,&m);
  if(n==0&&m==0)
    break;
  for(j=0;j<m;j++)
    b[j]=0;
  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      scanf("%d",&a[i][j]);
  for(j=0;j<m;j++)
    for(i=0;i<n;i++)
      b[j]=b[j]+a[i][j];
  for(i=1000;i>=0;i--){
    for(j=0;j<m;j++){
      if(i==b[j]){
	if(c==0){
	  printf("%d",j+1);
	  c++;
	}else
	  printf(" %d",j+1);
      }
    }
  }
  printf("\n");
  }
  return 0;
}

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

using namespace std;

int N, ap[309];
char sir[109];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s", sir + 1), N = strlen (sir + 1);
for (int i=1; i<=N; i++)
    ap[sir[i]] = i;
if (N != 26)
{
    for (int i='a'; i<='z'; i++)
        if (ap[i] == 0)
        {
            sir[++N] = i;
            break;
        }
    printf ("%s\n", sir + 1);
    return 0;
}
for (int i=N - 1; i>=0; i--)
{
    char c2 = -1;
    for (int c=sir[i + 1] + 1; c<='z'; c++)
        if (ap[c] > i)
        {
            c2 = c;
            break;
        }
    if (c2 != -1)
    {
        sir[i + 1] = c2, sir[i + 2] = 0;
        printf ("%s\n", sir + 1);
        return 0;
    }
}
printf ("-1\n");
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
typedef long long ll;
const int maxn = 2e5 + 5;
char str[10][10];
int h, w, k;
int vis_row[10], vis_col[10];
int ans = 0;

void dfs_col(int u) {
    if (u == w) {
      int cnt = 0;
      for (int i=0; i < h; i++) {
        if (!vis_row[i]) {
          for (int j=0; j < w; j++) {
             if (!vis_col[j] && str[i][j] == '#') {
               cnt++;
             }
           }
        }
      }

      if (cnt == k) {
        ans++;
      }
      return;
    }

    vis_col[u] = 0;
    dfs_col(u+1);
    vis_col[u] = 1;
    dfs_col(u+1);
}

void dfs_row(int u) {
    if (u == h) {
      dfs_col(0);
      return;
    }

    vis_row[u] = 0;
    dfs_row(u+1);
    vis_row[u] = 1;
    dfs_row(u+1);
}

int main (int argc, char **argv) {
  std::cin >> h >> w >> k;
  for (int i=0; i < h; i++) {
    for (int j=0; j < w; j++) {
       std::cin >> str[i][j];
    }
  }

  dfs_row(0);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3232
#include<stdio.h>

int main(void){

    int testnum[50000]={0};
    int testsum[50000]={0};
    int input[5];
    int i;    
    int j=0;
    int t;
    int s=0;
    int max=0;
    int min=1000;
    

    while(1){
        scanf("%d",&testnum[s]);
        if(testnum[s]==0) break;

        for(i=j;i<testnum[s]+j;i++){
        scanf("%d %d %d %d %d",&input[0],&input[1],&input[2],&input[3],&input[4]); 
        	
            for(t=0;t<5;t++){
                testsum[i]+=input[t];
            }
        }
        j+=testnum[s];
        s++;
    }
    i=0;
    t=0;
    j=0;
    while(testnum[i]!=0){
    	t+=testnum[i];	
    for(;j<t;j++){
    	if(testsum[j]>max) max = testsum[j];
		if(testsum[j]<min) min = testsum[j];
    }
    printf("%d %d\n",max,min);
    i++;
    max=0;
    min=1000;
    }
	
    return 0;
}

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

int main() {
	string s,t;cin>>s;
  	int l=0,m=0;
  	for(int i=0;i<s.size();i++){
    	if(s[i]=='A'){ l=i;break;}
    }
	for(int i=0;i<s.size();i++){
    	if(s[i]=='Z'){m=i;}
    }
  	cout<<m-l+1<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    lint n;
    scanf("%lld", &n);

    std::vector<lint> a(n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
    }

    std::map<lint, lint> m;

    for (auto ae : a)
    {
        if (m.find(ae) == m.end())
        {
            m[ae] = 1;
        }
        else
        {
            m[ae]++;
        }
    }

    lint ans = (lint)m.size();

    lint dup = 0;

    for (auto iter = m.begin(); iter != m.end(); iter++)
    {
        dup += iter->second - 1;
    }

    if (dup % 2 == 0)
        printf("%lld", ans);
    else
        printf("%lld", ans - 1);

    return 0;
}


Measured memory_bytes: 7296