akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        String[] str = br.readLine().split(" ");
        String str = br.readLine();
        char f = str.charAt(0);
        char e = str.charAt(str.length()-1);
        System.out.println(f + Integer.toString(str.length()-2) + e);
    }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define fi                first
#define se                 second
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define pll              pair<long long,long long>
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
              const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.se >b.se);
    }
    else
        return (a.fi<b.fi);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
int main()
{
 fast;
     int t=1;
     //cin>>t;
     while(t--)
     {
       ll k,n,i=0,j=0,c=0,d=0,e=0,f=0,g=0,h=0,maxi=0,sum=0;
        string a;
         cin>>n;
         cin>>a;
         for(i=0;i<n;i++)
         {
             if(a[i]=='R')
                c++;
         }
         for(i=0;i<c;i++)
         {
             if(a[i]=='W')
                d++;
         }
         cout<<d<<endl;
     }
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  ll N, x;
  cin >> N >> x;
  ll ans = 0;
  ll a1, a2 = 0;
  cin >> a1;
  if (a1 > x) {
    ans += a1 - x;
    a1 = x;
  }
  REP(i, N - 1) {
    cin >> a2;
    if (a1 + a2 > x) {
      ans += a1 + a2 - x;
      a2 = x - a1;
    }
    a1 = a2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
P=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(P[K-1])

Measured memory_bytes: 3060
import collections
n,x,m=map(int,input().split())
if n==1 or x==0:
  print(x)
  exit()
start,end,loopcnt=0,0,0
a={x:0}
wk=x
for i in range(1,m):
  wk=(wk*wk)%m
  if not wk in a:
    a[wk]=i
  else:
    start=a[wk]
    end=i
    break
a=sorted(a.items(),key=lambda x:x[1])
koteiindex=min(n,start)
koteiwa=0
for i in range(koteiindex):
  koteiwa+=a[i][0]
loopcnt=(n-koteiindex)//(end-start)
loopindex=start-1+(n-koteiindex)%(end-start)
loopwa=0
amariwa=0
for i in range(start,end):
  if i<=loopindex:
    amariwa+=a[i][0]
  loopwa+=a[i][0]
ans=koteiwa+loopwa*loopcnt+amariwa
print(ans)


Measured memory_bytes: 82800
#include<iostream>
#include<vector>
#include<limits>
#include<cmath>

int main(int argc, char const *argv[])
{
    using namespace std;
    int N,K;
    cin>>N>>K;

    vector<int> x(N);
    for(int i=0; i<N; i++) {
        cin>>x[i];
    }
    // int ans = numeric_limits<int>::infinity();
    int ans = 1e15;
    for (int l=0; l+K<=N; l++) {
        int r = l+K-1;
        // l -> r
        ans = min(
            ans,
            min(
                abs(x[l]) + abs(x[l]-x[r]),
                abs(x[r]) + abs(x[l]-x[r])
            )
        );
    }

    cout << ans << endl;

    /* code */
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define foreach(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n;cin>>n;){
		vvi c(n,vi(n,INFTY));
		rep(i,n) rep(j,n) cin>>c[i][j];
		ll res=0;
		rep(i,n) rep(j,i)
			res+=min(c[i][j],c[j][i]);
		cout<<res<<endl;
	}
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long int
#define pii pair<int,int>
#define mii map<int,int>
#define f first
#define s second
#define mp make_pair
using namespace std;

int main() 
{
  int n,m;
  cin>>n>>m;
  vector<int>ass(m,0);
  int sum=0;
  for(int i=0;i<m;i++)
  {
    cin>>ass[i];
    sum+=ass[i];
  }
  if(sum>n)
     cout<<-1<<"\n";
  else
    cout<<n-sum<<"\n";
  
	return 0;
}

Measured memory_bytes: 3664
using System;

public class Test
{
	public static void Main()
	{
		string s = Console.ReadLine();
		int y = int.Parse(s.Substring(0,4));
		int m = int.Parse(s.Substring(5,2));
		int d = int.Parse(s.Substring(8,2));
		
		if(y>=2020){
			Console.WriteLine("TBD");
		}else if(y<=2018){
			Console.WriteLine("Heisei");
		}else if(m<=4){
			Console.WriteLine("Heisei");	
		}else{
			Console.WriteLine("TBD");
		}
		
	}
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

ll t1, t2;
ll a1, a2, b1, b2;

int main(void)
{
	cin >> t1 >> t2;
	cin >> a1 >> a2;
	cin >> b1 >> b2;

	auto c = (a1 - b1) * t1;
	auto d = c + (a2 - b2) * t2;
	if (d == 0) {
		cout << "infinity" << endl;
		return 0;
	}

	auto ac = abs(c);
	auto ad = abs(d);
	if ((c/ac) * (d/ad) > 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << ac / ad * 2 + (ac % ad != 0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int DP[11]={0}, count=0;
    string str;
    cin >> str;
    DP[0]=0;
    for(int i=0;i<str.size();i++) {
        if(str[i]=='A'||str[i]=='T'||str[i]=='G'||str[i]=='C') {
            count++;
            DP[i+1] = max(DP[i], count);
            
        }
        else {
            count = 0;
            DP[i+1] = max(DP[i], count);
        }
        //cout << i+1 << " " << DP[i+1] << endl;
    }
    cout << DP[str.size()] << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        PriorityQueue<int> pq = new PriorityQueue<int>();
        string[] s = Console.ReadLine().Split(' ');
        while (s[0] != "end")
        {
            if (s[0] == "insert")
                pq.Enqueue(int.Parse(s[1]));
            else
                Console.WriteLine(pq.Dequeue());
            s = Console.ReadLine().Split(' ');
        }
    }
}
class PriorityQueue<T>
{
    private readonly List<T> heap;
    private readonly Comparison<T> compare;
    private int size;
    public PriorityQueue() : this(Comparer<T>.Default) { }
    public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) { }
    public PriorityQueue(Comparison<T> comparison) : this(16, comparison) { }
    public PriorityQueue(int capacity, Comparison<T> comparison)
    {
        this.heap = new List<T>(capacity);
        this.compare = comparison;
    }
    public void Enqueue(T item)
    {
        this.heap.Add(item);
        var i = size++;
        while (i > 0)
        {
            var p = (i - 1) >> 1;
            if (compare(item, heap[p]) <= 0)
                break;
            this.heap[i] = heap[p];
            i = p;
        }
        this.heap[i] = item;

    }
    public T Dequeue()
    {
        var ret = this.heap[0];
        var x = this.heap[--size];
        var i = 0;
        while ((i << 1) + 1 < size)
        {
            var a = (i << 1) + 1;
            var b = (i << 1) + 2;
            if (b < size && compare(heap[a], heap[b]) < 0) a = b;
            if (compare(x, heap[a]) >= 0)
                break;
            heap[i] = heap[a];
            i = a;
        }
        heap[i] = x;
        heap.RemoveAt(size);
        return ret;
    }
    public T Peek() { return heap[0]; }
    public int Count { get { return size; } }
    public bool Any() { return size > 0; }
}


Measured memory_bytes: 21780
#include <stdio.h>
#include <stdlib.h>

int F[30];

int fib(int n){
    if(n==0 || n==1) return F[n] = 1;
    if(F[n] != 0) return F[n];
    return F[n] = fib(n-1)+fib(n-2);
}

int main(){
    int n;
    scanf("%d", &n);
    int ppp = 0;
    ppp = fib(n);
    printf("%d\n", F[n]);
    return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>

int main(void) {

        int hours, minutes, seconds;

        

        scanf("%d", &seconds);

        

        hours = seconds / 3600;

        seconds %= 3600;

        minutes = seconds / 60;

        seconds %= 60;

        

        printf("%d:%d:%d\n", hours, minutes, seconds);

        return 0;

}


Measured memory_bytes: 1932
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  long long ans = LLONG_MAX;
  rep(i, pow(2, n)) {
    bitset<32> b(i);
    int num = 0;
    rep(j, 32) {
      if(b.test(j)) num++;
    }
    if(num < k || !b.test(0)) continue;
    long long alt = 0;
    int max = 0;
    rep(j, n) {
      if(j == 0) max = a[j];
      else {
        if(a[j] > max) {
          max = a[j];
          continue;
        }
        else if(b.test(j)){
          alt += (max + 1) - a[j];
          max += 1;
        }
      }
    }
    if(alt < ans) ans = alt;
  }

  cout << ans << endl;
}

Measured memory_bytes: 384
#include <cmath>
#include <cstdio>

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

using namespace std;

void solve(const int *a){
//rep(i,32) printf("%d",a[i]); puts("");
	int sign=(a[0]==0?1:-1);

	int ai=0;
	rep(i,24) ai=2*ai+a[i+1];

	// 1/2^7 = 0.0078125
	int af=0;
	rep(i,7) af+=a[i+25]*10000000/pow(2,i+1);

	char ans[32]={};
	sprintf(ans,"%s%d.%07d",sign>0?"":"-",ai,af);
	int i;
	for(i=31;;i--) if(ans[i] && ans[i]!='0') break;
	if(ans[i]=='.') i++;
	ans[i+1]='\0';
	puts(ans);
}

int main(){
	int hex[128];
	hex['0']=0;
	hex['1']=1;
	hex['2']=2;
	hex['3']=3;
	hex['4']=4;
	hex['5']=5;
	hex['6']=6;
	hex['7']=7;
	hex['8']=8;
	hex['9']=9;
	hex['a']=10;
	hex['b']=11;
	hex['c']=12;
	hex['d']=13;
	hex['e']=14;
	hex['f']=15;

	int q; scanf("%d",&q);
	rep(_,q){
		char s[9]; scanf("%s",s);
		int a[32];
		rep(i,8){
			int h=hex[s[i]];
			rep(j,4) a[4*i+j]=((h&(1<<3-j))?1:0);
		}
		solve(a);
	}

	return 0;
}

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

ll getnum(ll b,int s){
  ll r=0,x=1;
  for(int i=0;i<=s;i++){
    if((b&(1<<i)))r+=x;
    x*=2;
  }
  return r;
}

ll stoll(string s){
  ll r=0,x=16;
  for(int i=0;i<s.size();i++){
    if('0'<=s[i]&&s[i]<='9')r=r*x+s[i]-'0';
    else r=r*x+s[i]-'a'+10;
  }
  return r;
}

int main(){
  int d;
  string s;
  ll b[9],ans;
  cin>>d;
  while(d--){
    for(int i=0;i<9;i++){
      cin>>s;
      b[i]=stoll(s);
    }
    ans=0;
    for(int i=0;i<32;i++){
      ll sum=0;
      for(int j=0;j<8;j++)sum+=getnum(b[j],i);
      int f=0;
      for(int j=0;j<=i;j++)
	if((sum&(1LL<<j))!=(b[8]&(1LL<<j)))f=1;
      if(f){
	ans|=(1LL<<i);
	for(int j=0;j<9;j++){
	  if((b[j]&(1LL<<i)))b[j]&=~(1LL<<i);
	  else b[j]|=(1LL<<i);
	}
      }
    }
    printf("%llx\n",ans);
  }
  return 0;
}

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

using ll=long long;

int main(){
    ll A, B, N; cin >> A >> B >> N;
    ll res;
    ll r_max;
    if(N >= B-1) r_max=B-1;
    else r_max=N;
    res=A*r_max/B;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    double x1, y1, x2, y2, x3, y3, xp, yp;
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
        double x = 0.5 * (-y1 * x2 + y3 * (x2 - x1) + x3 * (y1 - y2) + x1 * y2);
        double s = 1.0 / (2.0 * x) * (y3 * x2 - x3 * y2 + (y2 - y3) * xp + (x3 - x2) * yp);
        double t = 1.0 / (2.0 * x) * (x3 * y1 - y3 * x1 + (y3 - y1) * xp + (x1 - x3) * yp);
        if(0.0 < s && s < 1.0 && 0.0 < t && t < 1.0 && 0.0 < 1.0 - s - t && 1.0 - s - t < 1.0){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }

    return 0;
}


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

int main(){
  int x[5];
  int i;

  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];

  for(i=0;i<5;i++){
    if(x[i]==0){
      cout << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool solve() {
    string str;
    if(!(cin >> str)) return false;

    vector<int> cnt(26, 0), target(26, 0);
    for(char c : string("AIDUNYAN")) {
        target[c-'A']++;
    }

    string res;
    for(int i = 0; i < str.size(); ++i) {
        cnt[str[i]-'A']++;
        if(i >= 8) cnt[str[i-8]-'A']--;
        if(cnt == target) {
            res = res.substr(0, i-7) + "AIZUNYAN";
        } else {
            res += str[i];
        }
    }
    cout << res << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct vertex {
  int k;
  int dis;
  int definite;
  int **vlist;
};

int main(int argc, char *argv[])
{
  int n, i, j, id;
  struct vertex *adj;
  int minv, op, cost, mind;

  scanf("%d", &n);
  adj = (struct vertex *)malloc(sizeof(struct vertex) * n);

  for (i = 0; i < n; i++) {
    scanf("%d", &id);
    scanf("%d", &(adj[id].k));
    adj[id].vlist = (int **)malloc(sizeof(int *) * adj[id].k);
    for (j = 0; j < adj[id].k; j++) {
      adj[id].vlist[j] = (int *)malloc(sizeof(int) * 2);
      scanf("%d", &(adj[id].vlist[j][0]));
      scanf("%d", &(adj[id].vlist[j][1]));
    }
    adj[id].dis = INT_MAX;
    adj[id].definite = 0;
  }

  adj[0].dis = 0;
  adj[0].definite = 1;
  minv = 0;
  while (minv != -1) {
    for (i = 0; i < n; i++) {
      if (adj[i].definite == 1) {
	for (j = 0; j < adj[i].k; j++) {
	  op = adj[i].vlist[j][0];
	  cost = adj[i].vlist[j][1];
	  if (adj[op].definite == 0 && adj[op].dis > adj[i].dis + cost) {
	    adj[op].dis = adj[i].dis + cost;
	  }
	}
      }
    }
    minv = -1;
    mind = INT_MAX;
    for (i = 0; i < n; i++) {
      if (adj[i].definite == 0 && mind > adj[i].dis) {
	mind = adj[i].dis;
	minv = i;
      }
    }
    if (minv != -1) adj[minv].definite = 1;
  }


  for (i = 0; i < n; i++) printf("%d %d\n", i, adj[i].dis);

  return 0;
}

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

class Cube{
public:
  int f[6];
  Cube(){}
  void roll_z(){roll(1,2,4,3);}
  void roll_y(){roll(0,2,5,3);}
  void roll_x(){roll(0,1,5,4);}
  void roll(int i, int j, int k, int l){
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
  void move(char ch){
    if( ch == 'E'){
      for(int i=0;i<3;i++){
        roll_y();
      }
    }
    if( ch == 'W'){
      roll_y();
    }
    if( ch == 'N'){
      roll_x();
    }
    if( ch == 'S'){
      for(int i=0;i<3;i++){
        roll_x();
      }
    }
  }
};


int main(){
  Cube c;
  string com;

  for(int i=0;i<6;i++) cin >> c.f[i];
  cin >> com;

  for(int i=0; i<com.size(); i++) c.move(com[i]);

  cout << c.f[0] << endl;

  return 0;
}



Measured memory_bytes: 3140
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

int main() {
   SS(ll,n)
   SV(ll,a,n)
   ll ans=0;
   rep(i,n)if(a[i]!=i+1)ans++;
   YES(ans<=2);
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    def gcd(a,b):
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    def query(p,q):
        p += num
        q += num
        res=0
        while p<q:
            if q&1:
                q-=1
                res=gcd(res,data[q-1])
            if p&1:
                res=gcd(res,data[p-1])
                p+=1
            p = p//2
            q = q//2
        return res

    n = int(input())
    a = tuple(map(int,input().split()))
    num =2**(n-1).bit_length()
    data=[0]*2*num

    for i in range(n):
        data[i+num-1]=a[i]
    
    for i in range(num-2,-1,-1) :
        data[i]=gcd(data[2*i+1],data[2*i+2]) 

    ans = -1
    for i in range(n):
        ans = max(ans,gcd(query(0,i),query(i+1,n)))
    print(ans)
if __name__=='__main__':
    main()

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

int main() {
    int n;
    scanf("%d", &n);
    int v[n];
    for (int i=0; i<n; i++) scanf("%d", &v[i]);

    int maxv = -2000000000;
    int minv = v[0];

    for ( int i=1; i < n; i++ ) {
        maxv = max(maxv, v[i] - minv);
        minv = min(minv, v[i]);
    }

    printf("%d\n", maxv);
    
    return 0;
}



Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;

  Int ans=0;
  for(Int i=1;i<=n;i++)
    for(Int j=i;j<=n;j+=i)
      ans+=j;
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
int main()
{
    int n, m, i, j, k, l;
    cin>>n>>m;
    set<int>s;
    for(i=1; i<=m; i++)
    {
        cin>>k;
        for(j=1; j<=k; j++)
        {
            int x;
            cin>>x;
            s.insert(x);
        }
    }
    cout<<n-s.size()<<endl;
    s.clear();
    return 0;
}


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


void solve(long long A, long long B, long long K){
  long long mya = max(0ll, A - K);
  long long myb = max(0ll, (B + min(0ll, A - K)));

  cout << mya << " " << myb << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long K;
  scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
/***********************
*  Date: 2018.11.28    *
*  Problem:            *
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,q,co[100010],most[100010];
vector <int> g[100010];
vector <pair<int,pii> > qs;
bool vis[100010];

int main()
{
	cin>>n>>m;
	memset(most,-1,sizeof(most));
	rep(i,m)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	cin>>q;
	rep(i,q)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		qs.pb({x,{y,z}});
	}
	for(int i=qs.size()-1;i>=0;i--)
	{
		//cout<<qs[i].fi<<' '<<qs[i].se.fi<<' '<<qs[i].se.se<<endl;
		memset(vis,0,sizeof(vis));
		int v=qs[i].fi,colo=qs[i].se.se,dist=qs[i].se.fi;
		queue <pii> q;
		q.push({v,0});
		while(!q.empty())
		{
			int pos=q.front().fi,dist1=q.front().se;
			//cout<<pos<<' '<<colo<<' '<<dist<<' '<<dist1<<endl;
			q.pop();
			if(most[pos]>=dist-dist1) continue;
			most[pos]=dist-dist1;
			if(vis[pos]) continue;
			vis[pos]=true;
			if(co[pos]==0) co[pos]=colo;
			if(dist1==dist) continue;
			rep(j,g[pos].size()) q.push({g[pos][j],dist1+1});
		}
	}
	repn(i,n) printf("%d\n",co[i]);
	rt0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

bool sort_fn(Pll &a, Pll &b) {
  if (a.first == b.first) {
    return a.second > b.second;
  }
  return a.first > b.first;
}

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

  vector<ll> x(n);
  vector<ll> y(n);
  for (ll i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }

  map<Pll, ll> m;
  for (ll i = 0; i < n; ++i) {
    for (ll j = 0; j < n; ++j) {
      if (i == j) continue;
      Pll k = mkp(x[i]-x[j], y[i]-y[j]);
      m[k]++;
    }
  }

  ll ans = 1e18;
  if (m.empty()) ans = 1;
  each (i, m) {
    ans = min(ans, n-i.second);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define int long long
using namespace std;


signed main(){
	int n,a,b;
	cin>>n>>a>>b;
	int dt[n];
	rep(i,n)cin>>dt[i];
	int ans=0;
	rep(i,n-1){
		ans+=(a*(dt[i+1]-dt[i])<b)?a*(dt[i+1]-dt[i]):b;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		String[] str = num.split(" ", 0);
		int k = Integer.parseInt(str[0]);
		int c = Integer.parseInt(str[1]);
		if(k-c<0) {
			System.out.println("0");
		}else {
			System.out.println((k-c));
		}
	}
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,i;
	cin>>a>>b>>c;
	for(i=0;i<=1000;i++){
	if(i*a%b==c){
	cout<<"YES"<<endl;
	return 0;
	}}
	cout<<"NO"<<endl;
    return 0;
}

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

#define int ll
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

int calc(int i, int j, int k) {
	if(i == j && j == k) return 1;
	if(i != j && j != k && i != k) return 6;
	else return 3;
}

void solve() {
	int n;
	cin >> n;

	vi cnt(n+1,0);

	FOR(i,1,101) {
		FOR(j,1,101) {
			FOR(k,1,101) {
				int val = i*i + j*j + k*k + j*i + j*k + k*i;
				if(val <= n) cnt[val]++;
			}
		}
	}

	FOR(i,1,n+1) {
		cout << cnt[i] << '\n';
	}
}

int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}


Measured memory_bytes: 3776
#https://qiita.com/chun1182/items/ddf2b6cba932b2bb0d4e
def BF(p,n,s):
    inf=float("inf")
    d=[inf for i in range(n)]
    d[s-1]=0
    for i in range(n+1):
        for e in p:
            if e[0]!=inf and d[e[1]-1]>d[e[0]-1]+e[2]:
                d[e[1]-1] = d[e[0]-1] + e[2]
    ans1=d[-1]
    for i in range(n+1):
        for e in p:
            if e[0]!=inf and d[e[1]-1]>d[e[0]-1]+e[2]:
                d[e[1]-1] = d[e[0]-1] + e[2]
    ans2=d[-1]
    if ans1>ans2:
      return ['inf']
    else:
      return [-ans1]
n,m,p=map(int,input().split())
g=[]
for _ in range(m):
  a,b,c=map(int,input().split())
  g.append([a,b,-(c-p)])
g.append([n,n+1,0])
ans=BF(g,n+1,1)[-1]
if ans=='inf':
  print(-1)
else:
  print(max(ans,0))

Measured memory_bytes: 47576
function Main(input) {
  var chars = input.trim().split(' ');

  var x = parseInt(chars[0], 10);
  var y = parseInt(chars[1], 10);

  var ans = 0;

  if (x === 1 && y === 1) {
    ans += 400000;
  }

  if (x === 1) ans += 300000;
  if (y === 1) ans += 300000;
  if (x === 2) ans += 200000;
  if (y === 2) ans += 200000;
  if (x === 3) ans += 100000;
  if (y === 3) ans += 100000;

  console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

// 基本要素

const double EPS = 1e-8;
const double INF = 1e12;
// 点
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
vector<P> ps;
vector<int> v;

// 点同士
double distancePP(const P &p, const P &q){
  return sqrt(pow(real(p)-real(q),2)+pow(imag(p)-imag(q),2));
}

#define maxLoop 100

double f(double x, double y){
  int n = ps.size();
  double res = -INF;
  P now(x,y);
  rep(i,n){
    chmax(res,distancePP(now, ps[i])/v[i]);
  }
  return -res;
} // 最大値を求めたい上に凸な関数

double ysearch(double x){
  double left = 0, right = 100;
  for (ll loop = 0; loop < maxLoop; ++loop){
    if (f(x, (left*2+right)/3) > f(x, (left+right*2)/3)){
      right = (left + right * 2) / 3;
    } else {
      left = (left * 2 + right) / 3;
    }
  }
  return f(x, (right + left) * 0.5);
}

double xsearch(){
  double left = 0, right = 100;
  for (ll loop = 0; loop < maxLoop; ++loop){
    if (ysearch((left * 2 + right) / 3) > ysearch((left + right * 2) / 3)){
      right = (left + right * 2) / 3;
    } else {
      left = (left * 2 + right) / 3;
    }
  }
  return ysearch((right + left) * 0.5);
}


signed main(){
  int n;
  while(cin >> n, n){
    ps.clear(); ps.resize(n);
    v.clear();  v.resize(n);
    rep(i,n){
      double x, y; cin >> x >> y;
      ps[i] = {x, y};
      cin >> v[i];
    }
    printf("%.10lf\n",-xsearch());
  }
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;

int N;
int a;
map<int, int> cnt;

signed main()
{
    cin >> N;
    REP(i,N) {
        cin >> a;
        cnt[a-1]++;
        cnt[a]++;
        cnt[a+1]++;
    }

    int ans = 0;
    for (auto it=cnt.begin(); it!=cnt.end(); it++) {
        ans = max(ans, it->second);
    }

    cout << ans << endl;
}


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

int main(void){
   char str[101];
   int i,k,l;

   scanf("%d%s",&k,str);

   l=strlen(str);

   if(k>=l) printf("%s",str);
   else{
      for(i=0;i<k;i++)
         printf("%c",str[i]);
      printf("...");
   }

   printf("\n");
   return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#define  N     102
using namespace std;

int main(){
	int r, c, table[N][N] = {0};

	cin>>r>>c;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>table[i][j];
		}
	}

	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			table[i][c] += table[i][j];
		}
	}
	
	for(int j=0;j<=c;j++){
		for(int i=0;i<r;i++){
			table[r][j] += table[i][j];
		}
	}

	for(int i=0;i<=r;i++){
		for(int j=0;j<=c;j++){
			if(j != 0) cout<<" ";
			cout<<table[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#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++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

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;
}

signed main() {
  init();
  ll N;
  cin >> N;
  rep(i, N) cout << "ACL";
  ENDL;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define step(i,s,n,c) for(int i=(s);i<(n);i+=(c))
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define each(i,vec) for(auto i:vec)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  long a,b,c,d;
  cin>>a>>b>>c>>d;
  long mx=b-a+1;
  long A,B,C,D,Ls,Lt;
  A=(a-1)/c;
  B=b/c;
  C=(a-1)/d;
  D=b/d;
  Ls=(a-1)/lcm(c,d);
  Lt=b/lcm(c,d);
  //debg(mx);debg(A);debg(B);debg(C);debg(D);debg(Ls);debg(Lt);
  long ans=mx-(B-A)-(D-C)+(Lt-Ls);
  out(ans);

  
  
  
  return 0;
}

Measured memory_bytes: 256
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class RAQ_RMQ:
    def __init__(self, n, F=min, e=float("inf"), fill=None):
        self.n = n
        self.n0 = 2**(n-1).bit_length()
        self.e = e
        self.F = F
        self.lazy = [0]*(2*self.n0)
        if fill is None:
            fill = e
        self.data = [fill]*(2*self.n0)

    def construct(self, a):
        for i, x in enumerate(a):
            self.data[i+self.n0] = x
        for i in range(self.n0-1, 0, -1):
            self.data[i] = self.F(self.data[2*i], self.data[2*i+1])

    def bottomup(self, i):
        i += self.n0
        k = i//(i & -i)
        c = k.bit_length()
        for j in range(c-1):
            k >>= 1
            self.data[k] = self.F(self.data[2*k], self.data[2*k+1]) + self.lazy[k]

    def topdown(self, i):
        i += self.n0
        k = i//(i & -i)
        c = k.bit_length()
        for j in range(c-1):
            idx = k >> (c - j - 1)
            ax = self.lazy[idx]
            if not ax:
                continue
            self.lazy[idx] = 0
            self.data[2*idx] += ax
            self.data[2*idx+1] += ax
            self.lazy[2*idx] += ax
            self.lazy[2*idx+1] += ax

    def query(self, l, r):
        self.topdown(l)
        self.topdown(r)
        L = l+self.n0
        R = r+self.n0

        s = self.e
        while L < R:
            if R & 1:
                R -= 1
                s = self.F(s, self.data[R])
            if L & 1:
                s = self.F(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def add(self, l, r, x):
        L = l+self.n0
        R = r+self.n0

        while L < R :
            if R & 1:
                R -= 1
                self.data[R] += x
                self.lazy[R] += x
            if L & 1:
                self.data[L] += x
                self.lazy[L] += x
                L += 1
            L >>= 1
            R >>= 1

        self.bottomup(l)
        self.bottomup(r)

n,m = map(int, input().split())

memo = [[] for i in range(n+2)]
for i in range(m):
    l,r,a = map(int, input().split())
    memo[l].append((l,a))
    memo[r+1].append((l,-a))

seg = RAQ_RMQ(n+2, F=max, e=-float("inf"), fill=0)

for i in range(1, n+2):
    for j, a in memo[i]:
        seg.add(0, j, a)
    tmp = seg.query(0, i)
    seg.add(i, i+1, tmp)

ans = seg.query(0, n+1)
print(ans)

Measured memory_bytes: 105292
from collections import Counter

N = int(input())
s = list(input())
c = Counter(s)

for _ in range(N - 1):
    s = list(input())
    tmp = Counter(s)
    for k, v in c.items():
        if k not in tmp:
            c[k] = 0
        else:
            c[k] = min(tmp[k], v)

ans = ""
c = sorted(c.items(), key=lambda x: x[0])
for k, v in c:
    ans += k * v
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 99999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    // 累積和
    llong sum[100003]={};
    rep(i,100002) sum[i+1] += sum[i]+i; 
    
    
    llong n,ans=0;
    map<string, llong> mp;
    string t;
    cin >> n;
    rep(i,n){
        cin >> t;
        sort(t.begin(),t.end());
        // cout << s[i] << endl;
        if(!(mp[t] >= 1)) mp[t] = 0;
        ans += mp[t];
        mp[t]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
/*
#include<cstdio>
const int N = 1e5;
int n, a, b, c;
int vis[N];
int main() {
	return 0;
}
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N = 1e5 + 5;
int n, m, ans;
int h[N], maxn[N];
int a[N], b[N];
void static_set() {
	static int tmp[N];
	memcpy(tmp, h, sizeof(h));
	std::sort(tmp + 1, tmp + n + 1);
	int cnt = std::unique(tmp + 1, tmp + n + 1) - tmp - 1;
	for (int i = 1; i <= n; i++) h[i] = std::lower_bound(tmp + 1, tmp + cnt + 1, h[i]) - tmp;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
	static_set();
	for (int i = 1; i <= m; i++) scanf("%d%d", &a[i], &b[i]);
	for (int i = 1; i <= m; i++) {
		maxn[a[i]] = std::max(maxn[a[i]], h[b[i]]);
		maxn[b[i]] = std::max(maxn[b[i]], h[a[i]]);
	}
	for (int i = 1; i <= n; i++)
		ans += h[i] > maxn[i];
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 3684
n = int(input())
q =[0]*100
a = 0
for i in range (100):
  if(n <=26):
    a = i
    q[i] = n
    break
  q[i] = n%26
  if(q[i]==0):
    q[i]=26
    n = n//26-1
  else:
    n = n//26
for i in range(a,-1,-1):
  print(chr(96+q[i]),end='')

Measured memory_bytes: 9200
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

vvii g;
vi p, vls;
vi comp, comp_size;
vll total, vis, max_con_sum;

void dfs(int u, int rep){
    vis[u] = 1;
    comp[u] = rep;
    comp_size[rep]++;
    total[comp[u]] += vls[u];
    for (ii v: g[u]){
        if (!vis[v.ff]) dfs(v.ff, rep);
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    p.resize(n+1);
    comp.resize(n+1);
    total.assign(n+1, 0);
    comp_size.assign(n+1, 0);
    vis.assign(n+1, 0);
    max_con_sum.assign(n+1, 0);
    vls.resize(n+1);
    g.assign(n+1,vii());
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> vls[p[i]];
    }
    for (int j = 1; j <= n; ++j) {
        g[p[j]].pb({p[p[j]], vls[p[p[j]]]});
    }
    for (int k = 1; k <= n; ++k) {
        if (!vis[k]) dfs(k, k);
    }
    ll ans = -1e18;
    vis.assign(n+1,  0);
    for (int l = 1; l <= n; ++l) {
        if (vis[comp[l]]) continue;
        vis[comp[l]] = 1;
        for (int len = 1; len <= min(k, comp_size[comp[l]]); ++len) {
            int p1 = l, p2 = l;
            ll sum = 0;
            for (int i = 0; i < len; ++i) {
                sum += vls[p2];
                p2 = g[p2][0].ff;
            }
            for (int j = 0; j <= comp_size[comp[l]]; ++j) {
                if (total[comp[l]] > 0) ans = max(ans, sum + (k-len)/comp_size[comp[l]] * total[comp[l]]);
                else ans = max(ans, sum);
                sum += vls[p2];
                p2 = g[p2][0].ff;
                sum -= vls[p1];
                p1 = g[p1][0].ff;
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4268
H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
for p in P:
    p[0] -= 1
    p[1] -= 1
cnth = [0]*H
cntw = [0]*W
ans = 0
for p in P:
    cnth[p[0]] += 1
for p in P:
    cntw[p[1]] += 1
mxh = max(cnth)
mxw = max(cntw)
cntx = 0
for p in P:
    if cnth[p[0]] == mxh and cntw[p[1]] == mxw:
        cntx += 1
if cntx == cnth.count(mxh) * cntw.count(mxw):
    ans = mxh + mxw -1
else:
    ans = mxh + mxw
print(ans)

Measured memory_bytes: 68348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[] da = new long[n];

        long ans = 9223372036854775800;
            
        da[0] = a[0];
        for(long i = 1; i < n; i++)
        {
            da[i] = a[i] + da[i - 1];
        }

        for (long i = 0; i < n - 1; i++)
        {
            long x = da[i];
            long y = da[n - 1] - da[i];
            ans = Math.Min(ans, Math.Abs(x - y));
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 37956
#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end() 
#define X first;
#define Y second;
#define mp make_pair;
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll; 
const int MOD = 1000000007;




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

 	//int t{},T{};
 	//cin>>t;T=t;
 	//while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},k{},a{},b{},c{},s{},f{};
        cin>>n;
        if(n%1000==0){
            cout<<0<<endl;
        }else{
            cout<<1000-n+1000*(n/1000)<<endl;
        }
    //}
    
    
	return 0;
}


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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }


int main(void){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);

    int x;

    FOR(i, 5){
        cin >> x;
        if(x == 0){
            cout << i+1;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3648