akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vli vector<pair<ll,int>>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

vector<ll> parent, rak;

void make_set(int f){
    fo(i,f+1)parent.pb(i);
    rak.assign(f+1,1);
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

ll union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rak[a]+=rak[b];
        return (rak[a]-rak[b])*(rak[b]);
    }
    return 0;
}

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n>>k;
    cin>>s;
    s[k-1]=towlower(s[k-1]);
    cout<<s;  
    return 0;
}


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

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

if (S=="SSS"){
 cout<<0<<endl;}
if (S=="RRR") {
  cout<<3<<endl;}
 if (S=="RSS"  || S=="SRS"  ||S=="SSR" || S=="RSR") {
   cout<<1<<endl;}
 if (S=="RRS"  ||  S=="SRR" ) {
   cout<<2<<endl;    
}
}

Measured memory_bytes: 3592
#!/usr/bin/env python3


def main():
    m1, d1 = (int(z) for z in input().split())
    m2, d2 = (int(z) for z in input().split())
    if m1 != m2:
        print(1)
    else:
        print(0)


if __name__ == "__main__":
    main()


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

int N,Q;
vector<int> edges[200000];
int64_t num[200000];

void dfs(int i,int p){
    for(int j:edges[i])if(j!=p){
        num[j]+=num[i];
        dfs(j,i);
    }
}

int main(){
    cin>>N>>Q;
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }
    for(int i=0;i<Q;i++){
        int p,x;
        cin>>p>>x;
        num[p-1]+=x;
    }
    dfs(0,-1);
    for(int i=0;i<N;i++)cout<<num[i]<<" \n"[i==N-1];
    return 0;
}

Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  int n,a,b=0;
    cin>>n;
    for(a=1; a<=n; a++)
    {
        if(a%3!=0&&a%5!=0)
            b=b+a;
    }
    cout<<b<<endl;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint INF = 1e18, MAX_COST = 2500;
typedef pair<lint, lint> P;
using edge = pair<lint, P>;

signed main(){
	lint N, M, S; cin >> N >> M >> S;
	S = min(S, MAX_COST);
	vector<vector<edge> > G(N);
	for(lint i = 0; i < M; i++){
		lint u, v, a, b; cin >> u >> v >> a >> b; --u; --v;
		G[u].push_back(edge(v, P(a, b))); G[v].push_back(edge(u, P(a, b)));
	}
	vector<lint> c(N), d(N);
	for(lint i = 0; i < N; i++) cin >> c[i] >> d[i];
	vector<vector<lint> > dist(N, vector<lint> (MAX_COST + 1, INF));
	priority_queue<edge, vector<edge>, greater<edge> > que;
	dist[0][S] = 0;
	que.push(edge(0, P(0, S)));

	while(que.size()){
		edge e = que.top(); que.pop();
		lint time = e.first, now = e.second.first, money = e.second.second;
		if(dist[now][money] < time) continue;

		if(money + c[now] <= MAX_COST){
			lint ntime = time + d[now], nmoney = money + c[now];
			if(dist[now][nmoney] > ntime){
				dist[now][nmoney] = ntime;
				que.push(edge(ntime, P(now, nmoney))); 
			}
		}

		for(auto e : G[now]){
			if(money < e.second.first) continue;
			lint next = e.first, ntime = time + e.second.second, nmoney = money - e.second.first;
			if(dist[next][nmoney] > ntime){
				dist[next][nmoney] = ntime;
				que.push(edge(ntime, P(next, nmoney)));
			}
		}
	}

	for(lint i = 1; i < N; i++){
		lint ans = INF;
		for(lint j = 0; j <= MAX_COST; j++){
			ans = min(ans, dist[i][j]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 7428
#include<iostream>
#include<cmath>
#define x first
#define y second
using namespace std;
const int N = 16, M = (1 << 15);
const long long INF = 0x3f3f3f3f3f3f3f3f;
int n, log_2[1 << N];
long long dx[M][N], dy[M][N], x[N], y[N], p[N], ans;

void dfs(int a, int b, int maska, int maskb, int posi)
{
	if(a == 0 && b == 0)
	{
		long long tmp = 0;
		for(int i = 0; i < n; ++i)
			tmp += min(dx[maska][i], dy[maskb][i]);
		ans = min(ans, tmp);
		return;
	}
	if(n - posi < a + b) return;
	if(a > 0) dfs(a-1, b, maska | 1 << posi, maskb, posi + 1);
	if(b > 0) dfs(a, b-1, maska, maskb | 1 << posi, posi + 1);
	dfs(a, b, maska, maskb, posi + 1);
}
int main()
{
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> p[i];
	for(int i = 0; i < n; ++i)
		dx[0][i] = abs(y[i] * p[i]), dy[0][i] = abs(x[i] * p[i]), log_2[1<<i] = i;
	for(int i = 1; i < 1 << n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			long long tmpx = abs(y[j] - y[log_2[i & -i]]),
					  tmpy = abs(x[j] - x[log_2[i & -i]]);
			dx[i][j] = min(dx[i & (i - 1)][j], tmpx * p[j]);
			dy[i][j] = min(dy[i & (i - 1)][j], tmpy * p[j]);
		}
	}
//	for(int i = 0; i < 1 << n; ++i)
//		for(int j = 0; j < n; ++j)
//			printf("dx[%d][%d] = %lld, dj[%d][%d] = %lld\n", i, j, dx[i][j], i, j, dy[i][j]);
//
	for(int k = 0; k < n; ++k)
	{
		ans = INF;
		for(int a = 0; a <= k; ++a)
			dfs(a, k - a, 0, 0, 0);
		cout << ans << endl;
	}
	cout << 0 << endl;
	return 0;
}


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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;


int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  string s; cin >> s;
  int n = s.size();
  int i = 0, j = n - 1;
  int ans = 0;
  while (i < j){
    if (s[i] != s[j]) ++ans;
    ++i; --j;
  }
  cout << ans;
}



Measured memory_bytes: 256
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
@a = gets.chomp.split.map(&:to_i)
@n = n
k = n/2

if n == 2 || n == 3
  puts @a.max
  exit
end

@memo = Array.new(3){Array.new(n+5)}
def solve(index,skip_c)
  @memo[skip_c][index] ||=
  if index >= @n
    if skip_c > 0
      -INF
    else
      0
    end
  elsif skip_c == 0
    solve(index + 2, 0) + @a[index]
  elsif skip_c == 1
    tmp = []
    [2, @n - index - 1].min.times do |i|
      tmp.push solve(index + 2 + i, skip_c - i) + @a[index + i]
    end
    # p [index, skip_c, tmp]
    tmp.max || -INF
  else
    tmp = []
    [3, @n - index - 1].min.times do |i|
      tmp.push solve(index + 2 + i, skip_c - i) + @a[index + i]
    end
    # p [index, skip_c, tmp]
    tmp.max || -INF
  end
end

if n.even?
  puts solve(0,1)
else
  puts solve(0,2)
end


Measured memory_bytes: 163456
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  vi a(4), b(4);
  map<int, int> m;
  int hit;

  while(!cin.eof()) {
    for (auto v:{&a, &b}) {
      rep (i, 4) {
        cin >> (*v)[i];
      }
    }
    if (cin.eof())
      break;

    m.clear();
    hit = 0;

    rep (i, 4) {
      m[a[i]]++;
      m[b[i]]++;
      if (a[i] == b[i])
        hit++;
    }
    cout << hit << " ";
    cout << count_if(all(m), [](pii p){ return p.second==2;}) - hit << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] list = new int[N];
		for (int i = 0; i < N; i++) {
			list[i] = sc.nextInt();
		}
		Arrays.sort(list);
		ArrayList<Integer> array = new ArrayList<Integer>();

		for (int i = list[0]; i <= list[N - 1]; i++) {
			int serve = 0;
			for (int p : list) {
				serve += (p - i) * (p - i);
			}
			array.add(serve);
		}

		Collections.sort(array);
		System.out.println(array.get(0));
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int N , M;
    scanf("%d %d",&N,&M);
    int a[N];
    int w[N];
    memset(a,0,N*sizeof(*a));
    memset(w,0,N*sizeof(*w));
    int prob;
    int ac=0;
    int wa=0;
    char SUB[3];
    for (int i=0;i<M;i++)
    {
     scanf("%d %s",&prob,&SUB);
     if (a[prob-1]==1)continue;
     if (strcmp("WA",SUB)==0)
     {
         w[prob-1]++;
     }
     else if (strcmp("AC",SUB)==0)
        {
            a[prob-1]=1;
            wa+=w[prob-1];
            ac++;

        }

    }

    printf("%d %d",ac,wa);

    return 0;
}


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


int main() {
	int n;
	cin >> n;
	int a[n];
	ll start = 1000, stock = 0;
	for(int i=0; i<n; i++) {
		cin >> a[i];
	}
	for(int i=0; i<(n-1); i++) {
		if(a[i] < a[i+1]) {
			stock += start/a[i];
			start = start % a[i];
		}
		else if(a[i] > a[i+1]) {
			start += stock*a[i];
			stock = 0;
		}
	}
	start += stock*a[(n-1)];
	cout << start << endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <algorithm>

using namespace std;


static int N,M;

static struct {
    int count;
    int weight;
} counts[1000];

static int max_weight=0,min_weight=100;


int main(){
    scanf("%d%d",&N,&M);

    for(int i=0;i<N;i++) scanf("%d",&counts[i].weight);

    bool all_equals;
    int weight=0;
    int i=0;
    do{
        max_weight=0;
        min_weight=100;
        all_equals=true;
        for (int j=0;j<M;j++){
            counts[i].count++;

            max_weight=max(max_weight,counts[i].weight);
            min_weight=min(min_weight,counts[i].weight);
            i=(i+1)%N;
        }

        weight+=max_weight-min_weight;

        for (int j=0;j<N-1;j++) if (counts[j].count!=counts[j+1].count) {all_equals=false; break;}
    }while(!all_equals);

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

    return 0;
}


Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
 #include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
#include <iostream>  
using namespace __gnu_pbds;  
using namespace std;

// typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>  ordered_set;
#define ll long long
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update>  ordered_set;
 
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl
 
#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
ll MOD=1000000007;
ll n,m;
ll dp[1005][1005];
char ar[1005][1005];
ll dfs(ll x,ll y)
{
    if(dp[x][y]!=-1)
        return dp[x][y];
    if(x==n-1&&y==m-1)
    {
        return 1;
    }
    ll a=0,b=0;
    if(ar[x+1][y]=='.')
    a=dfs(x+1,y);
    if(ar[x][y+1]=='.')
    b=dfs(x,y+1);
    return dp[x][y]=(a+b)%MOD;
}
#define INF 1000000000000000000
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long double pi= 3.14159265358979323846;
    cin>>n>>m;
    rep(i,1005)
    {
        rep(j,1005)
        {
            dp[i][j]=-1;
        }
    }
    rep(i,n)
    {
        rep(j,m)
        {
            cin>>ar[i][j];
        }
    }
    cout<<dfs(0,0);
    return 0;
}

Measured memory_bytes: 9216
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    if(a>=b){
        rep(i,a){
            cout << b;
        }
    }
    else{
        rep(i,b){
            cout << a;
        }
    }

    return 0;
}

Measured memory_bytes: 3624
/*
 * atcoder/dp_2nd/o.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long
#define MOD 1000000007

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

class Bits {
public:
  inline static bool included(ll S, ll v) {
    return ((S&(1<<v))>>v) == 1;
  }

  inline static ll add(ll S, ll v) {
    return S&(1<<v);
  }

  inline static ll remove(ll S, ll v) {
    return S&(~(1<<v));
  }

  inline static ll all(ll num) {
    ll a = 0;
    for (ll v=0; v<num; v++) {
      a |= (1<<v);
    }
    return a;
  }

};

const int MAX = 30;
ll N;
bool G[MAX][MAX];

// dp[i][S] := iまでの男性がSの女性たちとマッチングする通りの数
ll dp[MAX][1<<22];
ll all;

void input() {
  cin >> N;
  ll a;
  loop(i,1,N+1) {
    loop(j,1,N+1) {
      cin >> G[i][j];
    }
  }

  all = Bits::all(N);
}

void solve() {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (ll S=1; S<=all; S++) {
    for (int f=1; f<=N; f++) {
      int m = __builtin_popcount(S);
      if (!G[m][f]) continue;
      if (!Bits::included(S, f-1)) continue;
      dp[m][S] += dp[m-1][Bits::remove(S, f-1)];
      dp[m][S] %= MOD;
      // cout << "Trans: (" << (m-1) << ", " << (Bits::remove(S, f-1)) << ") -> (" << m << ", " << S << ")" << endl;
    }
  }

  cout << dp[N][all] << endl;
}

void dump() {
  for (int m=0; m<=N; m++) {
    for (ll S=0; S<=(1<<N); S++) {
      cout << dp[m][S] << " ";
    }
    cout << endl;
  }
}

int main() {
  // cout.precision(15);
  input();
  solve();
  // dump();
  return 0;
}


Measured memory_bytes: 983424
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final long X = Math.abs(sc.nextLong());
        final long K = sc.nextLong();
        final long D = sc.nextLong();
        
        long steps = (X + D / 2) / D;
        
        if (K < steps) {
            System.out.println(Math.abs(X - D * K));
            
        } else if ((K -steps) % 2 == 0) {
            System.out.println(Math.abs(X - D * steps));
            
        } else {
            System.out.println(- Math.abs(X - D * steps) + D);
            
        }
    }
}


Measured memory_bytes: 35860
from bisect import bisect_left, bisect_right
s = input()
t = input()
n_s = len(s)
n_t = len(t)


idx = [[] for _ in range(26)]
#print(ord("a"))
#print(ord("z"))

def a_idx(a):
    idx = ord(a)
    idx -= 97
    return idx


for i in range(n_s):
    idx[a_idx(s[i])].append(i)

t_syutugenkasyo = []
for i in range(n_t):
    t_syutugenkasyo.append(idx[a_idx(t[i])])
#print(t_syutugenkasyo)

now = -1
ans = 0
for i in range(n_t):
    if len(t_syutugenkasyo[i]) == 0:
        print(-1)
        exit()
    ni = bisect_right(t_syutugenkasyo[i], now)
    if ni >= len(t_syutugenkasyo[i]):
        ans += n_s
        now = -1
        ni = bisect_right(t_syutugenkasyo[i], now)
        now = t_syutugenkasyo[i][ni]
    else:
        now = t_syutugenkasyo[i][ni]
ans += now+1
print(ans)

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

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

    int size = S.length();

    if (size == 2) cout << S << endl;
    else {
        for (int i = 0; i < 3; i++){
            cout << S[2-i];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())

    if (H == 0):break#たぶんWの条件いらない

    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print ("#", end="")
            else:
                print (".", end="")
        print("")
    print("")



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

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

    bool to_mid[N+1] = {}, to_n[N+1] = {};
    int a, b;
    rep(i, M) {
        cin >> a >> b;
        if (a==1) to_mid[b] = true;
        else if (b==N) to_n[a] = true;
    }

    string ans = "IMPOSSIBLE";
    rep(i, N+1) {
        if (to_mid[i] && to_n[i]) ans = "POSSIBLE";
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int h, w;
string m[50];

int main() {
	cin >> h >> w;
	rep(i,h) cin >> m[i];
	
	rep(i,h) {
		rep(j,w) {
			if (m[i][j]=='#') continue;
			int t = 0;
			rep(d,8) {
				int di = i + ddy[d];
				int dj = j + ddx[d];
				if (0<=di && di<h && 0<=dj && dj<w && m[di][dj]=='#') t++;
			}
			m[i][j] = (char)(t+'0');
		}
	}
	rep(i,h) cout << m[i] << ln;
}

Measured memory_bytes: 256
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define MOD 1000000007

using namespace std;

int main() {

	SINT32 N = 0;
	string S;
	SINT64 ANS = 1;

	cin >> N;
	cin >> S;

	vector<SINT32> DATA(26);

	for (SINT32 i = 0; i < 26; i++) {
		DATA[i] = 0;
	}
	
	for (SINT32 i = 0; i < N; i++) {
		DATA[S[i]-'a']++;
	}

	for (SINT32 i = 0; i < 26; i++) {
		ANS = ANS * ((DATA[i] + 1)% MOD);
		ANS = ANS % MOD;
	}
	ANS--;

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

//#define mod 1000000007;

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

    int x, n;
    cin>>x>>n;
    set<int>s;
    int a,b;
    for(int i=0;i<n;i++)
    {
        int it;
        cin>>it;
        s.insert(it);
    }
    a = x;
    int m1,m2;
    while(1)
    {
        if(s.find(a) == s.end())
        {
            
            m1 = a;

            break;
        }
        a--;
    }
    a = x;
    while(1)
    {
        if(s.find(a) == s.end())
        {
            m2 = a;
            break;
        }
        a++;
    }
    if(abs(m1-x) > abs(m2-x))
        cout<<m2;
    if(abs(m1-x) < abs(m2-x))
        cout<<m1;    
    if(abs(m1-x) == abs(m2-x))
    {
        int ans = min(m1, m2);
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3660
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var dst = new long[5];
            for (var i = 0; i < 5; ++i)
                dst[i] = Sarray()[0];
            var k = Sarray()[0];
            if (k < dst[4] - dst[0])
                WriteLine(":(");
            else
                WriteLine("Yay!");
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 28220
X,K,D = map(int, open(0).read().split())
a = abs(X) // D
if K <= a:
    print(abs(X)-K*D)
else:
    if (K-a) % 2 == 0:
        print(abs(X)%D)
    else:
        print(abs(D-abs(X)%D))

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

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i += 2){
    int num_of_divisors = 0;
    for(int j = 1; j <= n; j++){
      if(i % j == 0){
        num_of_divisors++;
      }
    }
    if(num_of_divisors == 8){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter


def main():
    N = int(input())
    A = [input() for _ in range(N)]

    c = Counter(A)
    d = c.most_common()
    ans = []
    for i in c.items():
        if i[1] == d[0][1]:
            ans.append(i[0])
    for i in sorted(ans):
        print(i)


if __name__ == '__main__':
    main()


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

string s, t;

int main(void){
  // Here your code !
  cin >> s;
  cin >> t;

  for (int i = 0; i < s.size(); ++i) {
    string tmp;
    for (int j = 0; j < s.size(); ++j) {
      tmp.push_back(s[(j + i) % s.size()]);
    }

    bool same = true;
    for (int j = 0; j < t.size(); ++j) {
      same &= (tmp[j] == t[j]);
    }

    if (same) {
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
  int n, i, j;
  cin >> n;
  char w[n][120];
  for(i=0; i<n; i++)
    cin >> w[i];
  for(i=0; i<n-1; i++)
    if(w[i][strlen(w[i])-1]!=w[i+1][0]){
      cout << "No";
      return 0;
    }
  /*  sort(w, w+n);
  for(i=0; i<n-1;i++)
    if(strcmp(w[i], w[i+1])==0){
      cout << "No";
      return 0; */
  for(i=1;i<n; i++)
    for(j=0;j<i; j++){
      if(strcmp(w[i],w[j])==0){
	cout << "No";
	return 0;
      }
    }
  cout << "Yes";
  return 0;
}

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

namespace ABC121D_3
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long A = input[0], B = input[1];
            Console.WriteLine(F(A - 1) ^ F(B));
        }

        static long F(long x) => new[] {x, 1, x + 1, 0}[(x + 4) % 4];
    }
}

Measured memory_bytes: 13396
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <fstream>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll factorial(ll n) {//階乗
	ll ret = 1;
	rep(i,1, n + 1)
		ret = (ret *i)%MODU;

	return ret;
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
	return divmod(factorial(n) , (factorial(r) * (factorial(n - r)))%MODU, MODU);
}
signed main() {
	int x, y;
	cin >> x >> y;

	int a = -1, b = -1;

	REP(i, x + 1) {
		int rx = x - i, ry = y - 2 * i;

		if (rx == 2 * ry) {
			a = i;
			b = ry;
		}
	}
	ll ans = 0;
	if (a == -1) {
		cout << 0 << endl;
	}
	else
		cout << ncr(a + b, a) << endl;
	return 0;
}

Measured memory_bytes: 256
yyyy,mm,dd = map(int,input().split("/"))

if yyyy == 2019 and mm == 4 and dd == 30:
    print("Heisei")
    exit()

if yyyy >= 2019:
    if mm > 4:
        print("TBD")
    else:
        print("Heisei")
else:
    print("Heisei")
    


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

#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define dump(x) cerr << #x " = " << boolalpha << (x) << endl;

// 約数列挙
template <typename T>
inline auto generate_divisors (T n)
{
  set <T> res;
  for (T i = 1; i * i <= n; ++ i)
  {
    if (n % i == 0)
    {
      res.emplace (i);
      res.emplace (n / i);
    }
  }
  return res;
}

template <typename T>
inline auto operator << (ostream & stream, const vector <T> & x) -> ostream &
{
  copy (x.begin (), x.end (), ostream_iterator <T> (stream, " "));
  return stream;
}

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

  size_t n;
  int64_t k;
  cin >> n >> k;

  vector <int64_t> a;
  copy_n (istream_iterator <decay_t <decltype (a.front ())>> (cin), n, back_inserter (a));

  auto sum = accumulate (a.begin (), a.end (), static_cast <int64_t> (0));
  int64_t ans = 1;

  for (auto && d : generate_divisors (sum))
  {
    vector <int> rs;
    for (auto && elem : a)
    {
      auto r = elem % d;
      rs.emplace_back (r);
    }
    sort (rs.begin (), rs.end ());

    rep (i, rs.size ())
    {
      int64_t A = 0;
      int64_t B = 0;
      for (size_t j = 0; j < i; ++ j)
      {
        A += rs [j];
      }
      for (auto j = i; j < rs.size (); ++ j)
      {
        B += d - rs [j];
      }
      if (A == B && k >= B)
      {
        ans = max (ans, d);
      }
#ifdef LOCAL
      dump (d)
      dump (rs)
      dump (A)
      dump (B)
      cerr << endl;
#endif
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
	string s;
	cin >>s;
	int ans=1000000;
	rep(i,s.size()-2){
		int a,b,c;
		//abc
		a=(int)(s[i]-'0');
		b=(int)(s[i+1]-'0');
		c=(int)(s[i+2]-'0');
		ans=min(abs(753-(a*100+b*10+c)),ans);
	}
	cout <<ans<<endl;
}

Measured memory_bytes: 256
#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>;
using vi = vector<ll>;
using vv = vector<vi>;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1001001001001;

int main(){
    string s;
    cin >> s;
    
    if(s=="SSS")cout<<0<<endl;
    else if(s=="RRR")cout<<3<<endl;
    else if(s=="RRS" || s=="SRR")cout<<2<<endl;
    else cout<<1<<endl;
    
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;
    vec<int> ans(n-1);
    rep(j, n) rep(i, j) {
        // int opt = 0;
        // if (i <= x && y <= j) opt = j - i - (y - x);
        // else if (i <= x && j <= x) opt = j - i;
        // else if (y <= i && y <= j) opt = j - i;
        // else if 
        //cout << i << j << endl;
        int opt = min(j - i, abs(y-j) + abs(x-i) + 1);
        ans[opt-1]++;
    }
    rep(i, n-1) cout << ans[i] << endl;
}

Measured memory_bytes: 384
<?php
fscanf(STDIN, '%d %d', $n, $k);
fscanf(STDIN, '%s', $s);

$ans = '';
for($i = 0; $i < $n; $i++) {
    if ($i === $k - 1) $ans = $ans . strtolower($s[$i]);
    else $ans = $ans . $s[$i];
}
echo $ans . PHP_EOL;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 998244353;


template <typename T>
struct PrimeFact {
	vector<T> spf;
	PrimeFact(T N) { init(N); }
	void init(T N) { // 前処理。spf を求める
		spf.assign(N + 1, 0);
		for (T i = 0; i <= N; i++) spf[i] = i;
		for (T i = 2; i * i <= N; i++) {
			if (spf[i] == i) {
				for (T j = i * i; j <= N; j += i) {
					if (spf[j] == j) {
						spf[j] = i;
					}
				}
			}
		}
	}
	map<T, T> get(T n) { // nの素因数分解を求める
		map<T, T> m;
		while (n != 1) {
			m[spf[n]]++;
			n /= spf[n];
		}
		return m;
	}
};

int main() {

	ll n;
	cin >> n;

	VLL spf(n + 1, 0);
	for (int i = 0; i <= n; i++) spf[i] = i;
	for (int i = 2; i * i <= n; i++) {
		if (spf[i] == i) {
			for (int j = i * i; j <= n; j += i) {
				if (spf[j] == j) {
					spf[j] = i;
				}
			}
		}
	}

	ll ans = 1;

	FOR(i, 2, n + 1) {
		ll a = -1;
		ll b = 0;
		ll c = 1;
		int j = i;
		while (j != 1) {
			int tmp = spf[j];
			if (tmp != a) {
				a = tmp;
				c *= b + 1;
				b = 1;
			}
			else b++;
			j /= tmp;
		}
		c *= b + 1;
		ans += c * (ll)i;
	}
	cout << ans << endl;



}

Measured memory_bytes: 81400
count = 0
A, B, C, X = map(int, [input() for i in range(4)])
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if 500 * i + 100 * j + 50 * k == X:
                count += 1
print(count)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
vector<int> P,Q,PR,QR;

vector<int> rev(vector<int> A) {
	vector<int> R(N);
	int i;
	FOR(i,N) R[A[i]]=i;
	return R;
}
vector<int> conv(vector<int> A,vector<int> B) { 
	vector<int> R(N);
	int i;
	FOR(i,N) R[i]=A[B[i]];
	return R;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	P.resize(N);
	Q.resize(N);
	FOR(i,N) cin>>P[i];
	FOR(i,N) cin>>Q[i];
	FOR(i,N) P[i]--,Q[i]--;
	
	PR=rev(P);
	QR=rev(Q);
	K--;
	auto A=conv(conv(conv(Q,PR),QR),P);
	vector<int> E,B;
	FOR(i,N) E.push_back(i);
	B=E;
	FOR(i,30) {
		if((K/6)&(1<<i)) E=conv(E,A);
		A=conv(A,A);
	}
	
	K%=6;
	A=E;
	if(K>=3) {
		A=conv(A,Q);
		if(K>=4) A=conv(A,PR);
	}
	
	auto AR=rev(A);
	
	if(K==0) B=P;
	if(K==1) B=Q;
	if(K==2) B=conv(Q,PR);
	if(K==3) B=PR;
	if(K==4) B=QR;
	if(K==5) B=conv(QR,P);
	
	auto C=conv(conv(A,B),AR);
	FORR(c,C) cout<<c+1<<" ";
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 5920
N = input()
r = input()

data = [int(i) for i in r.split(" ")]
sorted_data = sorted(data)

diff_count = 0
for i in range(0, len(data)):
    if data[i] != sorted_data[i]:
        diff_count += 1

if diff_count >= 3:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3060
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

const static si NMAX = 8;
const static si XiMAX = 1000;
const static si YiMAX = 1000;

static si N;
static si Xi[NMAX];
static si Yi[NMAX];

inline ld distance(ld x1, ld y1, ld x2, ld y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

void solve(void) {
  ld res = 0;
  FOR0(i, N) {
    FOR0(j, N) {
      res += abs(distance(Xi[i], Yi[i], Xi[j], Yi[j]) / N);
    }
  }
  cout << setprecision(20) << res << endl;
}

int main(void) {
  cin >> N;
  FOR0(i, N) {
    cin >> Xi[i] >> Yi[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long  n,a,b,sum=0,p=1;
int x[100005];
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
	}
	while(p<=n-1)
	{
		if(x[p+1]*a-x[p]*a>b)
		{
			sum+=b;
			p++;
		}
		else
		{
			sum+=x[p+1]*a-x[p]*a;
			p++;
		}
	}
	cout<<sum;
	return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll h,w,K;
bool mp[1001][10];
ll tb[1001][10];
ll _get(ll l,ll r,ll y){//[l,r)
    return tb[r][y]-tb[l][y];
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>h>>w>>K;
    string s;
    rep(i,h){
        cin>>s;
        rep(j,s.size()){
            if(s[j]=='1')mp[j][i]=true;
            else mp[j][i] = false;
        }
    }
    rep(i,h){
        tb[0][i]=0;
        rep(j,w){
            if(mp[j][i])tb[j+1][i] = tb[j][i] + 1;
            else tb[j+1][i] = tb[j][i];
        }
    }
    ll ans = INF,as;
    ll tmp,tmp2;
    ll aa,xx;
    rep(mk,1<<(h-1)){
        xx = 0;
        as = 0;
        rep(i,w){
            aa = 0;
            tmp = 0;
            rep(j,h-1){
                tmp2 = 0;
                if(mk & (1<<j) ){
                    repi(k,aa,j+1){
                        tmp2 += _get(xx,i+1,k);
                    }
                    chmax(tmp,tmp2);
                    aa = j+1;
                }
                if(j==h-2){
                    tmp2 = 0;
                    repi(k,aa,h){
                        tmp2 += _get(xx,i+1,k);
                    }
                    chmax(tmp,tmp2);
                }
            }
            if(tmp>K){
                if((i-xx) == 0){
                    as = -1;
                    break;
                }
                xx = i;
                i-=1;
                as++;
                if(as>ans)break;
            }
        }
        if(as!=-1)as += __builtin_popcount(mk);
        if(as!=-1)chmin(ans,as);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin>>n;
    vint a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    int sum=SUM(a);
    if(sum%10!=0){
        cout<<sum<<endl;
        return 0;
    }
    rep(i,n){
        if((sum-a[i])%10!=0){
            cout<<sum-a[i]<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
}

Measured memory_bytes: 3620
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  long n, a, b;
  readf("%s %s %s\n", &n, &a, &b);
  if (b < a || (n == 1 && a != b)) {
    writeln(0);
  } else {
    auto l = a * (n - 1) + b;
    auto r = b * (n - 1) + a;
    writeln(r - l + 1);
  }
}


Measured memory_bytes: 256
let inp_matrix : 'a array -> int -> int -> unit = fun a m n ->
  for i = 0 to m - 1 do
    let line = Scanf.Scanning.from_string @@ input_line stdin in
    for j = 0 to n - 1 do
      a.(i).(j) <- Scanf.bscanf line " %d" (fun x -> x)
    done
  done
  
let rec inp_loop : (unit -> 'a) -> int -> 'a list = fun inp_fun n ->
  if n = 0 then []
  else
    let x = inp_fun () in
    x :: inp_loop inp_fun (n - 1)

let hole a m n k =
  for i = 0 to m - 1 do
    for j = 0 to n - 1 do
      if a.(i).(j) == k then
        a.(i).(j) <- (-1)
    done
  done

let calc_ans a =
  let ans = ref "No" in
  for i = 0 to 2 do
    if (a.(i).(0) == a.(i).(1) && a.(i).(0) == a.(i).(2)) then ans := "Yes"
  done;
  for j = 0 to 2 do
    if (a.(0).(j) == a.(1).(j) && a.(0).(j) == a.(2).(j)) then ans := "Yes"
  done;
  if (a.(0).(0) == a.(1).(1) && a.(2).(2) == a.(1).(1) || a.(0).(2) == a.(1).(1) && a.(0).(2) == a.(2).(0)) then ans := "Yes";
  !ans
  
  
let () =
  let a = Array.make_matrix 3 3 0 in
  let () = inp_matrix a 3 3 in
  let n = Scanf.sscanf (input_line stdin) "%d" (fun x -> x) in
  let l = inp_loop (fun () -> Scanf.sscanf (input_line stdin) "%d" (fun x -> x)) n in
  List.iter  (hole a 3 3) l;
  let ans = calc_ans a
  in
  print_endline ans


Measured memory_bytes: 384