akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

int gcd(int a,int b)
{
  if(a>b)swap(a,b);
  if(a==0){return b;}
  else return gcd(b%a,a);
}
map<ll,ll>prime_factor(int m)
{
  map<ll,ll>res;
  ll sqrm=sqrt(m)+1;
  for(int i=2;i<sqrm+1;i++)
  {
    while(m%i==0){res[i]++;m/=i;}
    if(m==1)break;
  }
  if(m>1)res[m]++;
  return res;
}

struct sieve{
  int p=0;
  vector<bool> furui;
  sieve(int n){
    furui.resize(n,1);
    furui[0]=0;
    furui[1]=0;
    for(int i=2;i<n;i++)if(furui[i])for(int j=i*2;j<n;j+=i)furui[j]=0;
  }
  bool isprime(int m){return furui[m];}
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int a;
  cin>>n;
  cin>>a;
  vector<ll>b(n+1);
  b[n]=a;
  a=abs(a);
  rep(i,n){cin>>b[n-1-i];}
  rep(i,n+1)
  {
    if(b[i]!=0)
    {
      if(a==0)
      {
        a=abs(b[i]);
      }
      else a=gcd(a,abs(b[i]));
    }
  }
  auto ma=prime_factor(a);
  auto ma2=prime_factor(abs(b[0]));
  sieve si(n+10);
  set<int>ans;
  
  if(b[0]==0)
  {
    rep(p,n+2)
    {
      if(!si.isprime(p))continue;
      ll tb=0;
      bool f=1;
      rep(i,p-1)
      {
        for(int j=i;j<=n;j+=p-1)tb+=b[j];
        if(tb%p!=0){f=0;break;}
      }
      if(f)
      {
        ans.insert(p);
      }
    }
  }
  else 
  {
    for(auto tp:ma2)
    {
      int p=tp.first;
      if(p-1>n)continue;
      ll tb=0;
      bool f=1;
      rep(i,p-1)
      {
        for(int j=i;j<=n;j+=p-1)tb+=b[j];
        if(tb%p!=0){f=0;break;}
      }
      if(f)
      {
        ans.insert(p);
      }
    }
  } 
  for(auto tp:ma)
  {
    if(tp.first<n+2)continue;
    ans.insert(tp.first);
  }
  for(auto tp:ans)
  {
    cout<<tp<<"\n";
  }


  return 0;

}


Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
  int x,a,b;
  int i,j;
  
  scanf("%d",&x);
  scanf("%d",&a);
  scanf("%d",&b);
  
  if(a-x<0)
    i=(a-x)*(-1);
  else
    i=a-x;
  if(b-x<0)
    j=(b-x)*(-1);
  else
    j=b-x;
  
  if(i<j)
    printf("A");
  else
    printf("B");
  
  return 0;
}

Measured memory_bytes: 128
S = input()
N = len(S)

s1 = S[0:int((N-1)/2)]
s2 = S[int((N+3)/2-1):]

if S == S[::-1] and s1 == s1[::-1] and s2 == s2[::-1]:
    print('Yes')
else:
    print('No')

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

using namespace std;

#define ll long long

int const N = 101, W = 1e5 + 1;

int n, w;

int arr[N][2];

bool vis[N][W];

ll dp[N][W];

ll pound(int index, int weight)

{

		if (index > n)				return 0;

				

		if (weight > w)

				return -1e9;

				

		if (vis[index][weight])

				return dp[index][weight];

				

		vis[index][weight] = 1;

		

		return dp[index][weight] = max(arr[index][1] + pound(index + 1, weight + arr[index][0]), pound(index + 1, weight));

}

int main()

{

		

		ios_base::sync_with_stdio(false);

		cin.tie(nullptr);

    cin >> n >> w;

    

    for (int i = 0; i < n; ++i)

        cin >> arr[i][0] >> arr[i][1];

        

    cout << pound(0, 0);

    

    return 0;

}

Measured memory_bytes: 87040
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  ll ans = accumulate(a.begin(), a.end(), 0LL), minv = INF;
  rep(i, n) {
    if (a[i] > b[i]) chmin(minv, b[i]);
  }
  ans -= minv;
  cout << (minv == INF ? 0 : ans) << '\n';




  
  return 0;
}

Measured memory_bytes: 640
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int W = sc.nextInt();
        sc.nextLine();
        int[] w = new int[n];
        int[] v = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
            sum+=v[i];
        }
        System.out.println(solve(n, W, w, v, sum));
    }
    private static int solve(int n, int W, int[] w, int[] v, int sum) {
        int[] dp = new int[sum +1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int j = 1; j < dp.length; j++) {
            if(v[0] == j)
                dp[j] = w[0];
        }
        for (int i = 1; i < n; i++) {
            for (int j = sum -v[i]; j >= 0; j--) {
                if(dp[j] != Integer.MAX_VALUE) {
                    dp[j+v[i]] = Math.min(dp[j+v[i]], dp[j]+w[i]);
                    if(dp[j+v[i]] > W) dp[j+v[i]] = Integer.MAX_VALUE;
                }

            }
        }
        for(int i = sum; i > 0; i--) {
            if(dp[i] <= W) return i;
        }
        return 0;
    }
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
 
typedef pair<long long int,long long int>pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
 
# define  MAX 200005
long long int MOD=998244353;
long long int INF=1e18;
 
int main()
{
    
       ios_base::sync_with_stdio(false); 
       cin.tie(NULL);
     cout.tie(NULL);
      long long int i,j,k=0,l=0,r=0,m=0,n,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t,d;
  cin>>n>>d;
    p=d+1;
    cnt=1;
    while(p+d<n)
    {
        p=p+2*d+1;
        cnt++;
       
    }
    cout<<cnt;
   
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if(a + b >= 10) cout << "error" << endl;
  else cout << a + b << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

int main() {
	ll N, A[5];
	cin >> N;
	for (int i = 0; i < 5; i++) {
		cin >> A[i];
	}
	ll ans = (N - 1) / A[0] + 1;
	ll m = A[0];
	for (int i = 1; i < 5; i++) {
		m = min(m, A[i]);
		ll rest = N - m * (ans - i);
		ans += (rest - 1) / m + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
def convert(sym):
	if sym == 'S':
		return 0
	if sym == 'H':
		return 1
	if sym == 'C':
		return 2
	if sym == 'D':
		return 3

	if sym == 0:
		return 'S'
	if sym == 1:
		return 'H'
	if sym == 2:
		return 'C'
	if sym == 3:
		return 'D'

grid = [[0 for j in range(13)] for i in range(4)]

n = int(input())
for i in range(n):
	x, y = map(str, input().split())
	y = int(y)- 1
	grid[convert(x)][y] += 1

for i in range(4):
	for j in range(13):
		if (grid[i][j] < 1):
			print(convert(i), j+1)



Measured memory_bytes: 5612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <cassert>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
const int maxn = 20;
char s1[maxn], s2[maxn], s3[maxn];

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%s %s %s", s1, s2, s3);
    char a = s1[0] + 'A' - 'a', b = s2[0] + 'A' - 'a', c = s3[0] + 'A' - 'a';
    cout << a << b << c << endl;
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return [init]*size1
  else
    return [[init]*size2]*size1
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,W=get_i
wv=array(N)
N.times do|i|
  wv[i]=get_i
end
wv.sort!{|x,y| x[0]<=>y[0]}
dp=array(W+1,0)
wv.each do|w,v|
  (W-w).downto(0) do|j|
    dp[j+w]=max(dp[j]+v,dp[j+w])
  end
end
puts dp[W]

Measured memory_bytes: 2556
import sys
N,H=map(int,input().split(' '))
mdmg=0
mth=0
th=[]
for i in range(N):
  a,b=map(int,input().split(' '))
  if mdmg==a and mth>=b:
    th.append(mth)
    mth=b
  elif mdmg<a: 
    mdmg=a
    th.append(mth)
    mth=b
  else: th.append(b)
th.sort()
th.reverse()
count=0
for i in th:
  if(i>=H or mth>=H):
    count+=1
    print(count)
    sys.exit()
  elif i<mdmg:
    break
  else:
    count+=1
    H-=i
if mdmg>mth: mth=mdmg
H-=mth
if H%mdmg==0:
  count+=int(H/mdmg)+1
else:
  count+=int(H/mdmg)+2
print(count)

Measured memory_bytes: 7388
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string n;
    cin>>n;
    for(int i=0;i<3;i++){
        if(n[i]=='7') {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}

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

using namespace std;

int solve() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<bool> visited(N);

  int current = 0;
  int count = 0;
  while (!visited[current]) {
    visited[current] = true;
    count++;
    current = a[current];
    if (current == 1) return count;
  }
  return -1;
}

int main() {
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Ribhav
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AButtons solver = new AButtons();
        solver.solve(1, in, out);
        out.close();
    }

    static class AButtons {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int a = s.nextInt();
            int b = s.nextInt();
            out.println(Math.max(a + b, Math.max(2 * a - 1, 2 * b - 1)));
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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


int main()
{
  int a, b;
  cin >> a >> b;
  
  if (abs(a - b) % 2 == 0)
    cout << (abs(a - b)/2 + min(a,b)) << endl;
  else
  	cout << "IMPOSSIBLE" << endl;    
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#define ivorysi
#define MAXN 5005
#define eps 1e-8
using namespace std;
typedef long long int64;
typedef double db;
struct node {
    int len,cnt,f;
    node *par,*nxt[26];
}pool[MAXN * 3],*tail = pool,*root,*last;
void Build_Sam(int len,int c) {
    node *nowp = tail++,*p;
    nowp->len = len;
    for(p = last ; p && !p->nxt[c] ; p = p->par) {
	p->nxt[c] = nowp;
    }
    if(!p) nowp->par = root;
    else {
	node *q = p->nxt[c];
	if(q->len == p->len + 1) nowp->par = q;
	else {
	    node *cp = tail++;
	    *cp = *q;cp->cnt = 0;cp->len = p->len + 1;
	    q->par = nowp->par = cp;
	    for( ; p && p->nxt[c] == q ; p = p->par) p->nxt[c] = cp;
	}
    }
    last = nowp;
}
int c[MAXN];
node *que[MAXN * 3];
char s[MAXN];
int N,K,M;
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    root = last = tail++;
    scanf("%s%d",s + 1,&K);
    N = strlen(s + 1);
    for(int i = 1 ; i <= N ; ++i) {
	Build_Sam(i,s[i] - 'a');
    }
    M = tail - pool;
    for(int i = 0 ; i < M ; ++i) {
	c[pool[i].len]++;
    }
    for(int i = 1 ; i <= N ; ++i) c[i] += c[i - 1];
    for(int i = 0 ; i < M ; ++i) {
	que[c[pool[i].len]--] = &pool[i];
    }
    for(int i = 1 ; i <= M ; ++i) que[i]->f = 1;
    for(int i = M ; i >= 1 ; --i) {
	for(int j = 0 ; j < 26 ; ++j) {
	    if(que[i]->nxt[j])
		que[i]->f += que[i]->nxt[j]->f;
	}
    }
    node *p = root;
    while(K > 0) {
	for(int i = 0 ; i < 26 ; ++i) {
	    if(!p->nxt[i]) continue;
	    if(K <= p->nxt[i]->f) {
		putchar('a' + i);
		p = p->nxt[i];
		--K;
		break;
	    }
	    else K -= p->nxt[i]->f;
	}
    }
    putchar('\n');
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    ll N;
    cin >> N;
    
    ll ans = INF;
    for(ll i = 1; i*i <= N;i++)
    {
        if( N%i != 0 ) continue;
        else
        {
            //cout << i << " " << N/i << endl;
            ll tmp = max(to_string(N/i).size(),to_string(i).size());
            if( ans > tmp ) ans = tmp;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

int oknum;
int change(long long int&a, const long long  int to) {
	int plus = 0;
	if (a == 0)plus--;
	if (to == 0)plus++;
	a = to;
	oknum += plus;
	return plus;
}

int main() {
	int N; cin >> N;
	vector<long long int>as(N/2);
	vector<long long int>sums(N/2+1);
	for (int i = 0; i < N; ++i) {
		int a; cin >> a;
		if (i >= N / 2) {
			as[N - i - 1] -= a;
		}
		else {

			as[i] += a;
		}
	}
	as.insert(as.begin(), 0);
	for (int i = 0; i < N/2; ++i) {
		sums[i] = as[i + 1] - as[i];
	}
	sums[N / 2] = -as[N / 2];
	oknum = count(sums.begin(), sums.end(), 0ll);
	int Q; cin >> Q;
	while (Q--) {
		long long int l, r, x;
		cin >> l >> r >> x;
		l--;
		{
			if (l >= N / 2) {
				change(sums[N - l], sums[N-l]+x);
			}
			else {
				change(sums[l], sums[l] + x);
			}
		}
		{
			if (r >= N / 2) {
				change(sums[N-r], sums[N-r] - x);
			}
			else {
				change(sums[r], sums[r] -x);
			}
		}
		if (oknum == N / 2+1)cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}

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

int main(int argc, char **argv)
{
	char a[4];
	char b[4];
	scanf("%s", a);
	scanf("%s", b);
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}

		return 0;
}

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



// Generated by 1.1.4 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(){
    int n;
    cin >> n;
    if (n == 1) cout << "Hello World" << endl;
    else {
        int a, b;
	cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
struct city{
    int num;
    int year;
};
bool cmp(const city &a, const city &b){
    return a.year < b.year;
}
int main(){
    int N,M,i,j,p,y;
    city tmp;
    cin >> N >> M;
    vector<int> q(M),a(M);
    vector< vector<city> > pref(N);
    for(i=0;i<M;i++){
        cin >> p >> tmp.year;
        tmp.num = i;
        pref.at(p-1).push_back(tmp);
        q.at(i)=p;
    }
    for(i=0;i<N;i++){
        if(pref.at(i).empty()) continue;
        sort(pref.at(i).begin(),pref.at(i).end(),cmp);
        for(j=0;j<pref.at(i).size();j++){
            a.at(pref.at(i).at(j).num)=j+1;
        }
    }
    for(i=0;i<M;i++){
        cout << setfill('0')<<setw(6)<<q.at(i);
        cout << setfill('0')<<setw(6)<<a.at(i)<<endl;
    }
    return 0; 
}

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

/* macros */
#define inf 1e9
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define gtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": " << solve() << "\n";TC++;}
#define gvtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": "; vsolve(); TC++;}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

void solve() {
    string s,t;
    cin>>s>>t;
    int m = sz(s);
    int n = sz(t);
    
    int en = m-n;
    int ans = INT_MAX;
    for (int i=0;i<=en;i++) {
        string ss = s.substr(i,n);
        int cnt = 0;
        for (int j=0;j<n;j++) {
            if (ss[j] != t[j]) {
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

int main(void){
    ll n;
    cin>>n;
    vl a(n+1);
    ll k;
    cin>>k;
    ll ans = 0;
    rep1(i,n+1){
        a[i] = ((i*n)%mod-i*(i-1)%mod+1)%mod;
        if(a[i] < 0) a[i] += mod;
        if(i>=k) ans+=a[i];
    }
    cout<<(ans+1)%mod<<endl;
}


Measured memory_bytes: 4764
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;

struct In{
    template<typename T>
    operator T(){
        T x;
        cin >> x;
        return x;
    }
};
In in;

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

template <typename T>
T gcd(T x,T y){
    if (y == 0) return x;
    return gcd(y,x%y);
}

template <typename T>
T lcm(T x,T y){
    return x*y/gcd(x,y);
}

int main(){
    int n=in,x[n],ans=INT_MAX,p;
    forin(x,n);
    for(int i=1;i<=100;i++){
        p=0;
        for (int i2=0;i2<n;i2++){
            p+=(x[i2]-i)*(x[i2]-i);
        }
        ans=min(p,ans);
    }
    out(ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n, m) for (int i = (n), i < (m); i++)

//typedef struct {float arg; int x, y;} shop;

/*int shop_comp(const void *a, const void *b)
{
  shop x = *(shop *)a, y = *(shop *)b;
  if (x.arg > y.arg) return  1;
  if (x.arg < y.arg) return -1;
  return 0;
}*/


int array[11], used[11], n;
double x[11], y[11], ans = 1e9+7;
void dfs(int i) {
  if (i == n) {
    //for (int j = 0; j <= n; j++) printf("%d ", array[j]); endl;
    double arg = 0.0;
    double u = 1.0, v= 0.0;
    double xf = 0.0, yf = 0.0;
    for (int i = 0; i <= n; i++) {
      int k = array[i];
      double dx = x[k] - xf, dy = y[k] - yf;
      //printf("%lf %lf %lf %lf\n", u, v, 
      //printf("%lf\n", acos((u*dx+v*dy)/sqrt((u*u+v*v)*(dx*dx+dy*dy))));
      arg += acos((u*dx+v*dy)/sqrt((u*u+v*v)*(dx*dx+dy*dy)));
      xf = x[k]; yf = y[k];
      u = dx; v = dy;
    }
    ans = Min(ans, arg);
    return ;
  }
  for (int j = 1; j <= n; j++) {
    if (used[j] == 0) {
      used[j] = 1;
      array[i] = j;
      dfs(i + 1);
      used[j] = 0;
    }
  }
}

  
int
main(int argc, char *argv[])
{
  scanf("%d", &n);
  x[n] = 0.0; y[n] = 0.0;
  rep(i, n) scanf("%lf %lf", &x[i + 1], &y[i + 1]);

  dfs(0);

  printf("%lf\n", (ans/M_PI) * 180.0);

  return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define endl '\n'
typedef long long int lli;
typedef long double ld;
typedef pair< lli,lli > ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef vector<vi> graph;
lli MOD=1000000007;long double EPS=1e-9;


void pre(){

}

lli n;
lli arr[200200];
lli dp[200200];

lli getsum(int ll,int rr){
	if(ll==0)return dp[rr];
	else return dp[rr]-dp[ll-1];
}

lli getval(int pos,int ll,int rr){
	return abs(getsum(ll,pos)-getsum(pos+1,rr));
}

int get(int ll,int rr){
	int pos=ll;
	for(int step=rr-ll+1;step;step>>=1){
		while(pos+step<rr&&getval(pos+step,ll,rr)<=getval(pos+step-1,ll,rr))pos+=step;
	}
	return pos;
}

void solve(){
	cin>>n;
	fr(i,n)cin>>arr[i];
	dp[0]=arr[0];
	rep(i,1,n-1){
		dp[i]=dp[i-1]+arr[i];
	}
	lli ans=MOD*MOD;
	for(int i=2;i<n-1;i++){
		int aa=get(0,i-1);
		int bb=get(i,n-1);
		lli mini=min({getsum(0,aa),getsum(aa+1,i-1),getsum(i,bb),getsum(bb+1,n-1)});
		lli maxi=max({getsum(0,aa),getsum(aa+1,i-1),getsum(i,bb),getsum(bb+1,n-1)});
		remin(ans,maxi-mini);
	}
	cout<<ans<<endl;

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	pre();
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

int main(){
  ll h,w;
  cin >> h >> w;
  if(h%3==0 || w%3==0){
    cout << 0 << ln; return 0;
  }

  ll ans = min(h,w);
  REP(i,1,w){
    vector<ll> a(3,0);
    a[0] = i*h;
    a[1] = (w-i)*(h/2);
    a[2] = (w-i)*(h-(h/2));
    sort(a.begin(),a.end());
    ans = min(ans, a[2]-a[0]);
  }
  swap(h,w);
  REP(i,1,w){
    vector<ll> a(3,0);
    a[0] = i*h;
    a[1] = (w-i)*(h/2);
    a[2] = (w-i)*(h-(h/2));
    sort(a.begin(),a.end());
    ans = min(ans, a[2]-a[0]);
  }
  cout << ans << ln;
  return 0;
}

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

int main(){
    long long n,m;
    cin >> n >> m;

    if ( (m - 2*n) > 0 ) cout << n + ( (m-(2*n)) / 4) << endl;
    else cout << m/2 << endl;

    return 0; 
}

Measured memory_bytes: 256
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <map>
#include <vector>

using namespace std;

const int MAXV = 10010;

struct Edge {
  int u;
  int v;

  Edge(int u, int v): u(u), v(v) {}
};

int v, e, source = 0, dfs_clock = 0, scc_count = 0;
vector<int> g[MAXV];
int pre[MAXV] = {0};
int low[MAXV] = {0};
map<int, int> scc_v_to_no;
vector<int> scc_no_to_v[MAXV];
stack<int> s;

void DFS(int u) {
  int child_num = 0;
  ++dfs_clock;
  pre[u] = dfs_clock;
  low[u] = dfs_clock;
  s.push(u);
  for (int v: g[u]) {
    if (!pre[v]) {
      DFS(v);
      low[u] = min(low[u], low[v]);
    } else if (scc_v_to_no.find(v) == scc_v_to_no.end()) {
      low[u] = min(low[u], pre[v]);
    }
  }
  if (low[u] == pre[u]) {
    while (1) {
      auto x = s.top();
      s.pop();
      scc_v_to_no.emplace(x, scc_count);
      scc_no_to_v[scc_count].push_back(x);
      if (x == u) {
        ++scc_count;
        break;
      }
    }
  }
}

void SCC() {
  for (int i = 0; i < v ; ++i) {
    if (!pre[i]) {
      DFS(i);
    }
  }
}

int main() {
  scanf("%d %d", &v, &e);
  for (int i = 0; i < e; ++i) {
    int s, t;
    scanf("%d %d", &s, &t);
    g[s].push_back(t);
  }

  SCC();

  int q;
  scanf("%d\n", &q);
  for (size_t i = 0; i < q; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", scc_v_to_no.at(a) == scc_v_to_no.at(b));
  }

  return 0;
}



Measured memory_bytes: 4900
#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair<ll , ll> Pair ;
const int N = 2e5 + 10 ;
ll a[N] , d[N] , sum[N] , zero[N];
int main()
{
  ll k , q ;
  scanf("%lld%lld" , &k , &q) ;
  for(int i = 0; i < k ;i ++)
   scanf("%lld" , &d[i]) ;
  while(q --)
  {
    ll n , x , m ;
    scanf("%lld%lld%lld" , &n , &x , &m) ;
    x %= m ;
    ll sum0 = 0 , sum1 = 0 ;
    sum[0] = 0 , zero[0] = 0 ;
    for(int i = 0 ;i < k ;i ++)
     {
       a[i] = d[i] % m , sum[i + 1] = sum[i] + a[i];
       zero[i + 1] = zero[i] + (a[i] == 0) ;
     }
    int zero0 =  (n - 1) / k * zero[k]  + zero[(n - 1) % k] ;
    sum0 = (x +  (n - 1) / k * sum[k] + sum[(n - 1) % k]) / m - x / m ;
    ll ans = n - 1 - sum0 - zero0 ;
    cout << ans << endl ;
  }
  return 0 ;
}


Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#include <stack>

using namespace std;

#define maxN 100000
#define maxM 100000

stack<int> edge[maxN];
set<int> all;

int func(int i){
  all.erase(i);
  
  while(!edge[i].empty()){
    if( all.find(edge[i].top()) == all.end() ){
      edge[i].pop();
    }
    else{
      func(edge[i].top());
      edge[i].pop();
    }
  }
  return 0;
}

int main(){
  int N, M;
  int X, Y, Z;
  set<int>::iterator ite;

  long long int res=0;

  cin >> N >> M;
  for(int i=0; i<M; i++){
    cin >> X >> Y >> Z;
    edge[X-1].push(Y-1);
    edge[Y-1].push(X-1);
  }
  for(int i = 0; i<N; i++){
    all.insert(i);
  }

  while(!all.empty()){
    res++;
    func(*all.begin());
  }
  cout << res <<endl;
  return 0;
}


Measured memory_bytes: 76800
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

using pl = pair<ll, ll>;

int main(){
  
  string s = stin();
  string t = stin();
  ll n = SZ(s);
  ll m = SZ(t);
  vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, -INFLL));
  vector<vector<pl>> pr(n + 1, vector<pl>(m + 1, pl(-INFLL, -INFLL)));
  dp[0][0] = 0;
  REP(i, n + 1){
    REP(j, m + 1){
      if(i < n && j < m && s[i] == t[j]){
        if(dp[i + 1][j + 1] < dp[i][j] + 1){
          dp[i + 1][j + 1] = dp[i][j] + 1;
          pr[i + 1][j + 1] = pl(i, j);
        }
      }
      if(i < n){
        if(dp[i + 1][j] < dp[i][j]){
          dp[i + 1][j] = dp[i][j];
          pr[i + 1][j] = pl(i, j);
        }
      }
      if(j < m){
        if(dp[i][j + 1] < dp[i][j]){
          dp[i][j + 1] = dp[i][j];
          pr[i][j + 1] = pl(i, j);
        }
      }
    }
  }
  ll ci = n;
  ll cj = m;
  string ans = "";
  while(!(ci == -INFLL && cj == -INFLL)){
    pl ne = pr[ci][cj];
    if(ci == ne.fi + 1 && cj == ne.se + 1){
      ans += s[ne.fi];
    }
    ci = ne.fi;
    cj = ne.se;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 211584
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b;
    cin >> a >> b;
    
    cout << b + b-a << endl;
    
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  ll n,x;
  cin>>n>>x;
  vll a(n);
  rep(i,n) {
    cin>>a[i];
    a[i]-=x;
  }
  ll ans=a[0];
  rep(i,n){
    ans=gcd(ans,a[i]);
  }
  COUT(abs(ans));
}

Measured memory_bytes: 1024
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
      String flag = "OK";
      
      int count = a.length();
//      System.out.println("count=" +count);
      int i = 0;
      
      // 1桁目
      if((a.charAt(i))==('L')){
         // 奇数の時、LはNG
         flag = "NG";
      }else{
         // OK
      }
      
      for(i = 1; i < count; i++){
//      System.out.println("i=" +i);
        if(i % 2 != 0){
          // 偶数
          if((a.charAt(i))==('R')){
            // 偶数の時、RはNG
            flag = "NG";
          }else{
            // OK
          }
        }else{
          // 奇数
          if((a.charAt(i))==('L')){
            // 奇数の時、LはNG
            flag = "NG";
          }else{
            // OK
          }
        }
          
          if(flag.equals("NG")){
            break;
          }
        }
           
           // kekka
      if(flag.equals("OK")){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define st first
#define nd second
#define pb push_back
#define pq priority_queue

using namespace std;
typedef long long ll;
ll const inf = 1e9;
ll const mod = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    vector <int> g[n + 1];
    fr(i, 0, m){
        int a, b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    for(auto u : g[1]){
        for(auto v : g[u]){
            if(v == n){

                cout << "POSSIBLE" << endl;
                return 0;
            }
        }

    }

    cout <<"IMPOSSIBLE"<<endl;




    return 0;
}


Measured memory_bytes: 12016
package main

import "fmt"

func main() {
	var a int
	var b int
	var c int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	if a < b && b < c {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}



Measured memory_bytes: 1104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
 		while(true){
 			int w = sc.nextInt();
 			int h = sc.nextInt(); 			

 			if(h == 0 && w == 0){break;}

 			for(int i = 1; i <= w; i++){
 				for(int j = 1; j <= h; j++){
 					if((i + j) % 2 == 1){
 						System.out.print(".");
 					}else{
 						System.out.print("#");
 					}
 				}
 	 			System.out.println("");
 			}
 			System.out.println("");
 		}
	}
}

Measured memory_bytes: 25788
#include <iostream>
#include <string>
  
int main(){
    const std::string wrong_word("Hoshino");
    const std::string right_word("Hoshina");
	
    int num;
    std::cin >> num;
    std::cin.ignore(); // ignore next newline character
      
    for(int i = 0; i < num; ++i){
        std::string str;
        std::getline(std::cin, str);
		
        std::size_t pos = str.find(wrong_word);
        while(pos != std::string::npos){
            str.replace(pos, wrong_word.length(), right_word);
            pos = str.find(wrong_word);
        }
		
        std::cout << str << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}
//int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}
//int power(int x, int y){ int res = 1;x = x % mod; if (x == 0) return 0;
//while (y > 0){ if(y & 1) res = (res*x) % mod; y = y>>1; x = (x*x) % mod;} return res;}

int32_t main(void){
	IOS;
	
	in2(x, n);
	int arr[n];
	mi m;
	rep(i, 0, n)
	{
		cin>>arr[i];
		m[arr[i]] += 1;
	}
	
	int n1, n2;
	int i = 0;
	while(true)
	{
		n1 = x-i;
		n2 = x+i;
		if(m[n1] == 0)
		{
			cout<<n1;
			return 0;
		}
		if(m[n2] == 0)
		{
			cout<<n2;
			return 0;
		}
		i+=1;
	}
}

Measured memory_bytes: 3640
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 * 0.5 == 1.0/2
 */

public class Main {
	
	public static void printlnYN(boolean b){
		if(b) System.out.println("Yes");
		else System.out.println("No");
	}

	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		int len = S.length();
		long ans = 0;
		
		for(int i = 0; i <= (1<<len-1)-1; i++){
			String ss = "";
			long sum = 0;
			ss += S.charAt(0);
			for(int j = (len - 1) - 1; j >= 0; j--){
				if((1&(i>>j)) == 1){
					sum += Long.valueOf(ss);
					//System.out.print(ss + "+");
					ss = "" + S.charAt(len-1-j);
				}else{
					ss += S.charAt(len-1-j);
				}
			}
			//System.out.println(ss);
			sum += Long.valueOf(ss);
			//System.out.println("=" + sum);
			ans += sum;
		}
		
		System.out.println(ans);
	}

}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,m;cin>>n>>m;
    vector<ll>a(n+1);
    vector<ll>w(n+1);
    ll ac=0,wa=0;
    rep(i,m){
        ll p;cin>>p;
        string s;cin>>s;
        if(s[0]=='A'&&a[p]==0){
            wa+=w[p];
            ac++;
            a[p]=1;
        }else if(s[0]=='W'){
            w[p]++;
        }
    }
    cout<<ac<<' '<<wa<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,k,a[10001],sum=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++) 
    {
	cin>>a[i];
    }
    for(int i=1;i<=n-1;i++)
        for(int j=i+1;j<=n;j++)
        {
            if(a[i]<a[j]) 
            {
			swap(a[i],a[j]);
		    }
        }
    for(int i=1;i<=k;i++) 
    {
	sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}

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

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

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    char a;
    cin >> a;

    // Process
    char ans;
    if ('A' <= a && a <= 'Z')
        ans = 'A';
    else
        ans = 'a';

    // Output
    cout << ans << endl;

    return 0;
}


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

int main(){
  int n,q;
  cin >>n>>q;
  queue <pair<string,int>> Q;

  pair<string,int> a;
  for(int i=0;i<n;i++){
    cin>>a.first>>a.second;
    Q.push(a);
  }
  
  int temp=0;
  while(!Q.empty()){
    pair<string,int> x ;
    x=Q.front();
    if(x.second<=q){
      cout<<x.first<<" "<<temp+x.second<<endl;
      temp=temp+x.second;
      Q.pop();
    }
    else {
      x.second=x.second-q;
      temp=temp+q;
      Q.pop();
      Q.push(x);
    }
  }
  return 0;
}

 


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

int main() {
  int h, w, d;
  cin >> h >> w >> d;

  map<int, pair<int, int>> a;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int x;
      cin >> x;
      a.insert({x, {i, j}});
    }
  }

  vector<ll> memo(h * w + 1);
  for (int i = 1; i < memo.size(); ++i) {
    if (memo[i] == 0) {
      for (int j = i + d; j < memo.size(); j += d) {
        int x = abs(a[j].first - a[j - d].first);
        int y = abs(a[j].second - a[j - d].second);
        memo[j] = memo[j - d] + x + y;
      }
    }
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    ll ans = memo[r] - memo[l];
    cout << ans << endl;
  }
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll a(n); REP(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());
  ll mi;  // 負から正に変わる最初のindex
  for (mi=1; mi<n-1; mi++) {if (a.at(mi) > 0) break;}
  ll tmp = a.at(mi-1);
  for (ll i=mi; i<n-1; i++) {
    tmp -= a.at(i);
  }
  ll tmp2 = a.at(n-1);
  for (ll i=0; i < mi-1; i++) {
    tmp2 -= a.at(i);
  }
  cout << tmp2 - tmp << endl;
  
  for (mi=1; mi<n-1; mi++) {if (a.at(mi) > 0) break;}
  tmp = a.at(mi-1);
  for (ll i=mi; i<n-1; i++) {
    cout << tmp << ' ' << a.at(i) << endl;
    tmp -= a.at(i);
  }
  tmp2 = a.at(n-1);
  for (ll i=0; i < mi-1; i++) {
    cout << tmp2 << ' ' << a.at(i) << endl;
    tmp2 -= a.at(i);
  }
  cout << tmp2 << ' ' << tmp << endl;
  return 0;
}


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

#define forw(i,a,n) for (int i=a;i<n;i++)
#define ford(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
#define SZ(x) ((int)(x).size())

typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;

const ll mod=1000000007;
const int maxn = 1e5 + 3;
void mf(){
	freopen("input.in","r",stdin);
	//freopen("output.ou","w",stdout);
}
//START SOL
int c[30];
int n;
string st;
void solve(){
	cin>>n;
	for(int i = 0; i <= 26; i++) c[i] = 0;
	cin>>st;
	for(int i = 0; i < n; i++){
		c[st[i] - 'a' + 1]++;	
	}
	ll s= 1;
	for(int i = 1; i <= 26; i++){
		if(c[i]==0) continue;
		s= (s*(c[i] + 1))% mod;
	}
	s-=1;
	if(s<0) s = (s + mod )% mod;
	cout<<s;

}

int main(){
	ios_base::sync_with_stdio(false);
	#ifdef tuanh
		mf();
	#endif
	solve();
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> vec(n);
  for (auto &v : vec)
    cin >> v;

  ll ans = 0;
  for (int i = 1; i < n; ++i)
    ans += min(a * (vec[i] - vec[i-1]), b);

  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]--;
  vector<int> idx(n);
  rep(i,n) idx[a[i]] = i;
  set<int> s;
  ll ans = 0;
  for (int x = n-1; x >= 0; --x) {
    int i = idx[x];
    ll c = 0;
    { // calc c
      s.insert(i);
      vector<int> l(2,-1);
      vector<int> r(2,n);
      { // calc l
        auto it = s.find(i);
        rep(j,2) {
          if (it == s.begin()) break;
          --it;
          l[j] = *it;
        }
      }
      { // calc r
        auto it = s.find(i);
        rep(j,2) {
          ++it;
          if (it == s.end()) break;
          r[j] = *it;
        }
      }
      vector<int> ls(2);
      ls[0] = i-l[0]; ls[1] = l[0]-l[1];
      vector<int> rs(2);
      rs[0] = r[0]-i; rs[1] = r[1]-r[0];
      c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
    }
    ans += c*(x+1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5760
def solve(s):
    def isPalindrome(s):
        return s == s[::-1]

    n = len(s)
    if not isPalindrome(s):
        print('No')
        return
    if not isPalindrome(s[:(n-1)//2]):
        print('No')
        return
    if not isPalindrome(s[(n+3)//2 - 1:]):
        print('No')
        return
    print('Yes')

s = input()
solve(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        ll abc[3] = {};
        for (size_t i = 0; i < s.size(); i++) {
            abc[s[i] - 'a']++;
        }
        bool ans = 1 >= abs(abc[0] - abc[1]) && 1 >= abs(abc[1] - abc[2]) && 1 >= abs(abc[2] - abc[0]);
        out << (ans ? "YES" : "NO") << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()             
#define MP( a, b )		make_pair( (a), (b) )
#define fi				first
#define se				second

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

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

int prime[1000000] = {};

signed main() {
	int n;
	fill( prime, prime + 1000000, 1 );

	FOR( i, 2, 1000000 ) {
		if( prime[i] ) {
			for( int j = i * i; j < 1000000; j += i ) {
				prime[j] = 0;
			}
		}
	}

	while( cin >> n ) {
		int cnt = 0;
		FORE( i, 2, n ) {
			if( prime[i] ) cnt++;
		}
		cout << cnt << endl;
	}
}


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

using namespace std ;

long long n, k ;

int main() {
    cin >> n >> k;
    if( k >= n ) {
        cout << min( n, k - n ) << '\n' ;
    }
    else {
        cout << min( n % k, k - (n % k) ) << '\n' ;
    }
}

Measured memory_bytes: 256