akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long//
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define r(i,n) for(ll i=0;i<n;i++)
#define rt return
#define db double
#define ldb long double
#define vd void
#define p(x) cout<<(x)<<endl;
#define ce continue;
#define bl bool
#define r0 rt 0;
#define r1 rt 1;
#define elif else if
#define bk break;
#define A p("A")
#define B p("B")
#define C p("C")
#define D p("D")
#define E p("E")
#define F p("F")
#define S(a) sort(a.begin(),a.end());
#define R(a) reverse(a.begin(),a.end());
#define cl cout<<endl;
#define pb(x) push_back(x);
#define str string
using namespace std;
void Cond(int g){if(g)p("YES")else p("NO")rt;}
void cond(int g){if(g)p("Yes")else p("No")rt;}
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)rt b;gcd(b,a%b);}
str su="0123456789";
str m1="abcdefghijklmnopqrstuvwxyz";
str m2="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
map<char,ll>m5;
typedef pair<ll,ll> P;
const ll INF=(ll)1e18+10;
ll t1=0,t2=0,t3=0,t4=0,t5=0,t6=0,t7=0,t8=0,g=0,ans=0;
ll n=0,m=0,k=0,mx=-INF,mn=INF,ct=0;
ll tmp=0,tmp1=0,tmp2=0,tmp3=0,tmp4=0;
ll sum=0,mask=0;
set<P> pst;
set<ll>st,st1,st2;
set<char> cst;
ll powmod(ll a,ll b,ll x){//(a^b)modx
    if(!b)r1
    if(!(b%2)){//B
        ll t=powmod(a,b/2,x);
        rt t*t%x;
    }
    rt ((a)*powmod(a,b-1,x))%x;
}
void di(){m5['a']=0;
    m5['b']=1;
    m5['c']=2;
    m5['d']=3;
    m5['e']=4;
    m5['f']=5;
    m5['g']=6;
    m5['h']=7;
    m5['i']=8;
    m5['j']=9;
    m5['k']=10;
    m5['l']=11;
    m5['m']=12;
    m5['n']=13;
    m5['o']=14;
    m5['p']=15;
    m5['q']=16;
    m5['r']=17;
    m5['s']=18;
    m5['t']=19;
    m5['u']=20;
    m5['v']=21;
    m5['w']=22;
    m5['x']=23;
    m5['y']=24;
    m5['z']=25;
}
map<ll,ll>mp,mp1,mp2,mp3;
typedef std::vector<ll> vl;
typedef pair<ll,ll> P;
typedef pair<ll,P>  P2;
typedef struct edge2{P tos;ll cost;}EDGE2;
typedef struct edge1{ll to,cost;}EDGE;
bl used[(ll)1e9];
const ll M=(ll)1e9+7;
ll fac[1000007],finv[1000007],inv[1000007];
void initcmb(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<1000007;i++){
        fac[i]=fac[i-1]*i%M;
        inv[i]=M-inv[M%i]*(M/i)%M;
        finv[i]=finv[i-1]*inv[i]%M;
    }
}
ll cmb(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%M)%M;
}
ldb pi=3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
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 ll MAX=5+(ll)1e5*3;
vl rui(MAX);

vector<vector<EDGE>>G(1e6);
int main(){//swap(ary１,ary２)
    //a.erase(a.begin()+5),a.insert(a.begin()+3,tmp)
    ios_base::sync_with_stdio(0); cin.tie(0);
clock_t start = clock();//timecalc
di();

cin>>k;
str s;
cin>>s;
if(s.length()<=k){
    p(s)
    r0
}
for(int i=0;i<k;i++){
    cout<<s[i];
}
cout<<"..."<<endl;





clock_t end = clock();//
const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;//timecalc
//printf("time %lf[ms]\n", time);//
return 0;
}//main


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

using namespace std;

const int N = 300 + 7;
const int mod = 1e9 + 7;

int n, cnt;
int f[N << 1][N][N];
int a[N << 1], b[N << 1];

int main() { 
  
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) {
		int y = i << 1, x = y - 1; 
		scanf("%d%d", &a[x], &a[y]);
		if (a[x] ^ -1) { 
			if (a[y] == -1) b[a[x]] = -1;
			else b[a[x]] = b[a[y]] = 1; 
		} else {
			if (a[y] ^ -1) b[a[y]] = -1;
			else ++ cnt;
		}
	}

	// f[i][j][k] [i, 2n] is ok, j special ), k normal )。

	f[n << 1 | 1][0][0] = 1; 
	for (int i = n << 1; i; -- i) { 
		if (b[i] == 1) memcpy(f[i], f[i + 1], sizeof(f[i]));
		else { 
			for (int j = 0; j <= n; ++ j)
				for (int k = 0; k <= n; ++ k) {
					if (b[i] ^ -1) { 
						(f[i][j][k + 1] += f[i + 1][j][k]) %= mod;
						if (j) (f[i][j - 1][k] += 1ll * j * f[i + 1][j][k] % mod) %= mod;
						if (k) (f[i][j][k - 1] += f[i + 1][j][k] % mod) %= mod;
					} else { 
						(f[i][j + 1][k] += f[i + 1][j][k]) %= mod;
						if (k) (f[i][j][k - 1] += f[i + 1][j][k]) %= mod;
					}
				}
		}

#ifdef ylsakioi
		for (int j = 0; j <= n * 2 - i + 1; ++ j)
			for (int k = 0; j + k <= n * 2 - j + 1; ++ k) 
				printf("%d %d %d %d\n", i, j, k, f[i][j][k]);
#endif

	}

	for (int i = 1; i <= cnt; ++ i) 
		f[1][0][0] = 1ll * f[1][0][0] * i % mod;
	printf("%d\n", f[1][0][0]);

	return 0;
}


Measured memory_bytes: 223104
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = []
l = 0
cnt = 0
for i, a in enumerate(A):
    if l != 0:
        j = l // 2
        cnt += B[j]
    B.append(a)
    l += 1
print(cnt)


Measured memory_bytes: 101820
#include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
int main(){
  int N;
  cin >> N;
  map<pair<int, int>, int> mp;
  for (int i = 0; i < N; i++){
    int x, y, w;
    cin >> x >> y >> w;
    mp[make_pair(x, y)] = w;
  }
  long long ans = 0;
  for (auto P : mp){
    int x = P.first.first;
    int y = P.first.second;
    for (int i = -1; i <= 1; i++){
      for (int j = -1; j <= 1; j++){
        long long sum = 0;
        for (int k = 0; k < 2; k++){
          for (int l = 0; l < 2; l++){
            if (mp.count(make_pair(x - i + k, y - j + l))){
              sum += mp[make_pair(x - i + k, y - j + l)];
            }
          }
        }
        ans = max(ans, sum);
      }
    }
  }
  cout << ans << " / " << 1 << endl;
}


Measured memory_bytes: 9400
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W = MI()

    def solve(H,W):
        ans = inf
        for h in range(H):
            if not (H-h)&1 or not W&1:
                piece = [h*W, (W*(H-h))//2]
                ans = min(ans, max(piece)-min(piece))
            else:
                if (H-h)&1:
                    piece = [h*W, ((H-h-1)*W)//2, ((H-h+1)*W)//2]
                    ans = min(ans, max(piece)-min(piece))
                if W&1:
                    piece = [h*W, ((W-1)*(H-h))//2, ((W+1)*(H-h))//2]
                    ans = min(ans, max(piece)-min(piece))
        return ans    

    ans1 = solve(H,W)
    ans2 = solve(W,H)

    print(min(ans1,ans2))

if __name__ == '__main__':
    main()


Measured memory_bytes: 42716
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    char name[20];
    int vl;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N;
    int cnt=0;
    scanf("%d",&N);
    int num[N];
    rep(i,N){
        scanf("%d",&num[i]);
    }
    rep(i,N){
        if(num[num[i]-1]==i+1){
            cnt++;
        }else{
            ;
        }
    }
    printf("%d",cnt/2);
}


Measured memory_bytes: 2084
#include <iostream>
#include <vector>
#include <string>;
#define ll long lomg

using namespace std;
#define ll long long
int max(int a,int b){
  if(a > b){
    return a;
  }else{
    return b;
  }
}

int main(void){
  ll num;
  cin  >> num;
  vector<ll> high(num);
  for(int i = 0;i < num;i ++){
    cin >> high[i];
  }
  ll most = 0;
  string ans = "Yes";
  for(int i = 0;i < num;i ++){
    if(most > high[i]){
      ans = "No";
    }else if(most < high[i]-1){
      most = high[i]-1;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4004
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		long K = GetLong();
		long[] A = GetLongs(N);
		long[] F = GetLongs(N);

		Array.Sort(A);
		Array.Sort(F);
		Array.Reverse(F);

		long ng = -1;
		long ok = (long)(1e13);
		while(Math.Abs(ng - ok) > 1)
		{
			long mid = (ng + ok) / 2;
			if(isOK(N, K, A, F, mid))
				ok = mid;
			else
				ng = mid;
		}

		Console.WriteLine(ok);
	}

	private bool isOK(int N, long K, long[] A, long[] F, long x)
	{
		long cnt = 0;
		for(int i = 0; i < N; i++)
			cnt += Math.Max(0, A[i] - x / F[i]);

		return (cnt <= K);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 48472
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[200010],vis(200010,0),dis(200010,inf),fin(200010,0),col(200010,0),par(200010,0);
int myrandom (int i) { return std::rand()%i;}
bool cmp(pair<int,int> p1,pair<int,int> p2)
{
    return abs(p1.ff)>abs(p2.ff);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> v;
    int i=0;
    while(i<n)
    {
        char ch=s[i];
        int cnt=0;
        while(i<n&&ch==s[i])
        {
            i++;
            cnt++;
        }
        if(ch=='R')
        {
            v.pb(cnt);
        }
        else
        {
            v.pb(-cnt);
        }
    }
    i=1;
    int t=k;
    while(i<(int)v.size()&&t>0)
    {
        v[i]=-v[i];
        i=i+2;
        t--;
    }
    int cnt=0;
    i=0;
    while(i<(int)v.size())
    {
        int temp=0;
        while(i<(int)v.size()&&v[i]>0)
        {
            temp=temp+abs(v[i]);
            i++;
        }
        cnt=cnt+max(0,temp-1);
        temp=0;
        while(i<(int)v.size()&&v[i]<0)
        {
            temp=temp+abs(v[i]);
            i++;
        }
        cnt=cnt+max(0,temp-1);
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 9676
#include <iostream>
using namespace std;
int main(void){
    char c[6];
    for(int i=0;i<6;i++)cin>>c[i];
    if(c[0]==c[5]&&c[1]==c[4]&&c[2]==c[3]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m; cin>>n>>m;
    vector<vector<LP>> to(n);
    rep(i, n - 1) {
        to[i].emplace_back(0, i - 1);
    }
    rep(i, m) {
        ll l, r, c;
        cin>>l>>r>>c; l--; r--;
        to[l].emplace_back(c, r);
    }

    priority_queue<LP, vector<LP>, greater<LP>> q;
    q.emplace(0, 0);
    vl dist(n, -1);
    while (!q.empty()) {
        LP p = q.top(); q.pop();
        ll d = p.fi;
        ll v = p.se;
        if (dist[v] != -1) continue;
        dist[v] = d;
        for (auto nv : to[v]) {
            q.emplace(d + nv.fi, nv.se);
        }
    }
    cout<<dist.back()<<endl;
}

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

int main()
{
ll n;
  cin>>n;
  ll a[n+1];
  ll dp[n+1];
  ll i=1;
  while(i<=n)
  {
    
  cin>>a[i];  
   i++; 
  }
  
  
  dp[n+1];
  dp[1]=0;
  dp[0]=0;
  
  i=2;
  dp[i]=abs(a[i]-a[i-1])+dp[i-1];
//  cout<<dp[i]<<" ";
  i=3;
  while(i<=n)
  {
    
   dp[i]=min(        abs(a[i]-a[i-1])      +dp[i-1],dp[i-2]+abs(a[i]-a[i-2])      ); 
  //  cout<<dp[i]<<" ";
   i++; 
  }
  
  
  
  
  cout<<dp[n];
  
  
 return 0; 
}




Measured memory_bytes: 1792
import math

N = int(input())
A = list(map(int, input().split()))

inf = int(1e6+5)
C = [0]*inf

for a in A:
    C[a] += 1

pa = True
se = True
for i in range(2, inf):
    cnt = 0
    cnt += sum(C[i::i])
    if cnt > 1:
        pa = False
    if cnt == N:
        se = False
        
if pa:
    print("pairwise coprime")
elif se:
    print("setwise coprime")
else:
    print("not coprime")


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;


int main() {
    string s; cin >> s;
    int ans = 0;
    int i = 0;
    while(i < s.size()){
        if(s[i] == '?'){
            s[i] = 'D';
        }
        i++;
    }
    cout << s << "\n";
}

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

int main(){
	int a[10];
	for(int i=0;i<10;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+10);
	printf("%d\n%d\n%d\n",a[9],a[8],a[7]);
	return 0;
}

Measured memory_bytes: 2756
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        
        List<Character> list = new ArrayList<Character>();
        int i = 0;
        
        while (n != 0) {
            list.add((char) ((n - 1) % 26 + 'a'));
            n = (n - 1) / 26;
        }
        
        Collections.reverse(list);
        
        for(char c : list){
            System.out.print(c);
        }
    }
}

Measured memory_bytes: 35600
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
using namespace std;
const int MOD = (int)1e9+7;
void solve()
{
   ll A,B,H,M;
   cin>>A>>B>>H>>M;
   long double theta=(long double)(11*M-60*H)/2.0;
   theta=theta*(PI/180.0);
   long double Result=(long double)(A*A+B*B)-(long double)(2*B*A)*cos(theta);
   cout<<fixed<<setprecision(20)<<sqrt(Result)<<endl;
}
int  main()
{
    IOS
        solve();
    return 0;
}



Measured memory_bytes: 4192
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 int A,B,C;
 cin >> A >> B >> C;
 
  bool flag = false;
  for(int i =0 ;i<=B;i++){//数列a(i) = (i*A)%Bは周期Bの数列だからi=Bまで調べる
    if((A*i)%B==C){
      flag = true;
      break;
    }
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
    
}

Measured memory_bytes: 256
N = int(input())

R_list = {}
for i in range(N):
    S, P = map(str, input().split(" "))

    if S in R_list:
        l = R_list[S]
        l.append((int(P), i+1))
    else:
        l = [(int(P), i+1)]
        R_list[S] = l

score_sorted = sorted(R_list.items(), key=lambda x:x[0])



for S in score_sorted:
    S[1].sort(reverse=True)
    for P in S[1]:
        print(P[1])



Measured memory_bytes: 3064
def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    a = numinput()
    count = 0
    for d in range(a[0], a[1] + 1):
        if a[2] % d == 0:
            count += 1
    print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
int main (){
  int n;
  cin>>n;
  int i;
  vector <int>v(n);
  vector <int>v1(n);
  for(i=0;i<n;i++){
	cin>>v[i];
    v1[i]=v[i];
  }
  int f[2];
  f[0]=n-1;
  f[1]=n-1;
  int j=0,k=-1;
  for(i=1;i<n;i++){
	if(v[i]<v[i-1]){
      f[j] = i + k;
      k++;
      j++;
      if(j==2){
        break;
      }
    }
  }
  if(j==2)
  swap(v[f[0]],v[f[1]]);
  
  sort(v1.begin(),v1.end());
    if(v1==v)
      cout<<"YES";
    else
      cout<<"NO";
  for(i=0;i<n;i++)
    //cout<<v[i];
    return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

int n;

int main(){
	ri(n);
	int Xor = 0;
	int odds = 0;
	for(int i=0; i<n; i++){
		int x;
		ri(x);
		if(x & 1) odds += 1;
		Xor ^= x;
	}
	if(Xor == 1) puts("Bob");
	else if(Xor == 0){
		if(odds > 0) puts("Alice");
		else puts("Bob");
	}
	else puts("Alice");
	return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define mp make_pair
#define pb push_back
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i < (int)(n); ++i)
#define nfor(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define correct(x, y, n, m) (0 <= x && x < n && 0 <= y && y < m)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second
#define endl "\n"

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }
template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; }
template<class T> T lcm(T a, T b) { return a / gcd (a, b) * b; }
template<class T> T sign(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); }

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int dxKn[8] = {-2, -1, 1, 2,  2,  1, -1, -2};
const int dyKn[8] = { 1,  2, 2, 1, -1, -2, -2, -1};
const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1};

const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 100;
const ll INF64 = 2e18;
const ld PI = ld(3.1415926535897932384626433832795);
const ld e = ld(2.7182818284590452353602874713527);
const ld EPS = 1e-9;

//#############################
const int MAXN = 1000005;

int main() {
    fastIO(); 
    int n = nxt();

    cout << (n + sqr(n) + sqr(n)*n) << endl;
    
    return 0;
}

Measured memory_bytes: 3648
N = int(input())
A = list(map(int, input().split()))
#greedyで解く
upflag = True
downflag = True
answer = 1
for i in range(N - 1):
    if A[i] < A[i + 1]:
        downflag = False
    if A[i] > A[i + 1]:
        upflag = False
    if not (upflag or downflag):
        answer += 1
        upflag = True
        downflag = True
print(answer)

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

int main() {
  int city, load;
  cin >> city >> load;

  vector<int> data(city);

  for (int i = 0; i < load; i++) {
    int a, b;
    cin >> a >> b;
    
    data.at(a - 1)++;
    data.at(b - 1)++;
  }

  for (int i = 0; i < city; i++) {
    cout << data.at(i) << endl;
  }
}


Measured memory_bytes: 256
var debug = false;

function check(a,b,c,d){
  if(debug) { console.log("END"); }
  if(a <= c) {
    if(c <= b) {
        // a   c (d)  b  (d)
        return Math.min(b,d) - c;
    } else {
        // a   b   c    d
        return 0;
    }
  } else {
    // c < a
    // c (d) a (d) b (d)
    if( d <= a ) {
      // c d a b
      return 0;
    } else {
      // c a  (d) b (d)
      return Math.min(b,d) - a;
    }

  }
  return -1;
}

function Main(inp) {
  var input = inp.split("\n");
  if(debug) {console.log(input)}
  var tmp = input[0].split(" ");
  if(debug) { console.log(parseInt(tmp[0],10))}
  var target = tmp.map(function(x){return parseInt(x,10);});
  if(debug) {console.log(target)}

  console.log(check(target[0],target[1],target[2],target[3]));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
unittest
{
	assert( [ "4", "2 3 5", "2 1 5", "1 2 5", "3 2 5" ].parse.expand.solve == "2 2 6" );
	assert( [ "2", "0 0 100", "1 1 98" ].parse.expand.solve == "0 0 100" );
	assert( [ "3", "99 1 191", "100 1 192", "99 0 192" ].parse.expand.solve == "100 0 193" );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	auto xyhs = new long[ 3 ][ n ];
	foreach( ref xyh; xyhs )
	{
		input.popFront;
		xyh = input.front.split.to!( long[] );
	}
	return tuple( xyhs );
}

auto solve( long[ 3 ][] xyhs )
{
	foreach( cx; 0 .. 101 )
	{
		LOOP: foreach( cy; 0 .. 101 )
		{
			// 高さが0より大きくなるやつで仮の高さを決める
			auto ch = 0L;
			foreach( xyh; xyhs )
			{
				if( 0 < xyh[ 2 ] )
				{
					// max( ch - ( x - cx ).abs - ( y - cy ).abs, 0 ) == h
					// -->  ch == h + ( y - cy ).abs + ( x - cx ).abs
					auto ch_t = xyh[ 2 ] + ( xyh[ 0 ] - cx ).abs + ( xyh[ 1 ] - cy ).abs;
					if( ch_t != 0 )
					{
						ch = ch_t;
						break;
					}
				}
			}
			if( ch == 0 ) continue LOOP;
			
			// 仮の高さが全部に当てはまるか判定
			foreach( xyh; xyhs )
			{
				if( max( ch - ( xyh[ 0 ] - cx ).abs - ( xyh[ 1 ] - cy ).abs, 0 ) != xyh[ 2 ] ) continue LOOP;
			}
			return format("%d %d %d", cx, cy, ch );
		}
	}
	
	assert( false );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int w, h;
char c[51][51];
bool f[51][51];
int ans = 0;


bool contain(int y, int x){
    return (0 <= y && y < h && 0 <= x && x < w);
}

void dfs(int y, int x){
    f[y][x] = true;
    if(c[y][x] == '0') return;
    rep(i, 0, 3){
        rep(j, 0, 3){
            int ny = y + i - 1;
            int nx = x + j - 1;
            if(contain(ny, nx) && f[ny][nx] == false){
                dfs(ny, nx);
            }
        }
    }
    return;
}

signed main(){
    while(cin >> w >> h){
        if(w + h == 0) break;
        rep(i, 0, h){
            rep(j, 0, w){
                cin >> c[i][j];
            }
        }
        rep(i, 0 ,51){
            rep(j, 0, 51){
                f[i][j] = false;
            }
        }
        // cout << -1 << endl;
        ans = 0;
        rep(i, 0, h){
            rep(j, 0 ,w){
                if(c[i][j] == '1' && f[i][j] == false){
                    // cout << i << ' ' << j << endl;
                    dfs(i, j);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }

}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define in2(x, y) int x,y;cin>>x>>y
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

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

#define lim5 100002
#define lim9 1000000002

int CanMake(int a, int b, int c) {
	if (a < b + c && b < c + a && c < a + b) {
		return 1;
	}
	return 0;
}

int main() {
	ll n, ans=0;
	cin >> n;
	ll sq = sqrt(n);

	for (ll i = sq; i <= n; ++i) {
		if (n % i == 0) {
			ans += i - 1;
			ans += n / i - 1;
			break;
		}

		if (n % (sq - (i - sq)) == 0) {
			ans += (sq - (i - sq)) - 1;
			ans += n / (sq - (i - sq)) - 1;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;


int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    while(0 < s.size()){
        if(s == t)  break;
        s = s.substr(1);
        t = t.substr(0, t.size()-1);
    }

    cout << 2*n-s.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N_MAX 10000
#define S_MAX 100000000

int main(){
  int i,j=0,c=0,n,A[N_MAX],flag;
  double sqrtNum;
  scanf("%d",&n);
  if(n>N_MAX || n<=0)exit(8);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(A[i]>S_MAX || A[i]<2)exit(8);
  }
  
  for(j=0;j<n;j++){
    flag=0;
    if(A[j]%2==0 && A[j]!=2){
      flag=1;
    }
    else{
    sqrtNum = sqrt(A[j]);
    for(i=3;i<=sqrtNum;i+=2){
      if(A[j]%i==0){
	flag=1;
	break;
      }    
    }
    if(flag==0)c++;
    }
  }
  printf("%d\n",c);
  return 0;
}
  



Measured memory_bytes: 2124
n, k = map(int, input().split())
mod = 10**9+7
dp = [0]*(k+1)
ans = 0
for i in range(1, k+1)[::-1]:
    res = pow(k//i, n, mod)
    for j in range(i*2, k+1, i):
        res-=dp[j]
    dp[i] = res%mod
    ans+=i*res
    ans%=mod
print(ans)

Measured memory_bytes: 68892
S = input()

while True:
    if "dreameraser" in S:
        S = S.replace("dreameraser", "")
    elif "dreamerase" in S:
        S = S.replace("dreamerase", "")
    elif "dreamer" in S:
        S = S.replace("dreamer", "")
    elif "eraser" in S:
        S = S.replace("eraser", "")
    elif "dream" in S:
        S = S.replace("dream", "")
    elif "erase" in S:
        S = S.replace("erase", "")
    else:
        if S == "":
            print("YES")
        else:
            print("NO")
        break


Measured memory_bytes: 3188
A,B,C = sorted(list(map(int,input().split())))
if (B-A)%2==0 and (C-B)%2==0:
    cnt = (B-A)//2+C-B
elif (B-A)%2==0 and (C-B)%2==1:
    cnt = (B-A)//2+C-B
elif (B-A)%2==1 and (C-B)%2==0:
    cnt = 1+(B+1-A)//2+C-B
else:
    cnt = (B+1-A)//2+C+1-B
print(cnt)

Measured memory_bytes: 38384
#include <stdio.h>
 
using namespace std;
 
int main(){
    char str[20001];
    int m,tmp,length;
    while(true){
        scanf("%s",str);
        if(str[0] == '-') break;
        length = 0;
        for(int k = 0; str[k] != '\0';k++) length++;
        scanf("%d",&m);
        int index = 0;
        for(int i = 0; i < m; i++){
            scanf("%d",&tmp);
            for(int j = 0; j < tmp; j++){
                str[index+length] = str[index];
                index++;
            }
        }
        for(int p = 0; p < length; p++){
            printf("%c",str[index+p]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 2588
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    REP (i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    REP (i, m) {
        int b;
        cin >> b;
        mp[b]++;
    }
    vector<int> v, u;
    for (auto p : mp) {
        if (p.second == 2) v.push_back(p.first);
        u.push_back(p.first);
    }
    cout << v.size() << " " << u.size() << endl;
    for (int vv : v) cout << vv << endl;
    for (int uu : u) cout << uu << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 18536
n,q=map(int, input().split())
go_list=[[] for i in range(n+1)]
cnt=[0]*(n+1)
Oya=[False]*(n+1)
Oya[1]=True
for i in range(n-1):
    a,b=map(int, input().split())
    go_list[a].append(b)
    go_list[b].append(a)

for i in range(q):
    p,x=map(int, input().split())
    cnt[p]+=x

from collections import deque
que=deque()

que.append(1)
sumi=[False]*(n+1)
sumi[1]=True
while que:
    ne=que.popleft()
    for i in go_list[ne]:
        if not sumi[i]:
            cnt[i]+=cnt[ne]
            sumi[i]=True
            que.append(i)

cnt.pop(0)
print(*cnt)

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

void solve()
{
    int n, m; cin >> n >> m;
    int minval = INT_MIN, maxval = INT_MAX;
    for (int i = 0; i < m; ++i) {
        int l, r; cin >> l >> r;
        minval = max(minval, l);
        maxval = min(maxval, r);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += i >= minval && i <= maxval;
    }
    cout << ans << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N),indegree(N),vis(N); char st[N];
vector<int> adj[N];
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
bool comp(const pii a, const pii b)
{
    if(a.se==b.se)
    return a.fi<b.fi;
    return a.se<b.se;
}
vector<vector<int>> dp,v;
void solve()
{
    int k,a,b; cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK";
            return;
        }
    }
    cout<<"NG";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 19484
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v(100000),v1;
int main()
{
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>v[i];
    for(int i=-100;i<=100;++i)
    {
        int sum=0;
        for(int j=0;j<n;++j)
        {
         sum+=pow(v[j]-i,2);
        }
        v1.push_back(sum);
    }
    int mn=1e9;
    for(int i=0;i<v1.size();++i)
        mn=min(mn,v1[i]);
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))

c = [-1, -1 ,-1]

sum = 1
tmp = 0
for a in A:
    sum = sum * c.count(a-1) % 1000000007
    if a-1 == c[0]:
        c[0] += 1
        tmp = c.count(c[0] - 1) + 1
    elif a-1 == c[1]:
        c[1] += 1
        tmp = c.count(c[1]-1) + 1
    elif a-1 == c[2]:
        c[2] += 1
        tmp = c.count(c[2] - 1) + 1
print(sum)


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

int main(){
    char c;
    cin >> c;
    if(c=='A' || c=='B' || c=='C' || c=='D' || c=='E' || c=='F' || c=='G' || c=='H'
       || c=='I' || c=='J' || c=='K' || c=='L' || c=='M' || c=='N' || c=='O'|| c=='P'
       || c=='Q' || c=='R' || c=='S' || c=='T' || c=='U' || c=='V' || c=='W' || c=='X'
        || c=='Y' || c=='Z') cout << "A" << endl;
    else cout << "a" << endl;
}

Measured memory_bytes: 3612
def solve(e,y):
    if e == 0:
        if y < 1912:
            r = 'M' + str(y-1868+1)
        elif y < 1926:
            r = 'T' + str(y-1912+1)
        elif y < 1989:
            r = 'S' + str(y-1926+1)
        else:
            r = 'H' + str(y-1989+1)
    else:
        yy = [0,1868,1912,1926,1989]
        r = yy[e] + y - 1

    return r

def main():
    E,Y = map(int,input().split())
    print(solve(E,Y))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7792
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	ll h, w;
	cin >> h >> w;
	if (!cin) return false;

	if (h == 1 || w == 1) cout << "1\n";

	else {
		if (h * w % 2 == 1) cout << (h * w) / 2 + 1 << '\n';
		else cout << (h * w) / 2 << '\n';
	}

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N, M, K, Q, W, H, R, C;
int lr[110][110];
int bu[110][110];
int dis[110][110];

int main() {
    vector<int> ans;
    while (true) {
        cin >> W >> H;
        if (W == 0 && H == 0) break;
        REP(i, 2 * H - 1) {
            if (i % 2 == 0) {  // 左右
                REP(j, W - 1) { cin >> lr[j][i / 2]; }
            } else {  // 上下
                REP(j, W) { cin >> bu[j][i / 2]; }
            }
        }

        REP(y, H) {
            REP(x, W) { dis[x][y] = -1; }
        }

        queue<P> que;
        que.push({0, 0});
        dis[0][0] = 1;
        while (!que.empty()) {
            P now = que.front();
            que.pop();
            int x = now.first;
            int y = now.second;
            if (0 <= x - 1 && lr[x - 1][y] == 0 && dis[x - 1][y] == -1) {
                que.push({x - 1, y});
                dis[x - 1][y] = dis[x][y] + 1;
            }
            if (x + 1 < W && lr[x][y] == 0 && dis[x + 1][y] == -1) {
                que.push({x + 1, y});
                dis[x + 1][y] = dis[x][y] + 1;
            }
            if (0 <= y - 1 && bu[x][y - 1] == 0 && dis[x][y - 1] == -1) {
                que.push({x, y - 1});
                dis[x][y - 1] = dis[x][y] + 1;
            }
            if (y + 1 < H && bu[x][y] == 0 && dis[x][y + 1] == -1) {
                que.push({x, y + 1});
                dis[x][y + 1] = dis[x][y] + 1;
            }
        }
        /*
        REP(y, H) {
            REP(x, W) { cout << dis[x][y] << " "; }
            cout << endl;
        }
        */
        if (dis[W - 1][H - 1] == -1) {
            ans.push_back(0);
        } else {
            ans.push_back(dis[W - 1][H - 1]);
        }
    }

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

    return 0;
}



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

int main() {
    int a[3];
    int n;
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> a[0] >> a[1] >> a[2];
        sort(begin(a), end(a));
        if(a[0]*a[0] + a[1]*a[1] == a[2]*a[2]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int A = in.nextInt();
        int B = in.nextInt();
        if(A <= 8 && B <= 8){
            System.out.println("Yay!");
        }else{
            System.out.println(":(");
        }
    }
}


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

typedef long long ll;
const ll INF = 1LL << 60;

int N2;
vector<ll> a, b, c;
ll dp[(int)1e5 + 10][3];

int main() {
    cin >> N2;
    a.resize(N2);
    b.resize(N2);
    c.resize(N2);
    rep(i, N2) cin >> a[i] >> b[i] >> c[i];

    // dp[i][j]
    // i: 何日めか
    // j: 前日に何をしたか 0 ~ 2 
    rep(i, N2) {
        rep(j, 3) {
            ll tmp = 0;
            // 活動種類 j 以外の max
            rep(k, 3) {
                if (k == j) continue;

                // if (k == 0) tmp = max(tmp, a[i]);
                // if (k == 1) tmp = max(tmp, b[i]);
                // if (k == 2) tmp = max(tmp, c[i]);
                ll tmp = 0;
                switch (k)
                {
                case 0:
                    tmp = a[i];
                    break;
                case 1:
                    tmp = b[i];
                    break;
                case 2:
                    tmp = c[i];
                    break;
                }

                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + tmp);
            }
        }
    }

    ll ans = 0;
    rep(j, 3) {
        ans = max(ans, dp[N2][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    double xa, ya, ra, xb, yb, rb;
    int i;
    double d;

    n = sc.nextInt();
    for(i = 0;i < n;i++){
      xa = sc.nextDouble();
      ya = sc.nextDouble();
      ra = sc.nextDouble();
      xb = sc.nextDouble();
      yb = sc.nextDouble();
      rb = sc.nextDouble();
      d = Math.sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));

      if(ra > d + rb)out.println("2");
      else if(rb > d + ra)out.println("-2");
      else if(ra + rb < d)out.println("0");
      else out.println("1");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20512
from itertools import permutations
base = "=+-*()01"
s = input()
l = len(s)
mapping = {}
counter = {}
cnt = 0
for c in s:
    if c in base:
        continue
    if c not in mapping:
        mapping[c] = cnt
        cnt += 1
    v = mapping[c]
    counter[v] = counter.get(v, 0) + 1
if cnt > 8:
    print(0)
    exit(0)

def solve(read):
    cur = failed = 0
    def next():
        nonlocal cur
        cur += 1
    def error():
        nonlocal failed
        failed = 1
    def number():
        res = 0
        if read(cur) not in "01":
            error()
        first = 1
        while 1:
            c = read(cur)
            if c not in "01":
                break
            if not first and res == 0:
                error()
            res = (res << 1) ^ int(c)
            next() # "0" or "1"
            first = 0
        return res
    def factor():
        c = read(cur)
        if c == "-":
            next() # "-"
            return -factor()
        elif c == "(":
            next() # "("
            val = expr()
            if read(cur) != ")":
                error()
            next() # ")"
            return val
        return number()
    def term():
        res = 1
        while 1:
            res *= factor()
            c = read(cur)
            if c != "*":
                break
            next() # "*"
        return res
    def expr():
        res = 0
        op = "+"
        while 1:
            if op == "+":
                res += term()
            else:
                res -= term()
            c = read(cur)
            if c not in "+-":
                break
            next() # "+" or "-"
            op = c
        return res
    if sum(read(i) == "=" for i in range(l)) != 1:
        return 0
    lv = expr()
    next() # "="
    rv = expr()
    if not failed and cur == l:
        return lv == rv
    return 0

def get(b):
    def read(cur):
        if l <= cur:
            return "$"
        if s[cur] in base:
            return s[cur]
        return b[mapping[s[cur]]]
    return read

ans = 0
for b in permutations(base, cnt):
    ans += solve(get(b))
print(ans)

Measured memory_bytes: 7952
def main():
  s = input()
  if set(s) == 1:
    print(0)
    exit()
  group_count = 1
  v = s[0]
  for i in range(1, len(s)):
    if v == s[i]:
      continue
    group_count += 1
    v = s[i]
  print(group_count-1)
    
  

def input_list():
  return map(int, input().split())

import math
main()

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

int main() {
	long long n,a,b;cin>>n>>a>>b;
	if(n==1){
		if(a!=b){
		cout<<0<<endl;}
		else{
			cout<<1<<endl;
		}
		return 0;
	}
	if(a>b){
		cout<<0<<endl;
		return 0;
	}
	cout<<(n-2)*(b-a)+1<<endl;
	return 0;
}


Measured memory_bytes: 256