akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main()
{
	int a, b, c;
	
	while(scanf("%d %d %d", &a, &b, &c) != EOF)
	{
		if(a == -1 && b == -1 && c == -1)
		{
			break;
		}
		if((a == -1 || b == -1) && c == -1)
		{
			printf("F\n");
		}
		else 
		{
			int sum = 0, k = 0;
			if(a >= 0)
			{
				sum += a;
			}
			if(b >= 0)
			{
				sum += b;
			}
			if(sum >= 80)
			{
				printf("A\n");
			}
			else if(sum >= 65 && sum < 80)
			{
				printf("B\n");
			}
			else if((sum >= 50 && sum < 65) || c >= 50)
			{
				printf("C\n");
			}
			else if(sum >= 30 && sum < 50)
			{
				printf("D\n");
			}
			else 
			{
				printf("F\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2680
#include <iostream>
#include<algorithm>
using namespace std;
const int  maxn = 20;
int a[maxn][maxn];
int ans = 1e9;
int n,m,x;
int Get[maxn];
int c[maxn];
int pay = 0;
int check()
{
    for(int i=0;i<m;i++)
    {
        if(Get[i]<x) return 0;
    }
    return 1;
}
void dfs(int u)
{
    if(u==n)
    {
        if(check())
        {
            if(pay<ans) ans = pay;
        }
        return ;
    }
    pay+=c[u];
    for(int i=0;i<m;i++)  Get[i]+=a[u][i];
    dfs(u+1);
    for(int i=0;i<m;i++)  Get[i]-=a[u][i];
     pay-=c[u];
     dfs(u+1);
}
int main()
{
    cin>>n>>m>>x;
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
   dfs(0);
    if(ans!=1e9) cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
#define LLINF 1145148101919
#define PI 3.14159265359
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

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

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

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

int ctoi_alpha(char c)
{
    if (c >= 'a' && c <= 'z')
    {
        return c - 'a';
    }
    return 0;
}

void swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////

int main()
{
    int N; cin >> N;
    ll ans=0;

    FOR(i,1,N+1){
        string res = to_string(i);
        //cout << res << endl;
        if(res.size()%2!=0) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

abc = list(sorted(map(int ,input().rstrip().split(" "))))

if len([i for i in abc if i % 2 == 0]) > 0:
    print(0)
    exit(0)

red = abc[0] * abc[1] * int(abc[2]/2)
blue = abc[0] * abc[1] * (abc[2] - int(abc[2]/2))

print(abs(red-blue))


Measured memory_bytes: 2940
#include<stdio.h>

int main(void)
{
  int n,k,x[101],i,ans=0;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++)
    {
      scanf("%d",&x[i]);
      if(k-x[i] < x[i])
	{
	  ans += (k-x[i]) * 2;
	}
      else
	{
	  ans += x[i] * 2;
	}
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll sum = a[0];
  rep(i, n - 1) sum ^= a[i + 1];
  rep(i, n) { 
    ll res = sum ^ a[i];
    cout << res << " ";
   }
   cout  << endl;
  return 0;
}

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

int main()
{
  int n,k;
  cin >> n >> k;
  
  int x,y;
  int ans[n+1] = {0};
  for(int i = 1; i <= k; i++){
    cin >> x;
    for(int j = 1; j <= x; j++){
      cin >> y;
      ans[y]++;
    }
  }
  
  int cou = 0;
  for(int i = 1; i <= n; i++){
    if(ans[i] == 0){
      cou++;
    }
  }
  
  cout << cou << endl;
    
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
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 All(v) (v).begin(), (v).end()
typedef long long ll;

int main() {
    string a, s, c;
    cin >> a >> s >> c;
    cout << a[0] << s[0] << c[0] << endl;
    return 0;
}

Measured memory_bytes: 256
// 色々な解説ブログを読んだけどあんまり腑に落ちてない
#include<iostream>
#include<numeric>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

bool ok(int x, int k, vector<int> &v){
    vector<int> y;
    for(int k : v)  y.push_back(k%x);
    sort(y.begin(), y.end());
    ll sum = accumulate(y.begin(), y.end(), 0ll);
    ll tmp = accumulate(y.begin(), y.begin()+(int)(y.size())-sum/x, 0ll);
    return tmp <= k;
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    int x = abs(accumulate(v.begin(), v.end(), 0));
    int ret = 1;
    for(int i = 1; i*i <= x; i++){
        if(x%i) continue;
        if(ok(i, k, v))    ret = max(ret, i);
        if(ok(x/i, k, v))  ret = max(ret, x/i);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    long long N, M;
    cin >> N >> M;

    vector<long long> c(N, 0);
    for (long long i = 0; i < M; i++)
    {
        long long a, b;
        cin >> a >> b;
        c[min(a, b) - 1] += 1;
        c[max(a, b) - 1] += -1;
    }

    long long t = 0;
    for (long long i = 0; i < N; i++)
    {
        t += c[i];
        if (t % 2 == 1)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let s: Vec<u32> = buf
        .trim()
        .chars()
        .map(|c| c.to_digit(10).unwrap())
        .collect();

    let cnt = (0..s.len()).filter(|&i| i % 2 == s[i] as usize).count();
    println!("{}", std::cmp::min(cnt, s.len() - cnt));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,e) for(int i=0;i<(e);++i)

int main() {
  int n;
  cin >> n;
  rep(i, n){
    int y, m, d;
    cin >> y >> m >> d;
    int ans=0;
    while(y<1000){
      ans++;
      d++;
      if (d>20){
        d = 1; m++;
      }
      else if(m%2==0 && y%3!=0 && d>19){
        d = 1; m++;
      }
      if(m>10){
        m = 1; y++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3068
def main():
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    ans = []
    for _ in range(M):
        P, X = map(int, input().split())
        ans.append(str(sum(T) - T[P - 1] + X))
    print("\n".join(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 63632
import math

N = int(input())
x = []
y = []

for k in range(N):
    #print(i)
    X, Y =  map(int,input().split())
    x.append(X)
    y.append(Y)

ans = 0    
for i in range(N):
    for j in range(N):
        tmp = math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
        ans += tmp
 
print(ans/N)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
q = int(input())
a_dic = {}

for elem in a:
    if elem not in a_dic:
        a_dic[elem] = 1
    else:
        a_dic[elem] += 1

a_sum = sum(a)

for i in range(q):
    b, c = map(int,input().split())
    if b in a_dic:
        diff = c - b
        a_sum += diff * a_dic[b]
        print(a_sum)
        if c in a_dic:
            a_dic[c] += a_dic[b]
            del a_dic[b]
        else:
            a_dic[c] = a_dic[b]
            del a_dic[b]
    else:
        print(a_sum)

Measured memory_bytes: 20704
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <array>
#include <iomanip>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0);
using namespace std;
double dp[3005][3005];
double prob[3005][2];

int main(){
    AC
    int n;
    cin>>n;
    for(int i=1; i<=n; i++){
        double p;
        cin>>p;
        prob[i][0] = p;
        prob[i][1] = 1-p;
    }

    dp[0][0] = 1;
    for(int i=1; i<=n; i++){
        dp[i][0] = dp[i-1][0]*prob[i][1];
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(i<j)
                dp[i][j] = 0;
            else
                dp[i][j] = dp[i-1][j]*prob[i][1] + dp[i-1][j-1]*prob[i][0];
        }
    }

    double result = 0;
    for(int j=(n/2+1); j<=n; j++)
        result += dp[n][j];
    cout<<setprecision(10)<<result<<endl;
}

Measured memory_bytes: 73612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int r;
  cin >> r;
  if (r < 1200) cout << "ABC" << endl;
  else if (r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}

Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
	}
    
    let a = get!();
    let b = get!();
    
    let ans = (a - 1) * (b - 1);
    
    println!("{}", ans);
    
}

Measured memory_bytes: 4352
using System;

namespace AOJ.Volume0
{
    class Program0000
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= 9; j++)
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i*j);
                }
            }
        }
    }
}

Measured memory_bytes: 5552
N = int(input())
P = list(map(int, input().split()))

rec = N
ans = 0

for i in range(N):
    if i == 0:
        rec = P[i]
        ans += 1
    else:
        if rec > P[i]:
            ans += 1
        rec = min(rec, P[i])
print(ans)

Measured memory_bytes: 26012
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
typedef long long i64;
const int MAXN = 1e5 + 10;

i64 answer;
i64 totCnt;
i64 N, M;
i64 check[MAXN];
i64 cnt[3];

bool flag;

vector<pair<i64, i64> > Adj[MAXN];

inline void addEdge(i64 u, i64 v, i64 w)
{
	Adj[u].emplace_back(v, w);
}

void DFS(int cur)
{
	cnt[check[cur]] ++;

	for(auto x : Adj[cur])
	{
		totCnt += (x.second == 1);

		if(check[x.first] != -1)
		{
			if((check[cur] + x.second) % 3 != check[x.first])
				flag = true;
		}
		else
		{
			check[x.first] = (check[cur] + x.second) % 3;
			DFS(x.first);
		}
	}
}

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

	cin >> N >> M;
	for (int i = 1; i <= M; i++)
	{
		i64 u, v;
		cin >> u >> v;
		addEdge(u, v, 1);
		addEdge(v, u, 2);
	}

	memset(check, -1, sizeof check);

	for(int i = 1; i <= N; i++)
	{
		if(check[i] != -1)
			continue;

		check[i] = 0, totCnt = 0;
		cnt[0] = cnt[1] = cnt[2] = 0;
		flag = false;

		DFS(i);
		if(flag)
			answer += (cnt[0] + cnt[1] + cnt[2]) * (cnt[0] + cnt[1] + cnt[2]);
		else if(!cnt[0] || !cnt[1] || !cnt[2])
			answer += totCnt;
		else
			answer += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0];

	}

	cout << answer << endl ;

	return 0;
}

Measured memory_bytes: 12800
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    long long A, B, C;
    cin >> A >> B >> C;

    cout << B + min(A + B + 1, C) << endl;

}















































Measured memory_bytes: 256
def m(L,R):
 global c;c+=len(L)+len(R)
 T=[];j=0
 for l in L:
  while j<len(R)and R[j]<l:T+=[R[j]];j+=1
  T+=[l]
 while j<len(R):T+=[R[j]];j+=1
 return T
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


Measured memory_bytes: 61876
N, K = gets.chomp.split(" ").map(&:to_i)
V = gets.chomp.split(" ").map(&:to_i)

ans = 0

st = (K+1)/2; ed = K
st = N if st > N; ed = N if ed > N
(st..ed).each{|k|
  s = V[0...k].inject(:+)
  m = V[0...k].select{|v| v < 0}

  (0..k).each{|i|
    r = [K-k, m.size].min
    rt = r > 0 ? m.sort[0...r].inject(:+) : 0
    ans = (s - rt) if ans < (s - rt)
    if i < k then
      si = V[-i-1]; so = V[k-1-i]
      s += si - so
      m << si if si < 0
      m.delete_at(m.index(so)) if so < 0
    end
  }
}

puts ans


Measured memory_bytes: 1788
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var sampleText = Console.ReadLine().Split(' ');
        double s = double.Parse(sampleText[0]);
        double l = double.Parse(sampleText[1]);
        double t1 = double.Parse(sampleText[2]);
        double t2 = double.Parse(sampleText[3]);
        
        double t1kakudo = t1 * 30 + t2 * 0.5;
        double t2kakudo = t2 * 6;
        double rad = (Math.PI / 180) * Math.Abs(t1kakudo - t2kakudo);
        double result = Math.Sqrt((s * s) + (l * l) - (2.0d * s * l * Math.Cos(rad)));
        Console.WriteLine(result);

    }
  
}

Measured memory_bytes: 27888
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main() {
    ll  N;
    cin >> N;
    ll A, B;
    ll ans = MOD;
    for(int i = 1; i <= sqrt(N); i++){
        if(N % i == 0){
            A = i;
            B = N / i;
            ans = min(ans, ll(max(to_string(A).size(), to_string(B).size())));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3764
#include<stdio.h>
 int main() {
	 int x;
	 scanf("%d", &x);
	 int c500 = x / 500; // 500 円硬貨の数
	 int r500 = x % 500; // 端数
	 int c5 = r500 / 5; // 5 円硬貨の数
	 printf("%d\n", c500 * 1000 + c5 * 5);
	
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    string name, old[101];
    int sub = 0;
    string cmp;
    int ans = 0;

    cin >> n >> name;

    for (int i = 0; i < n; i++) cin >> old[i];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < old[i].size(); j++) { //開始地点
            for (int k = 1; k < 101; k++) { //文字の間隔
                if ((int)name.size() + ((k-1) * ((int)name.size() - 1)) > (int)old[i].size()) break;

                for (int l = j; l < old[i].size(); l += k) {
                    cmp += old[i][l];
                    if ((int)cmp.size() == (int)name.size()) {
//                        cout << "start:" << j << " " << "space:" << k << " " << cmp << endl;
                        if (cmp == name) {
                            ans++;
                            cmp = "";
                            goto nxt;
                        }
                        else {
                            cmp = "";
                            break;
                        }
                    }
                }
                cmp = "";
            }
        }
    nxt:;
    }

    cout << ans << endl;
}



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

int main() {
  int N,X; cin >> N >> X;
  vector<int> D(N + 1);
  D[0] = 0;
  rep(i,N) {
    int L; cin >> L;
    D[i + 1] = D[i] + L;
  }
  int ans = 0;
  rep(i,N+1) {
    if(D[i] <= X) ans++;
    else break;
  }
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
 
 
const int N=2e6+6;
const ll MOD=998244353;


int main(){
	fastio;
	ll n,a,b;
	cin>>n>>a>>b;
	if (a%2==b%2){
		cout<<abs(b-a)/2ll<<endl;
	}
	else{
		if(a>b) swap(a,b);
		//cout<<(b-a-1ll)/2ll<<endl;
		cout<<min((b-a-1ll)/2ll+a,(n-(a+n-b+1))/2ll+n-b+1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = map(int, input().split())

price = 0
if (c*2 > a+b):
    price += a*x + b*y
else:
    if (x > y):
        price = c*2 * y
        if(c*2 < a):
            price += c*2 * (x-y)
        else:
            price += a * (x-y)
    else:
        price = c*2 * x
        if(c*2 < b):
            price += c*2 * (y-x)
        else:
            price += b * (y-x)
            
print(price)

Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

const int nmax = 40, abmax = 10, inf = 1000000;
int a[nmax], b[nmax], c[nmax];
int dp[nmax + 1][nmax*abmax + 1][nmax*abmax + 1];

int main() {

	int n, ma, mb;
	cin >> n >> ma >> mb;

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

	for (int i = 0; i <= n; i++) {
		for (int ca = 0; ca <= nmax*abmax; ++ca) {
			for (int cb = 0; cb <= nmax*abmax; ++cb) {
				dp[i][ca][cb] = inf;
			}
		}
	}

	dp[0][0][0] = 0;


	//iを使ってi+1の状態を計算する。
	for (int i = 0; i < n; i++) {
		for (int ca = 0; ca <= nmax*abmax; ++ca) {
			for (int cb = 0; cb <= nmax*abmax; ++cb) {
				//iの段階で到達できないならi+1を加えることはできない。
				if (dp[i][ca][cb] == inf)continue;

				//****************注意!!!!!!!!!!****************
				//dp[i+1][ca][cb]=dp[i][ca][cb]としてWAくらいかけた
				//i+1のループ中、同じca,cbになることはあるぞ。
				dp[i + 1][ca][cb] = min(dp[i+1][ca][cb],dp[i][ca][cb]);

				//i+1を加える。当然Aの重さはa[i]増え、Bの重さはb[i]増える。
				//もともとdpテーブルに書いてあったコストと
				//[i][ca][cb]のコストにc[i]を足した
				//のうち小さい方をdpテーブルにメモする。
				dp[i + 1][ca+a[i]][cb+b[i]] = min(dp[i + 1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
			}
		}
	}
	
	//最小値の更新なので、最大値で初期化。
	int ans = inf;

	//全てのアイテムを使える状態でのdpテーブルをca,cbで順番にみていく。
	//重さの比が指定されたものになってる要素だけに着目し、
	//最小値が更新できるなら更新する。
	for (int ca = 1; ca <= nmax*abmax; ++ca) {
		for (int cb = 1; cb <= nmax*abmax; ++cb) {
			if (ca*mb == cb*ma)ans = min(ans, dp[n][ca][cb]);
		}
	}

	//一度も更新が行われなかったので、作成不能。
	//-1を出力するために代入しておく。
	if (ans == inf)ans = -1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 25984
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(b-a == c-b)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
   int n;
   cin >> n;
   cout << pow(n, 3) << endl;
   return 0; 
}

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

int f(int a, int b){
  int i=0, j=0;
  while(a){
    i += a%10;
    a /= 10;
  }
  while(b){
    j += b%10;
    b /= 10;
  }
  return i+j;
}

int main(){
  int n;
  cin >> n;
  int ans = n;
  rep(a,n){
    int b = n-a;
    if(a>=b)ans = min(ans, f(a, b));
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = [0]
cnt = 1
for i in range(1, N+1):
  d = D[i-1] + L[i-1]
  if d <= X:
    cnt = cnt + 1
  D.append(d)

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

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


int main(){
    cin>>H>>N;
    vec a(N), b(N);
    rep(i,N) cin>>a[i]>>b[i];
    mat dp(N + 1, vec(H + 1 + int(1e+4), INF));
    dp[0][0] = 0;
    ll ans = INF;
    rep(i,N){
        rep(j,H + 1 + int(1e+4)){
            dp[i+1][j] = dp[i][j];
            if(j >= a[i]) chmin(dp[i+1][j], dp[i+1][j - a[i]] + b[i]);
            if(i == N - 1 && j >= H) chmin(ans, dp[i+1][j]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 160640
#include<bits/stdc++.h>
using namespace std;
#define  vi vector<long long int>
#define  set1 set<long long int>
#define  pb push_back
#define  map1 map<long long int,long long int>
#define  ll    long long int
#define  mp make_pair
#define  inf 1e17
#define  minf INT_MIN
#define  setbits(x) __builtin_popcountll(x)
#define  pres(x,y) fixed<<setprecision(y)<<x
#define  pair1 pair<long long int,long long int>
#define  mk(arr,n,type) type *arr=new type[n];
#define  mod 1000000007
#define  pi  3.1415926535897932384626433832
#define  ins insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//find_by_order() --> returns an iterator to the k-th largest element (counting from zero)
//order_of_key()  --> the number of items in a set that are strictly smaller than our item.
#define  w(t) long long int t;t=1;while(t--)

double dp[3000][3000];

double solve1(double *a, ll i, ll x) {

	if (x == 0) {
		return 1;
	}
	if (i == 0) {
		return 0;
	}

	if (dp[i][x] > -0.9) {
		return dp[i][x];
	}

	return dp[i][x] = (a[i] * solve1(a, i - 1, x - 1)) + ((1 - a[i]) * solve1(a, i - 1, x));



}
void solve() {

	ll n;
	cin >> n;
	double a[n + 1];
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
	}
	memset(dp, -1, sizeof(dp));
	cout << pres(solve1(a, n, ((n + 1) / 2)),15);

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("inp.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	w(t) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 74300
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz jzm
#define ll long long
#define ull unsigned ll
const int N=200005;
int n, m, c;
int cnt[N], a[N], p[N];
int main() {
	scanf("%d%d", &n, &m);
	c=n;
	for (int i=0; i<n; i++) {
		scanf("%d", &a[i]);
		cnt[a[i]]++;
		int pos=a[i]-cnt[a[i]];
		if (pos>=0) {
			if (!p[pos])
				c--;
			p[pos]++;
		}
	}
	while (m--) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		int pos=a[x]-cnt[a[x]];
		if (pos>=0) {
			p[pos]--;
			if (!p[pos])
				c++;
		}
		cnt[y]++;
		cnt[a[x]]--;
		a[x]=y;
		pos=a[x]-cnt[a[x]];
		if (pos>=0) {
			if (!p[pos])
				c--;
			p[pos]++;
		}
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 3712
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

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

vector<edge> G[4096];
ll d[4096];

void dijkstra(int n, vector<edge> G[], int s, ll d[]) {
	fill(d, d + n, LLONG_MAX); d[s] = 0;
	priority_queue<ll_i, vector<ll_i>, greater<ll_i> > q;
	q.push(ll_i(0, s));
	while (!q.empty()) {
		ll_i p = q.top(); q.pop();
		int u = p.second;
		if (p.first > d[u]) continue;
		for (int i = 0; i < G[u].size(); i++) {
			edge e = G[u][i];
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				q.push(ll_i(d[e.v], e.v));
			}
		}
	}
}

int w, h;

int encode(int y, int x, int k) {
	return (y * w + x) * 4 + k;
}

int main() {
	for (;;) {
		cin >> w >> h;
		if (w == 0) break;
		vector< vector<int> > s(h + 2, vector<int>(w + 2, 4));
		for (int y = 1; y <= h; y++)
			for (int x = 1; x <= w; x++)
				cin >> s[y][x];
		h += 2; w += 2;
		vector<int> c(4);
		for (int i = 0; i < 4; i++)
			cin >> c[i];
		int n = h * w * 4;
		for (int u = 0; u < n; u++) {
			G[u].clear();
			int y = u / (w * 4);
			int x = u % (w * 4) / 4;
			int k = u % 4;
			if (x - 1 >= 0 && x + 1 < w && y - 1 >= 0 && y + 1 < h);
			else continue;
			if (s[y][x] != 4) {
				int _k = (k + s[y][x]) % 4;
				int _x = x + dx[_k], _y = y + dy[_k];
				int _u = encode(_y, _x, _k);
				edge e = {u, _u, 0};
				G[u].push_back(e);
			}
			for (int i = 0; i < 4; i++) {
				int _k = (k + i) % 4;
				int _x = x + dx[_k], _y = y + dy[_k];
				int _u = encode(_y, _x, _k);
				edge e = {u, _u, c[i]};
				G[u].push_back(e);
			}
		}
		dijkstra(n, G, encode(1, 1, 2), d);
		ll mini = LLONG_MAX;
		for (int i = 0; i < 4; i++)
			mini = min(mini, d[encode(h - 2, w - 2, i)]);
		cout << mini << endl;
	}
}

Measured memory_bytes: 2008
n = int(input())
alist = [int(x) for x in input().split()]
twolist = [536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]

count = 0
for x in alist:
  for i,num in enumerate(twolist):
    if x % num == 0:
      count += (29-i)
      break
print(count)

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

typedef long long ll;
const int N = 1e5;
const int MOD = 998244353;

ll dmod(ll x){
	return x%MOD;
}

int n;
int li[N+5];
int isi[N+5];

ll fakto[N+5];

void pre(){
	fakto[0] = 1;
	for(int i=1;i<=N;i++){
		fakto[i] = dmod(fakto[i-1] * (ll)i);
	}
	return;
}

ll fe(ll x, ll p){
	if(p==0) return 1;
	if(p==1) return x;
	ll ret = fe(x,p/2);
	ret = dmod(ret*ret);
	if(p&1) ret = dmod(ret*x);
	return ret;
}

ll nCr(ll x, ll y){
	ll ret = dmod(fakto[y] * fakto[x-y]);
	ret = fe(ret,MOD-2);
	ret = dmod(ret*fakto[x]);
	return ret;
}

int main(){
	pre();
	scanf("%d",&n);
	int mks = 0;
	for(int i=1;i<=n;i++){
		scanf("%d",&li[i]);
		isi[li[i]]++;
		mks = max(mks,li[i]);
	}
	if(li[1] != 0 || isi[0] > 1){
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=mks;i++){
		if(isi[i] == 0){
			printf("0\n");
			return 0;
		}
	}
	ll ans = 1;
	
	for(int i=1;i<=mks;i++){
//		cout << isi[i] << " " << isi[i-1] << endl;
//		cout << "nCr " << isi[i] + isi[i-1] - 1 << " , " << isi[i-1] - 1 << endl;
		ans = dmod(ans*fe(isi[i-1], isi[i]));
	}
	printf("%lld\n",ans);
	return 0;
}

/*
a + b + c = x
a , b, c >= 0
a + b + c = x+3
a,b,c > 0
x+3-1 C 2
*/


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);
 
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;
 
constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;
 
template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	int N; cin >> N;
	cout << N/2 + N%2 << endl;

    return 0;
}

Measured memory_bytes: 256
# run on python 3.4.3
from sys import stdin


def main():
    n = list(stdin.readline().strip())
    s0 = set()
    s1 = set()
    for i in range(3):
        s0.add(n[i])
    for i in range(1, 4):
        s1.add(n[i])
    ans = len(s0) == 1 or len(s1) == 1
    print(['No', 'Yes'][ans])


main()


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

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

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

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, T;
  cin >> N >> T;
  vector< int > A(N), B(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  vector< int > ord(N);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), [&](int a, int b) {
    return A[a] < A[b];
  });
  auto dp = make_v< int64 >(T + 1);
  for(auto &i : ord) {
    for(int k = T - 1; k >= 0; k--) {
      chmax(dp[min(T, k + A[i])], dp[k] + B[i]);
    }
  }
  cout << dp[T] << endl;
}


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

    int main (void){
        int x, y, z;
        cin >> x;
        cin >> y;
        cin >> z;
        if(x > y){
            int temp = x;
            x = y;
            y = temp;
        }
        if(y > z){
            int temp = y;
            y = z;
            z = temp;
        }
        if(x > y){
            int temp = x;
            x = y;
            y = temp;
        }
            
        cout << x << " " << y << " " << z << endl;
        
    }
        


Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};
#define inRange(x,a,b) (a <= x && x < b)

void rot(int r, int c, int x, vector<vector<bool>> &v){
    vector<vector<bool>> next = v;
    for(int i = 0; i < x; i++){
        for(int j = 0; j < x; j++){
            next[r+i][c+j] = v[r+x-1-j][c+i];
        }
    }
    v = next;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> a(n, vector<bool>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int x;  cin >> x;
            a[i][j] = (x==1);
        }
    }
    int r, c, x, ang;
    while(m--){
        int op;
        cin >> op;
        if(op == 0){
            cin >> r >> c >> x >> ang;
            r--, c--;
            ang /= 90;
            while(ang--){
                rot(r, c, x, a);
            }
        }else if(op == 1){
            cin >> r >> c >> x;
            r--, c--;
            for(int i = 0; i < x; i++){
                for(int j = 0; j < x; j++){
                    a[r+i][c+j] = !a[r+i][c+j];
                }
            }
        }else if(op == 2){
            cin >> r;
            r--;
            vector<bool> tmp = a[r];
            for(int j = 0; j < n; j++)  a[r][j] = tmp[(j+1)%n];
        }else if(op == 3){
            cin >> r;
            r--;
            vector<bool> tmpb = a[r];
            for(int j = 0; j < n; j++)  a[r][j] = tmpb[(j+n-1)%n];
        }else if(op == 4){
            cin >> r >> c;
            r--, c--;
            vector<vector<bool>> b(n, vector<bool>(n,0));
            int cp = a[r][c];
            queue<int> q;
            q.push(r*n+c);
            while(!q.empty()){
                int x = q.front();  q.pop();
                int i = x/n, j = x%n;
                b[i][j] = true;
                for(int k = 0; k < 4; k++){
                    int ni = i+di[k], nj = j+dj[k];
                    if(inRange(ni,0,n)&&inRange(nj,0,n)&&a[ni][nj]==cp&&!b[ni][nj]){
                        q.push(ni*n+nj);
                    }
                }
            }
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    if(b[i][j]) a[i][j] = !a[i][j];
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cout << a[i][j] << " \n"[j==n-1];
        }
    }
    return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int cnt = 1;
  for(int i = 0; i < n-1; i++){
    if(s[i] == s[i+1]) continue;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3760
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int leftAns[SIZE], rightAns[SIZE];

void init(int w){
  int idL = 0;
  int idR = 0;
  
  if(w%2 == 0){
    for(int i=1;i<w;i+=2){
      leftAns[idL++] = i;
    }
    for(int i=w-2;i>=0;i-=2){
      leftAns[idL++] = i;
    }

    for(int i=w-2;i>=0;i-=2){
      rightAns[idR++] = i;
    }
    for(int i=1;i<w;i+=2){
      rightAns[idR++] = i;
    }
  }else{
    for(int i=1;i<w;i+=2){
      leftAns[idL++] = i;
    }
    for(int i=w-1;i>=0;i-=2){
      leftAns[idL++] = i;
    }

    for(int i=w-1;i>=0;i-=2){
      rightAns[idR++] = i;
    }
    for(int i=1;i<w;i+=2){
      rightAns[idR++] = i;
    }
  }
  
}

int getID(int h, int w, int y, int x){

  if( (y+x)%2 == 0 ){
    //left
    y -= x;

    y = (y/2) + (w-1);

    return leftAns[y%w];
  }else{
    //right
    y -= (w-x-1);

    if( w%2 == 0 )
      y = (y/2) + (w-1);
    else
      y = (y/2);

    return rightAns[y%w];
  }
}

int main(){
  int s[SIZE], ans[SIZE];
  int h,w,n;
  pair<int,int> query[SIZE];
  
  scanf("%d%d%d",&h,&w,&n);

  init(w);
  
  for(int i=0;i<w;i++) s[i] = i;

  for(int i=0;i<n;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--; b--;

    query[i] = {a,b};
  }

  sort(query, query+n);

  for(int i=0;i<n;i++){    
    swap(s[getID(h,w,query[i].first, query[i].second)],
         s[getID(h,w,query[i].first, query[i].second+1)]);
  }


  
  for(int i=0;i<w;i++){
    ans[s[getID(h,w,h,i)]] = i + 1;
  }

  for(int i=0;i<w;i++){
    printf("%d\n",ans[i]);
  }
  
  return 0;
}




Measured memory_bytes: 7900
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    long long int h,n,k,sum=0;
    cin>>n>>k;
    while(n--)
    {
        cin>>h;
        if(h>=k)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
INF = -10**11
x, y, z, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True) + [INF]
b = sorted([int(item) for item in input().split()], reverse=True) + [INF]
c = sorted([int(item) for item in input().split()], reverse=True) + [INF]

num = x + y + z
ac, bc, cc = 0, 0, 0
ad = a[0] - a[1]
bd = b[0] - b[1]
cd = c[0] - c[1]
kadd = min(12000, x*y*z)
while (ac+1) * (bc+1) * (cc+1) < kadd:
    if ad <= bd and ad <= cd:
        ac += 1
        ad = a[ac] - a[ac+1]
    elif bd <= ad and bd <= cd:
        bc += 1
        bd = b[bc] - b[bc+1]
    elif cd <= ad and cd <= bd:
        cc += 1
        cd = c[cc] - c[cc+1]

for i in range(30):
    if ac+1 < x:
        ac += 1
    if bc+1 < y:
        bc += 1
    if cc+1 < z:
        cc += 1

vals = []
for ai in a[:ac+1]:
    for bi in b[:bc+1]:
        for ci in c[:cc+1]:
            vals.append(ai+bi+ci)
vals.sort(reverse=True)
for i in range(k):
    print(vals[i])

Measured memory_bytes: 64948
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

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

  i64 N, K;
  cin >> N >> K;
  vector<i64> P(N);
  for (auto &x : P) cin >> x;

  vector<int> lsorted(N), rsorted(N);
  for (int i = 0; i < N; ++i) {
    lsorted[i] = 1;
    if (i > 0 && P[i - 1] <= P[i]) {
      lsorted[i] = lsorted[i - 1] + 1;
    }
    int j = N - 1 - i;
    rsorted[j] = 1;
    if (i > 0 && P[j] <= P[j + 1]) {
      rsorted[j] = rsorted[j + 1] + 1;
    }
  }

  deque<tuple<i64, int>> minq, maxq;
  auto minadd = [&](int i) {
    while (!minq.empty() && P[i] <= get<0>(minq.back())) {
      minq.pop_back();
    }
    minq.emplace_back(P[i], i);
  };
  auto maxadd = [&](int i) {
    while (!maxq.empty() && P[i] >= get<0>(maxq.back())) {
      maxq.pop_back();
    }
    maxq.emplace_back(P[i], i);
  };
  REP(i, K - 1) {
    minadd(i);
    maxadd(i);
  }

  set<tuple<int, int>> sorted_ranges;
  bool nochange = false;
  for (int l = 0; l <= N - K; ++l) {
    int r = l + K;  // exclusive
    assert(r <= N);
    minadd(r - 1);
    maxadd(r - 1);
    while (get<1>(minq.front()) < l) {
      minq.pop_front();
    }
    while (get<1>(maxq.front()) < l) {
      maxq.pop_front();
    }
    assert(!minq.empty());
    assert(!maxq.empty());
    i64 mine = get<0>(minq.front());
    i64 maxe = get<0>(maxq.front());

    if (r - lsorted[r - 1] <= l) {
      DEBUG(nochange, l, r);
      nochange = true;
      continue;
    }

    int al = l;
    if (l - 1 >= 0 && P[l - 1] < mine) {
      al = l - lsorted[l - 1];
    }
    int ar = r;
    if (r < N && P[r] > maxe) {
      ar = r + rsorted[r];
    }
    sorted_ranges.emplace(al, ar);
  }
  int ans = sorted_ranges.size() + int(nochange);
  cout << ans << endl;
}


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

int main(void) {
  int r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}

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

using namespace std;

int main(){
    int N;
    int count =0,ans =0;
    cin >> N;

    for(int i=1;i<N+1;i++){
        for(int j=1;j<i+1;j++){
            if(i%2==1){
                if(i % abs(j) ==0)  count++;
            }
            
        }
        if(count == 8) ans++;
        count = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	for(int i=0;i<s.length();i++){
		if(i%2==0){
			if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
				cout << "No";
				return 0;
			}
		}
		else{
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256