akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {

    public static void main(String[] args){
        Scanner Ent = new Scanner(System.in);
        int number = Ent.nextInt();
        boolean a = true;
        for (int i = 1; i < 10; i++) {
            if( number % i == 0){
                int cociente = number / i;
                if(cociente>0 && cociente<10){
                    System.out.println("Yes");
                    a = false;
                    break;
                }
            }
        }
        if(a){
            System.out.println("No");
        }

    }
}

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

int main(){
    string s;
    cin >> s;
    int ans = 0;

    int front = 0, back = s.size() - 1;

    while(front < back){
        if(s[front] == s[back]){

            front++;
            back--;
            continue;
        }else if(s[front] == 'x'){
            ans++;
            front++;
            continue;
        }else if(s[back] == 'x'){
            ans++;
            back--;
            continue;
        }else{
            cout << -1 << "\n";
            return 0;
        }
    }

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

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

vector<ll> to[200001];
vector<ll> ans;
void dfs(ll v, ll p=-1) {
	for (ll u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u,v);
	}
}


int main() {
	ll n,q;
	cin >> n >> q;
	rep(i,n-1) {
		ll a,b;
		cin >> a >> b;
		a--,b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans.resize(n);
	rep(i,q) {
		ll p,x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}
	dfs(0);

	rep(i,n) {
		cout << ans[i] << endl;
	}

	return 0;

}


Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define pb push_back

#define rep(var,start,end)       for(int var=start;var<end;var++)
#define erep(var,start,end)      for(int var=start;var<=end;var++)
#define rrep(var,start,end)      for(int var=start;var>=end;var--)

#define pa(x)                    cout<<x<<endl

#define pii                      pair<int,int>
#define pci                      pair<char,int>
#define pll                      pair<ll,ll>
#define test                     int t;cin>>t;while(t--)

ll modularExponentiation(ll x,ll n,ll M){
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modularExponentiation((x*x)%M,n/2,M);
    return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;
}
template<class T> 
T power(T n, T p){ if(p==0) return 1; else return power(n,p-1)*n;} 

void solve(){
    int n,m;
    cin>>n>>m;
    int a[n],sum=0;
    rep(i,0,n) {
        cin>>a[i];
        sum+=a[i];
    }
    double threshold= sum/(4.00*m);
    threshold=ceil(threshold);
  	int x=0;
    rep(i,0,n){
        if(a[i]>=threshold) x++;
    }
    if(x>=m) cout<<"Yes";
    else cout<<"No";
}

int main()
{
    bs;
    solve();
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  int A,B;
  cin>>n>>A>>B;
  VEC<int>p(n);
  int a,b,c;
  a=b=c=0;
  REP(i,0,n){
    int t;
    cin>>t;
    if(t<=A)++a;
    else if(t<=B)++b;
    else ++c;
  }
  cout<<min({a,b,c});

  return 0;
}


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

Measured memory_bytes: 596
H, W = map(int, input().split())

a = []
n = 0
ans = []

for h in range(H):
    a.append(list(map(int, input().split())))
    for w in range(W):
        a[h][w] %= 2

for h in range(H):
    for w in range(W - 1, 0, -1):
        if a[h][w] != 0:
            n += 1
            ans.append("{} {} {} {}".format(h + 1, w + 1, h + 1, w))
            a[h][w - 1] = (a[h][w - 1] + a[h][w]) % 2

for h in range(H - 1, 0, -1):
    if a[h][0] != 0:
        n += 1
        ans.append("{} {} {} {}".format(h + 1, 1, h, 1))
        a[h - 1][0] = (a[h - 1][0] + a[h][0]) % 2

print(n)
print("\n".join(ans))

Measured memory_bytes: 20124
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,k;

int main(){
	cin>>n>>k;
	int t=0;
	while(n){
		n/=k;
		t++;
	}
	cout<<t<<endl;
}

Measured memory_bytes: 256
void main()
{
    long n = readln.chomp.to!long;

    long a, b, ab;
    long cnt;
    foreach (i; 0 .. n)
    {
        string s = readln.chomp;
        cnt += s.count("AB");
        if (s[$-1] == 'A' && s[0] == 'B') ++ab;
        else if (s[$-1] == 'A') ++a;
        else if (s[0] == 'B') ++b;
    }

    if (ab > 0)
    {
        cnt += ab - 1;
        if (max(a, b) > 0) cnt += min(a, b) + 1;
    }
    else
    {
        cnt += min(a, b);
    }

    cnt.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long long ll;
int num[100005];
int main(void)
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
        scanf("%d",&num[i]);
    sort(num,num+n);
    int maxn = num[n-1];
    int mid = (maxn+1)/2;
    int maxm;
    int s = 1e9;
    for(int i = 0;i < n;i++)
    {
        if(num[i] == mid)
            maxm = num[i];
        else
        {
            if(abs(num[i] - mid) < s)
            {
                maxm = num[i];
                s = abs(num[i] - mid);
            }
        }
    }
    printf("%d %d\n",maxn,maxm);
    return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        String s = in.next();
        char[] c = s.toCharArray();
        boolean check = true;
        for(int i = 0; i<2; i++){
            if(c[i]==c[i+1] && c[i]==c[i+2]){
                out.println("Yes");
                check = false;
                break;
            }
        }
        if(check) out.println("No");
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 32936
using System;
class Program
{
    static void Main(string[] args)
    {
        var n = Read();
        Write((int)(n / 2) * (int)((n + 1) / 2));
    }

    static void Write(string s) { Console.WriteLine(s); return; }
    static void Write(long n) { Console.WriteLine(n.ToString()); return; }
    static string ReadStr() { return Console.ReadLine(); }
    static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
    static long Read() { return long.Parse(Console.ReadLine()); }
    static long[] Read(long n)
    {
        long[] p = new long[n];
        string[] t = Console.ReadLine().Split(' ');
        for(long i = 0; i < n; i++) { p[i] = long.Parse(t[i]); }
        return p;
    }
    static long abs(long n) { return (n > 0) ? n : -n; }
    static long gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; }
    static long gcd(long a, long b) { return (a==0)?b:gcd(b % a, a); }
    static long lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; }
    static long lcm(long a, long b) { return a * b / gcd(a, b); }
    static long max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p>n[i])?p:n[i]; } return p; }
    static long min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p<n[i])?p:n[i]; } return p; }
    static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
    static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
    static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
    static string clip(string s, int start, int count)
    {
        if (start + count < s.Length) { s = s.Remove(start + count); }
        if (start > 0) { s = s.Remove(0, start); }
        return s;
    }
    static long ConvToLong(string n, int b)
    {
        long m = 0; long t = 1;
        for (int i = n.Length - 1; i >= 0; i--)
        {
            int k = int.Parse(n[i].ToString());
            m += t * k;
            t *= b;
        }
        return m;
    }
}


Measured memory_bytes: 11092
def main():
    n = int(input())
    S = list(map(int, input().split()))

    q = int(input())
    T = list(map(int, input().split()))
    
    res = 0
    for t in T:
        res += binary_search(S, t)
        
    print(res)
        
def binary_search(S, t):
    left = 0
    right = len(S)
    
    res = 0
    while left < right:
        mid = (left + right) // 2
    
        if t > S[mid]:
            left = mid + 1
        elif t < S[mid]:
            right = mid
        else:
            res += 1
            break
            
    return res
    
if __name__ == '__main__':
    main()
    


Measured memory_bytes: 16708
#include<bits/stdc++.h>
using namespace std;
vector<int> arr1,arr2;
int n;long long k;
bool ok(long long target){
  long long tmp = k;
  for(int i=0;i<n;++i){
    long long curr = 1ll * arr1[i] * arr2[i];
    if(curr > target){
      long long mins = (curr - target) / (1ll*arr2[i]);
      if((curr - target)%arr2[i]>0){
        mins++;
      }
      tmp -= mins;
      //cout<<i<<" "<<mins<<" "<<tmp<<endl;
      if(tmp<0){
        return false;
      }
    }
    
  }
  return true;
}
int main(){
  cin>>n>>k;
  arr1 = vector<int>(n);
  arr2 = vector<int>(n);
  for(int i=0;i<n;++i)cin>>arr1[i];
  for(int i=0;i<n;++i)cin>>arr2[i];
  sort(arr1.begin(),arr1.end());
  sort(arr2.begin(),arr2.end());
  for(int i=0;i<=n/2;++i){swap(arr2[i],arr2[n-1-i]);}
  
  long long l = 0;
  long long r = 1e18;
  while(l<r){
    long long mid = (l+r)/2;
    if(ok(mid)){
      r = mid;
    }else{
      l = mid+1;
    }
  }
  cout<<l<<endl;
  
  return 0;
}


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

int main() {
  int n;cin>>n;
  int an[26][n];rep(i,26)rep(j,n)an[i][j]=0;
  rep(i,n) {
    string s;cin>>s;
    rep(j,s.size()) {
      int c = s[j] - 'a';
      an[c][i] ++ ;
    }
  }
  rep(i,26) {
    int m = *min_element(an[i], an[i]+n);
    char cc = 'a' + i;
    cout << string(m, cc);
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int max(int a,int b){
  return (a<b)?b:a;
}
int main(){
  int n,v[101],w[101],W;
  int dp[101][10001];
  cin >> n>>W;
  for(int i=0;i<n;i++){
    cin >> v[i] >> w[i];
  }
  for(int i=0;i<=n;i++){
    for(int j=0;j<=W;j++){
      if(i==0||j==0)dp[i][j]=0;
      else if(j<w[i-1])dp[i][j]=dp[i-1][j];
      else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
    }
  }
  cout << dp[n][W]<<endl;
}



Measured memory_bytes: 7040
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007

using namespace std;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll inv(ll a, ll b = MOD)
{
    ll x = 0, y = 1, u = 1, v = 0;
    while(a!=0)
    {
        ll q = b/a, r = b%a, m = x-u*q, n = y-v*q;
        b = a, a = r, x = u, y = v, u = m, v = n;
    }
    return modx(x);
}

ll ncr(ll a, ll b)
{
    ll ret = 1;
    for(ll i = a; i>a-b; i--)
        ret = modx(ret*i);
    for(ll i = 1; i<=b; i++)
        ret = modx(ret*inv(i));
    return ret;
}

ll x, y;

int main()
{
    cin >> x >> y;
    if(((x+y)%3)||((2*x-y)%3)||(2*x<y)||(2*y<x))
        cout << 0 << endl;
    else
        cout << ncr((x+y)/3,(2*x-y)/3) << endl;
}

Measured memory_bytes: 256
import heapq

class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign


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

heap_l = Heapq(A[:n])
heap_r = Heapq(A[2*n:],desc=True)

max_l = [0]*(n+1)
min_r = [0]*(n+1)
max_l[0] = sum(A[:n])
min_r[0] = sum(A[2*n:])

for i in range(n):
    p = heap_l.pop()
    heap_l.push(max(A[n+i],p))
    max_l[i+1] = max_l[i]+max(0,A[n+i]-p)

    q = heap_r.pop()
    heap_r.push(min(A[-1-i-n],q))
    min_r[i+1] = min_r[i]+min(0,A[-1-i-n]-q)

ans = -float('inf')

for i in range(n+1):
    ans = max(ans,max_l[i]-min_r[-1-i])

print(ans)

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

int main () {
  int i, j, k, N, A, B, z, count=0, ans=0, sum;
  
  cin >> N >> A >> B;
  
  rep(i,N){
    z=i+1;
    sum=0;
    for(;z!=0;){
      sum+=z%10;
      z/=10;
    }
    if(sum>=A && sum<=B) ans +=i+1;
  }
  
  cout << ans;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  ll x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  vl red(a);
  vl green(b);
  vl nocolor(c);
  vector<pair<ll,string>> all(a+b+c);
  rep(i,a){cin >> all[i].first;all[i].second="3red";}
  rep(j,b){cin >> all[j+a].first;all[j+a].second="2green";}
  rep(i,c){cin >> all[i+a+b].first;all[i+a+b].second="1nocolor";}
  sort(all.begin(),all.end());
  reverse(all.begin(),all.end());

  ll ans=0;
  ll xx=0;//xまで
  ll yy=0;//yまで
  ll no=0;
  rep(i,a+b+c){
    if((x!=xx&&all[i].second=="3red")||(y!=yy&&all[i].second=="2green")||(no<x-xx+y-yy&&all[i].second=="1nocolor")){
      ans+=all[i].first;
    }
    else continue;
    //追加した場合の話
    if(all[i].second=="3red")xx++;
    else if(all[i].second=="2green")yy++;
    else if(all[i].second=="1nocolor"){
      no++;
    }
    if(xx+yy+no==x+y)break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 21376
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    if(n == 1){
        cout << 1 << '\n';
        return 0;
    }
    vector<int> xs(n), ys(n);
    for(int i = 0; i < n; i++){
        cin >> xs[i] >> ys[i];
    }
    unordered_map<ll, int> cnts;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j){ continue; }
            ll dx = xs[j] - xs[i], dy = ys[j] - ys[i];
            cnts[dx * (1ll << 32) + dy]++;
        }
    }
    printde(cnts);
    int maxi = 0;
    for(auto& p : cnts){
        maxi = max(maxi, p.second);
    }
    cout << n - maxi << '\n';
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-

from collections import Counter

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

c = Counter(a)
ans = 1
mod = 10 ** 9 + 7
for k, v in c.items():
    if k == 0:
        num = 1
    else:
        num = 2

    if v == num:
        ans *= v
        ans %= mod
    else:
        ans = 0
        break

print(ans)


Measured memory_bytes: 14820
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>

#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    int K, N;
    cin >> N >> K;
    vector<int> P(N);
    rep(i, N)
        cin >> P[i];

    sort(P.begin(), P.end());
    uint64_t ret = 0;
    rep(i, K)
        ret += P[i];
    cout << ret << endl;


    return 0;
}


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

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

	int ans;
	if (a[0]*a[1]<a[2]){
		ans = a[0]*a[1];
	}else{
		ans = a[2];
	}

	cout << ans << endl;
}

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

using namespace std;

int N, A[100000];
int gcds[100000];
int igcds[100000];

int gcd(int a, int b){
	if(!b){
		return a;
	}
	return gcd(b, a % b);
}

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

	int sgcd = A[0];
	int igcd = A[N - 1];
	for (int i = 0; i < N; i++){
		sgcd = gcd(sgcd, A[i]);
		igcd = gcd(igcd, A[N - 1 - i]);
		gcds[i] = sgcd;
		igcds[N - 1 - i] = igcd;
	}

	int ans = 0;
	for (int i = 0; i < N; i++){
		if (i == 0){
			ans = igcds[i + 1];
		}else if(i == N-1){
			ans = max(ans, gcds[N - 2]);
		} else {
			ans = max(ans, gcd(gcds[i - 1], igcds[i + 1]));
		}
	}

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

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
// utility
#define all(i) (i).begin(), (i).end()
#define rep(i, n) for(int i=0;i<int(n);++i)
#define rrep(i, n) for(int i=int(n)-1;i>=0;--i)
#define in(a, x, b) (a<=x && x<b)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;


signed main() {
  int N;
  std::cin >> N;

  map<int, int> a{};

  int d;
  rep(i, N){
    std::cin >> d;
    a[d]++;
  }

  std::cout << a.size();
  std::cout << std::endl;


  return 0;
}

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

typedef long long ll;

int ac, wa, tle, re;

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

    while(t--){
        string s;
        cin >> s;

        if(s == "AC"){
            ac++;
        }
        else if(s == "WA"){
            wa++;
        }
        else if(s == "TLE"){
            tle++;
        }
        else if(s == "RE"){
            re++;
        }
    }

    cout <<"AC x " << ac << "\n";
    cout <<"WA x " << wa << "\n";
    cout <<"TLE x " << tle << "\n";
    cout <<"RE x " << re << "\n";

}


Measured memory_bytes: 3628
# coding: utf-8
import math
import bisect
import numpy as np
N, k = map(int,input().split())
X = list(map(int,input().split()))
#if 0 in X:
 #   k -= 1
ans = float('inf')
for i in range(N-k+1):
    a = X[i]
    b = X[i+k-1]
    #print(a, b)
    if np.sign(a)*np.sign(b) >= 0:
        ans = min(ans, max(abs(a), abs(b)))
        #print("d="+str(max(abs(a), abs(b))))
    else:
        ans = min(ans, abs(a)+abs(b)+min(abs(a), abs(b)))
        #print("d="+str(abs(a)+abs(b)))
print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <cassert>
#include <queue>

#define INF 922337203685477580
typedef long long ll;

using namespace std;

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

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


  ll op = 0LL;
  ll sum = 0LL;

  if (a[0] != 0) {
    sum = a[0];
    for (int i = 1; i < n; i++) {
      if (!(sum * (sum + a[i]) < 0)) {
        ll tmp_a = sum < 0 ? abs(sum) + 1 : -1 *(abs(sum) + 1);
        op += abs(tmp_a - a[i]);
        sum = sum + tmp_a;
      } else {
        sum += a[i];
      }
    }

    ll op_m = op;
    if (a[0] > 0) {
      sum = -1LL;
      op = a[0] + 1;
    } else {
      sum = 1LL;
      op = -1 * a[0] + 1;
    }
    for (int i = 1; i < n; i++) {
      if (!(sum * (sum + a[i]) < 0)) {
        ll tmp_a = sum < 0 ? abs(sum) + 1 : -1 *(abs(sum) + 1);
        op += abs(tmp_a - a[i]);
        sum = sum + tmp_a;
      } else {
        sum += a[i];
      }
    }
    op = min(op, op_m);
  } else {
    sum = 1;
    op = 1;
    for (int i = 1; i < n; i++) {
      if (!(sum * (sum + a[i]) < 0)) {
        ll tmp_a = sum < 0 ? abs(sum) + 1 : -1 *(abs(sum) + 1);
        op += abs(tmp_a - a[i]);
        sum = sum + tmp_a;
      } else {
        sum += a[i];
      }
    }
    ll op_m = op;

    sum = -1;
    op = 1;
    for (int i = 1; i < n; i++) {
      if (!(sum * (sum + a[i]) < 0)) {
        ll tmp_a = sum < 0 ? abs(sum) + 1 : -1 *(abs(sum) + 1);
        op += abs(tmp_a - a[i]);
        sum = sum + tmp_a;
      } else {
        sum += a[i];
      }
    }
    op = min(op, op_m);
  }

  cout << op << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline void read(int &x){
    char c = getchar();
    int p = 1;
    x = 0;
    while(!isdigit(c)){
        if(c == '-')p = -1;
        c = getchar();
    }
    while(isdigit(c)){
        x = (x << 1) + (x << 3) + (c ^ '0');
        c = getchar();
    }
    x *= p;
}
#define mid ((l + r) >> 1)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define mp make_pair
#define x first
#define y second
typedef pair<int, int> pa;
const int maxn = 100050;
int mn[maxn << 2], cnt[maxn], pre[maxn], b[maxn], n, m;
inline void push_up(int rt){
    mn[rt] = min(mn[rt << 1], mn[rt << 1 | 1]);
}
inline void build(int rt, int l, int r){
    if(l == r){
        mn[rt] = b[l];
        return ;
    }
    build(lson), build(rson);
    push_up(rt);
}
inline pair<int, int> query(int rt, int l, int r, int R, int val){
    if(l == r)return mp(mn[rt], r);
    if(R >= mid + 1 && val >= mn[rt << 1 | 1]){
        pa ret = query(rson, R, val);
        if(ret.x < val)return ret;
    }
    return query(lson, R, val);
}
inline void solve(int num){
    int R = b[num], tmp = cnt[num];
    while(R && tmp){
        int r = query(1, 0, m, num - 1, R).y;
        if(r == 0){
			cnt[0] += tmp * (R / n);
            pre[R % n] += tmp;
			return;
		}
        cnt[r] += tmp * (R / b[r]);
        R %= b[r];
		num = r;
    }
}
signed main(){
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    read(n), read(m);
    for(register int i = 1; i <= m; ++i){
        read(b[i]);
    }
    build(1, 0, m);
    cnt[m] = 1;
    for(register int i = m; i >= 1; --i){
        solve(i);
    }
	for(int i = n - 1; i >= 1; --i){
        pre[i] += pre[i + 1];
    }
	for(int i = 1; i <= n; ++i){
        printf("%lld\n", pre[i] + cnt[0]);
    }
    return 0;
}

Measured memory_bytes: 6144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  string H;
  cin >> H;
  if(H.size()%2){cout <<"No";return 0;}
  Rep(i,H.size()/2){
    if(H.at(2*i) != 'h' || H.at(2*i+1) !='i' ){
      cout << "No";return 0;
    }
  }
  cout << "Yes";
}
    

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

int main () {
	char w[100][11];
	int n, flag = 1;

	scanf ("%d", &n);
	scanf ("%s", w[0]);
	for (int i=1; i<n; i++) {
		scanf ("%s", w[i]);
		int l = strlen (w[i-1]);
		if (w[i-1][l-1] != w[i][0])
			flag = 0;
		for (int j=0; j<i-1; j++)
			if (! strcmp (w[i], w[j]))
				flag = 0;
	}

	if (flag)
		printf ("Yes\n");
	else
		printf ("No\n");

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;
vector<int> dh={-1,0,1,1,1,0,-1,-1},dw={1,1,1,0,-1,-1,-1,0};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int H,W;cin>>H>>W;
        if(H+W==0) break;
        map<string,int> MA;
        string ans="";
        
        vector<string> S(H);
        for(int i=0;i<H;i++) cin>>S[i];
        
        for(int a=0;a<H;a++){
            for(int b=0;b<W;b++){
                for(int k=0;k<8;k++){
                    string T;
                    int hnow=a,wnow=b;
                    while(1){
                        T+=S[hnow][wnow];
                        MA[T]++;
                        
                        hnow+=dh[k];
                        wnow+=dw[k];
                        
                        if(hnow<0) hnow+=H;
                        if(hnow>=H) hnow-=H;
                        
                        if(wnow<0) wnow+=W;
                        if(wnow>=W) wnow-=W;
                        
                        if(hnow==a&&wnow==b) break;
                    }
                }
            }
        }
        
        for(auto it=MA.begin();it!=MA.end();it++){
            if((*it).second>=2){
                if(ans.size()==(*it).first.size()){
                    ans=min(ans,(*it).first);
                }else if(ans.size()<(*it).first.size()){
                    ans=(*it).first;
                }
            }
        }
        
        if(ans.size()>=2) cout<<ans<<endl;
        else cout<<0<<endl;
    }
}




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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int p, q, a, n;
int cnt = 0;

int check(vi &v) {
  int bunbo = 1;
  rep (i, v.size()) {
    bunbo *= v[i];
  }
  if (bunbo > a) return 0;
  int bunsi = 0;
  rep (i, v.size()) {
    bunsi += bunbo / v[i];
  }

  int pp = p, qq = q;
  bunsi *= qq;
  pp *= bunbo;
  if (bunsi == pp) cnt++;
  if (bunsi <= pp) return 2;
  else return 1;
}

void dfs(vi &v, int bunbo) {
  if (v.size() == n) return;
  int pre;
  if (v.size() == 0) pre = a;
  else pre = v.back();

  pre = min(pre, a / bunbo + 2);
  for (int i = pre; i >= 1; i--) {
    v.push_back(i);
    int temp = check(v);
    if (temp == 0) {
      v.pop_back();
      continue;
    }
    else if (temp == 1) {
      v.pop_back();
      break;
    }
    else {
      dfs(v, bunbo * i);
      v.pop_back();
    }
  }
}

int main() {
  while (true) {
    cnt = 0;
    cin >> p >> q >> a >> n;
    if (q == 0) return 0;
    vi v;
    dfs(v, 1);
    cout << cnt << endl;
  }
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mpp make_pair
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    fast;
    string s,s1;
    cin>>s>>s1;
    vector<ll>v;
    ll n=s.size();
    ll m=s1.size();
    for(ll i=0; i<=n-m; i++)
    {
        ll cnt=0;
        for(ll j=0; j<m; j++)
        {
            if(s1[j]!=s[i+j])
            {
                cnt++;
            }
        }
        v.pb(cnt);
    }
    cout<<*min_element(v.begin(),v.end())<<endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
 
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値
 
ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}
 
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back
 
 
int main(){
    ll a; cin >> a;
    cout << a + a*a + a*a*a;
}

Measured memory_bytes: 3632
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	a = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	c=0
	for i, v in enumerate(al):
		if i % 2 == 0 and v % 2 == 1:
			c+=1
	print(c)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 61960
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int N,M,K,L;

int p[200010] = {0},r[200010] = {0};
void init(int N){
	for(int i=0;i<=N;++i) p[i] = i;
}

int root(int a){
	if(p[a] == a) return a;
	return (p[a] = root(p[a]));
}

bool is_same_set(int a,int b){
	return root(a) == root(b);
}

void unite(int a, int b){
	a = root(a);
	b = root(b);
	if(a==b) return;
	if(r[a]<r[b]){
		p[a] = b;
	}else{
		p[b] = a;
		if(r[a] == r[b]) r[a]++;
	}
}


int main(){
	cin >> N >> M;
	init(N + M);
	for(int i=1;i<=N;i++){
		cin >> K;
		for(int j=1;j<=K;j++){
			cin >> L;
			unite(i,N+L);
		}
	}
	bool ans = true;
	for(int i=2;i<=N;i++){
		if(!is_same_set(1,i)) ans = false;
	}
	if(ans) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

int main() {
	int n, h;
	std::cin >> n >> h;
	std::vector<int>a(n);
	std::vector<int>b(n);
	for (int i = 0;i < n;i++) {
		std::cin >> a[i] >> b[i];
	}
	std::sort(a.rbegin(), a.rend());
	std::sort(b.rbegin(), b.rend());
	int ans = 0;
	for (int i = 0;i < n;i++) {
		if (a[0] <= b[i]) {
			h -= b[i];
			ans += 1;
		}
		if (h <= 0) {
			break;
		}
	}
	if (h > 0) {
		ans += h / a[0];
		if (h%a[0] != 0) {
			ans += 1;
		}
	}
		std::cout << ans << std::endl;
	return 0;
}

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

int main()
{
    int a,b,c,ans=0;

    cin>>a>>b>>c;

    for(int i=a;i<=b;i++){
        if(c%i==0)ans++;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=50;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n;
ll f[N][N][N];
char s[N][N];

int main() {
	cin>>n;n<<=1;
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1),f[i][i][i]=1;
	for(int len=3;len<=n;len+=2)
		for(int l=1;l<=n-len+1;l++) {
			int r=l+len-1;
			for(int t=l+1;t<r;t++)
				for(int a=l;a<r;a+=2)
					for(int b=r;b>t;b-=2)
						for(int x=l;x<=a;x++)
							for(int y=b;y<=r;y++)
								if(s[x][y]=='1') f[l][r][t]+=f[l][a][x]*f[b][r][y]*f[a+1][b-1][t];
		}
	ll ans=0;
	for(int i=2;i<=n;i++) if(s[1][i]=='1') ans+=f[2][n][i];
	cout<<ans;
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

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

typedef pair<int ,int> P;

int main()
{
    int N,R;
    while(cin >> N >> R && N != 0 && R != 0)
    {
        int card[N];
        rep(i,N+1) { card[i] = N - i; };
        rep(i,R)
        {
            int p,c;
            cin >> p >> c;

            int tmp_card[N];
            rep(j,N) { tmp_card[j] = 0; }
            rep(j,c){ tmp_card[j] = card[p - 1 + j]; } 
            rep(j,p-1) { tmp_card[j + c] = card[j]; }
            rep(j,c + p-1) { card[j] = tmp_card[j]; }
        }
        cout << card[0] << endl;
    }
}

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

int main(){
  int n,m,x;
  int ans=INF;
  int c[100005], a[15][15];
  cin >> n >> m >> x;
  for(int i=0;i<n;i++){
    cin >> c[i];
    for(int j=0;j<m;j++)cin >> a[i][j];
  }


  for(int i=0;i<1<<n;i++){
    int tmp=i;
    int hiyo = 0;
    int rikai[15];
    for(int i=0;i<15;i++)rikai[i]=0;
    // cout << i;
    for(int j=0;j<n;j++){
      //購入
      if(tmp%2==1){
        hiyo+=c[j];
        for(int k=0;k<m;k++)rikai[k]+=a[j][k];
      }
      tmp=tmp/2;
    }
    // cout << " hiyo:" << hiyo << " ";
    bool flag=true;
    for(int j=0;j<m;j++){
      // cout << rikai[j] << " ";
      if(rikai[j]<x)flag = false;
    }
    // cout << endl;
    if(flag){
      ans = min(ans, hiyo);
    }
  }
    
  if(ans==INF)cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


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

int main(){
  
  int n,k;
  
  cin >> n >> k;
  
  int count = 0;
  
  while(n/k != 0)
  {
    count++;
    n = n/k;
  }
  
  cout << count+1;
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def insertion_sort(n,a):
    for i in range(n):
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print(' '.join(map(str,a)))
    return a
    
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    insertion_sort(n,a)



Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string x,y;
	int m,n,i,j;
	cin >> x >> y;
	m = x.length(); //use i for x
	n = y.length() ;//use j for y
	int dp[m+1][n+1] ; //rows  for x and coloumns for y
	for(i=0;i<=m;i++)
	{
		for(j=0;j<=n;j++)
		{
			if(i==0 || j==0)
			dp[i][j] = 0;
			else if(x[i-1] == y[j-1])
			dp[i][j] = 1 + dp[i-1][j-1];
			else
			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}
	if(dp[m][n] == 0)
	{
		cout << " "<<endl;
		return 0;
	}
	stack <char> s;
	for(i=m,j=n;i>0 && j>0;)
	{
		if(dp[i][j] != dp[i-1][j] && dp[i][j] != dp[i][j-1])
		{
			s.push(x[i-1]);
			i--;
			j--;
		}
		else if(dp[i][j-1] > dp[i-1][j])
		j--;
		else
		i--;
	}
	while(!s.empty())
	{
		cout<<s.top();
		s.pop();
	}
	return 0;
}

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

class C
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var x = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var xo = x.OrderBy(v => v).ToArray();
		int b1 = xo[n / 2], b2 = xo[n / 2 - 1];
		Console.WriteLine(string.Join("\n", x.Select(v => v < b1 ? b1 : b2)));
	}
}


Measured memory_bytes: 50248
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
int dp[2010][2010] = {0};
int sm[2010][2010] = {0};
signed main(){
    
    int n,m;
    cin >> n >> m;
    vector<int> s(n);
    vector<int> t(m);

    rep(i,n)cin >> s[i];
    rep(i,m)cin >> t[i];

    rep(i,2005)dp[i][0] = dp[0][i] = 1;
    
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = (dp[i][j-1] + dp[i-1][j])%MOD;
            }else{
                dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]+MOD)%MOD;
            }
        }
    }

    // for(int i = 1;i <= n;i++){
    //     for(int j = 1;j <= m;j++){
    //         if(s[i-1] == t[j-1]){
    //             dp[i][j] = (dp[i-1][j] + dp[i][j-1] + 1)%MOD;
    //         }else{
    //             dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]+MOD)%MOD;
    //         }
    //     }
    // }
    cout << dp[n][m]%MOD << endl;

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc130.contest.atcoder.jp/tasks/abc130_b

Measured memory_bytes: 32512
<?php
  $n = trim(fgets(STDIN));
  $x = explode(" ", trim(fgets(STDIN)));
  $y = explode(" ", trim(fgets(STDIN)));
  $p1 = 0;
  $p2 = 0;
  $p3 = 0;
  $max = array();
  for($i=0; $i < $n; $i++) {
    $q = $x[$i] - $y[$i];
    if ($q < 0) { $q = $q * -1; }
    array_push($max, $q);
    $p1 += $q;
    $p2 += pow($q, 2);
    $p3 += pow($q, 3);
  }
  print($p1 . "\n" . sqrt($p2) . "\n" . pow($p3, (1 / 3)) . "\n" . max($max));
?>

Measured memory_bytes: 6700
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

class Point
{
public:
    double y, x;
    Point(){
        y = x = 0.0;
    }
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(double a) const{
        return Point(y * a, x * a);
    }
    Point operator/(double a) const{
        return Point(y / a, x / a);
    }
    double length() const{
        return sqrt(y * y + x * x);
    }
    double dist(const Point& p) const{
        return sqrt(pow(y - p.y, 2) + pow(x - p.x, 2));
    }
};

class Edge{
public:
    int to;
    double time;
    Edge(){}
    Edge(int to0, double time0){
        to = to0;
        time = time0;
    }
};

int n;
double vw, vc;
vector<Point> p;

void dig(vector<vector<Edge> >& edges)
{
    edges.assign(n, vector<Edge>(0));

    for(int a=0; a<2; ++a){
        stack<pair<double, int> > stk;
        stk.push(make_pair(-DBL_MAX, -1));

        for(int i=0; i<n; ++i){
            while(p[i].y < stk.top().first - EPS)
                stk.pop();

            int j = stk.top().second;
            if(j != -1 && j != i-1){
                double t = (p[i].y - p[j].y) / (p[j+1].y - p[j].y);
                Point q = p[j] * (1-t) + p[j+1] * t;
                if(a == 0)
                    edges[j].push_back(Edge(i, p[j].dist(q) / vw + q.dist(p[i]) / vc));
                else
                    edges[n-1-i].push_back(Edge(n-1-j, p[j].dist(q) / vw + q.dist(p[i]) / vc));
            }

            stk.push(make_pair(p[i].y, i));
        }

        reverse(p.begin(), p.end());
    }
}

int main()
{
    for(;;){
        cin >> n;
        if(n == 0)
            return 0;

        cin >> vw >> vc;

        p.resize(n);
        for(int i=0; i<n; ++i)
            cin >> p[i].x >> p[i].y;

        vector<vector<Edge> > edges;
        dig(edges);

        vector<double> dp(n, DBL_MAX);
        dp[0] = 0.0;
        for(int i=0; i<n-1; ++i){
            dp[i+1] = min(dp[i+1], dp[i] + p[i].dist(p[i+1]) / vw);
            for(unsigned j=0; j<edges[i].size(); ++j)
                dp[edges[i][j].to] = min(dp[edges[i][j].to], dp[i] + edges[i][j].time);
        }

        printf("%.10f\n", dp[n-1]);
    }
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int n,m,q;
int mxp = 0;

int rec(int i,int *a,vector<vector<int>> rq){
    int point = 0;

    if(i == n-1){

        
        //rep(i,n)cout<<a[i]<<"  ";
        //*/

        rep(i,q){

            int ai = rq[i][0];
            int bi = rq[i][1];
            int ci = rq[i][2];
            int di = rq[i][3];

            //db2(ai,bi)
            //db2(ci,di)
            //ln;

            if(   a[bi]-a[ai]==ci  )point+=di;

        }
        //chmax(mxp,point);
        //db(point);ln;
        return point;

    }else{
        //vector<int> tp = a;
        rep1(j,a[i],m+1){
            a[i+1] = j;
            chmax(point ,rec(i+1,a,rq));
            //tp.pop_back();
        }

        return point;
    }
}

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    cin>>n>>m>>q;
    vector<vector<int>> rq(q,vector<int>(4));

    rep(i,q){
        rep(j,4){
            cin>>rq[i][j];
            if(j == 0 || j==1)--rq[i][j];
        }
    }


    rep1(i,1,m+1){
        //vector<int> a(n,0);
        
        int a[n] = {};
        a[0] = i;
        chmax(ans,rec(0,a,rq));
    }

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);

int main(){
  int n;cin>>n;
  int count=0;
  for(int i=1;i<=n;i++){
  	int t;cin>>t;
    count += int(t!=i);
  }
  cout<<((count==0||count==2)?"YES":"NO")<<endl;
}

Measured memory_bytes: 256