akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;
const int MX = 110000;
ll inv[MX], f[MX], invf[MX];
void calc(){
	inv[0] = inv[1] = f[0] = f[1] = invf[0] = invf[1] = 1;
	for (int i = 2; i < MX; i++){
		inv[i] = mod - mod / i * inv[mod % i] % mod;
		f[i] = f[i - 1] * i % mod;
		invf[i] = invf[i - 1] * inv[i] % mod;
	}
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	calc();
	int n; cin >> n;
	vi v(n); rep(i, n) cin >> v[i];
	vector<ll> s(n + 1), lensum(n + 1);
	rep(i, n) s[i + 1] = (s[i] + v[i]) % mod;
	
	for(int i = 1, l = 0, r = n; 2 * i <= n + 1; i++){
		lensum[i] = (lensum[i - 1] + s[r] + mod - s[l]) % mod;
		lensum[n - i + 1] = lensum[i];
		r--; l++;
	}
	
	//rep(i, n + 1) dbg(i, lensum[i]);
	
	ll lrsum = 0, ans = 0;
	
	for(int i = 1; i < n; i++){
		lrsum += v[i - 1];
		lrsum += v[n - i];
		lrsum %= mod;
		
		ll x = (lensum[i] + mod - lrsum) % mod;
		ans += 2 * f[n] * x % mod * inv[i + 1] % mod * inv[i + 2] % mod;
		ans += f[n] * lrsum % mod * inv[i + 1] % mod;
		ans %= mod;
	}
	ans += f[n] * s[n] % mod;
	cout << ans % mod << endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    double L;
    cin >> L;
    L /= 3;
    cout << fixed <<setprecision(10) <<  pow(L, 3) << endl;
}


Measured memory_bytes: 4248
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, long long Q, std::string S, std::vector<long long> l, std::vector<long long> r){
    vll sum(N, 0);
    rep(i, N){
        if(i > 0 && S[i]== 'C' && S[i-1]== 'A'){
            sum[i] = sum[i-1]+1;
        }
        else if(i>0)
            sum[i] = sum[i-1];
    }
    rep(i, Q){
        l[i]--; r[i]--; 
        if(l[i]==0 )
            cout << sum[r[i]]<<endl;
        else{
            if(S.at(l[i])!='A')
                cout << sum[r[i]] - sum[l[i]] << endl;
            else
                cout << sum[r[i]] - sum[l[i]-1] << endl;
        }
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::string S;
    std::cin >> S;
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&l[i]);
        scanf("%lld",&r[i]);
    }
    solve(N, Q, S, std::move(l), std::move(r));
    return 0;
}


Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long x = sc.NextLong();

        long[] counts = new long[n + 1];
        long[] pCounts = new long[n + 1];
        counts[0] = 1;
        pCounts[0] = 1;
        for (int i = 1; i <= n; i++)
        {
            counts[i] = counts[i - 1] * 2 + 3;
            pCounts[i] = pCounts[i - 1] * 2 + 1;
        }

        long answer = dfs(x, n, counts, pCounts);

        Console.WriteLine(answer);
    }

    private static long dfs(long x, long level, long[] counts, long[] pCounts)
    {
        if (x <= 0)
        {
            return 0;
        }

        if (level == 0)
        {
            return 1;
        }

        if (x == counts[level])
        {
            return pCounts[level];
        }

        long mid = (counts[level] + 1) / 2;
        if (x == mid)
        {
            return dfs(x - 2, level - 1, counts, pCounts) + 1;
        }
        else if (x > mid)
        {
            return dfs(x - mid, level - 1, counts, pCounts) + 1 + pCounts[level - 1];
        }
        else
        {
            return dfs(x - 1, level - 1, counts, pCounts);
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27464
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

typedef  long long ll;

#define rep(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(ll (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007


using namespace std;

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

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

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}


void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

ll divisors(ll n) {
    vector<ll> res;

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i-1);
        if(n/i == i) continue;
        res.push_back((n/i)-1);
    }

    ll ans = 0;

    rep(i,0,res.size()){
        if(res[i] != 0)
        if(n/res[i] == n%res[i]) ans += res[i];
    } 
    return ans;
}

void solve(void){
   int k;
   cin >> k;
   int odd ,even;

   if(k %2 == 0){
       odd = k/2;
       even = k - odd;
   }else{
       odd = k/2+1;
       even = k - odd;
   }
   cout << odd*even << endl;
}

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

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

typedef long long ll;

#define debug(args...)do{cerr<< #args << " : ";shaon(args);}while(0)
void shaon () { cerr << endl; }
template <typename T, typename ... north>
void shaon(T arg, const north &... rest){cerr << arg << ' ';shaon(rest...);}

const ll N=1e5+5;
ll n, w[110], v[110], WWE, dp[101][N];

ll solve (ll x, ll free)
{
    if(x==n+1) return 0;

    ll &r = dp[x][free];
    if(r!=-1) return r;
    r=solve(x+1,free);

    if(w[x]<=free) r=max(r,v[x]+solve(x+1,free-w[x]));

    return r;
}

int main()
{
    scanf("%lld %lld",&n,&WWE);

    for(ll i=1; i<=n; i++){
        scanf("%lld %lld",&w[i],&v[i]);
    }

    memset(dp,-1,sizeof(dp));

    printf("%lld",solve(1,WWE));


    return 0;
}


















Measured memory_bytes: 79104
#include <stdio.h>
int main() {
  int set[4], i;

  for (i = 0; i < 4; i++) {
    scanf("%d", &set[i]);
  }

  int X[set[0]], Y[set[1]], Z = set[3] - set[2];

  for (i = 0; i < set[0]; i++) {
    scanf("%d", &X[i]);
  }
  for (i = 0; i < set[1]; i++) {
    scanf("%d", &Y[i]);
  }

  int znum = set[2], xfl, yfl, flag = 0, j;

  for (i = 0; i < Z; i++) {
    znum++;
    xfl = 0;
    yfl = 0;

    for (j = 0; j < set[0]; j++) {
      if (znum > X[j]) {
        xfl++;
      }
    }
    for (j = 0; j < set[1]; j++) {
      if (znum <= Y[j]) {
        yfl++;
      }
    }

    if (xfl == set[0] && yfl == set[1]) {
      flag++;
    }
  }

  if (flag > 0) {
    printf("No War");
  } else {
    printf("War");
  }
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string> 
#include<map>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<utility>
#include<cstdio>
#include<cstring>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qui queue<int>
#define vit vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define prq priority_queue
#define pii pair<int,int>
#define mp make_pair
#define sz size()
#define em empty()
#define ct continue
using namespace std;
ll n,c=0,a[201001];
int main()
{
	cin>>n;
	fo(i,0,n){
		cin>>a[i];
		a[i]-=i;
	}
	sort(a,a+n);
	fo(i,0,n)c+=abs(a[i]-a[(n-1)/2]);
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var s = LnStr();
        var S = s.Length;
        var dp = new int[S];
        var remains = new int[2019];
        s = new string(s.Reverse().ToArray());

        
        dp[0] = int.Parse(s[0].ToString()) % 2019;
        remains[dp[0]]++;
        var d = 1;
        for (int i = 0; i < s.Length - 1; i++)
        {
            d = (d * 10) % 2019;
            dp[i + 1] = (dp[i] + int.Parse(s[i + 1].ToString()) * d) % 2019;
            remains[dp[i + 1]]++;
        }
        var result = remains[0];
        for (int i = 0; i < remains.Length; i++)
        {
            result += remains[i] * (remains[i] - 1) / 2;
        }

        print(result);
    }

    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
}



Measured memory_bytes: 25068
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    ll a , b , k ;
    cin >> k >> a >> b ;
    bool flag = false ;
    for(ll i = 0 ; i < b-a+1 ; i++){
       if((a + i)%k == 0 ){
           flag = true ;
       }
    }
    if(flag == true){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }

    
    return 0 ;
}

 



Measured memory_bytes: 3652
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
ll dp[550][555];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    std::vector<ll> v(n);
    std::vector<ll> cum(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>v[i];
        if(i==0)
        {
            cum[i]=v[i];
        }
        else
        {
            cum[i]=cum[i-1]+v[i];
        }
    }
    for (int l = n-1; l >=0 ; --l)
    {
        for (int r = l; r < n; ++r)
        {
            dp[l][r]=1e18;
            if(l==r)
            {
                dp[l][r]=0;
                // continue;
            }
            for (int k = l; k <r; ++k)
            {
                if(l==0)
                {
                    dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+cum[r]);
                }
                else
                {
                    dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+cum[r]-cum[l-1]);
                }   
            }
            // cout<<l<<" "<<r<<" "<<dp[l][r]<<'\n';
        }
    }
    cout<<dp[0][n-1]<<'\n';
}


Measured memory_bytes: 2048
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int a, b, c;
  cin >> a >> b >> c;
  int x = max({a, b, c})*3 - (a+b+c);
  cout << (x % 2 == 0 ? x/2 : x/2+2) << endl;
  return 0;
}

Measured memory_bytes: 256
a, b, c, x = 4.times.map { gets.to_i }
cnt=0
(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |h|
      cnt += 1 if i*500+j*100+h*50 == x
    end
  end
end
puts cnt

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>
#include <queue>

using namespace std;
using ll = long long int;

int h, w;


class UnionFind{
 public:
  int n;
  vector<int> parents;
  vector<int> ranks;
  vector<ll> group_pw, group_pb;
 
  explicit UnionFind(int n){
    this->n = n;
    parents = vector<int>(n, -1);
    for(int i = 0; i < n; i++)
    {
      parents[i] = i;
    }
    ranks = vector<int>(n, 0);
    group_pb = vector<ll>(n, 0);
    group_pw = vector<ll>(n, 0);
  }
 
  ///木の根を求める
  int findRoot(int target)
  { 
    if(parents[target] == target)
    {
      return target;
    }else{
      return parents[target] = findRoot(parents[target]);
    }
  }
 
  ///target1とtarget2の属する集合を併合
  void uniteGroup(int target1, int target2)
  { 
    int parent_target1 = findRoot(target1);
    int parent_target2 = findRoot(target2);
    if(parent_target1 == parent_target2)
    {
      ///すでに同じ集合に属している
      return;
    }
    if(ranks[parent_target1] < ranks[parent_target2])
    {
      parents[parent_target1] = parent_target2;
      group_pw[parent_target2] += group_pw[parent_target1];
      group_pb[parent_target2] += group_pb[parent_target1];
      group_pw[parent_target1] = group_pb[parent_target1] = 0;
    }else{
      group_pw[parent_target1] += group_pw[parent_target2];
      group_pb[parent_target1] += group_pb[parent_target2];
      group_pw[parent_target2] = group_pb[parent_target2] = 0;
      parents[parent_target2] = parent_target1; 
      if(ranks[parent_target1] == ranks[parent_target2]) ranks[parent_target1]++;
    }
  }
 
  ///target1とtarget2が同じ集合に属するか
  bool same(int target1, int target2)
  { 
    return findRoot(target1) == findRoot(target2);
  } 
 };

int main(){
  cin >> h >> w;
  vector<string> s(h);
  for(int i = 0; i < h; i++)
  {
    cin >> s[i];
  }
  //vector<vector<bool>> flag(h, vector<bool>(w, false));
  UnionFind uf(h * w);
  vector<vector<int>> index(h, vector<int>(w));
  int count = 0;
  for(int i = 0; i < h; i++)
  {
    for(int j = 0; j < w; j++)
    {
      index[i][j] = count;
      count++;
    }
  }
  ll result = 0;
  for(int i = 0; i < h; i++)
  {
    for(int j = 0; j < w; j++)
    {
      if(s[i][j] == '.')
      {
        uf.group_pw[index[i][j]] = 1;
      }else{
        uf.group_pb[index[i][j]] = 1;
      }
    }
  }
  for(int i = 0; i < h; i++)
  {
    for(int j = 0; j < w; j++)
    { 
      if(i < h - 1)
      {
        if(!uf.same(index[i][j], index[i + 1][j]) && s[i][j] != s[i + 1][j])
        {
          uf.uniteGroup(index[i][j], index[i + 1][j]);
        }
      } 
      if(j < w -1)
      {
        if(!uf.same(index[i][j], index[i][j + 1]) && s[i][j] != s[i][j + 1])
        {
          uf.uniteGroup(index[i][j], index[i][j + 1]);
        }
      }
    }
  }
  for(int i = 0; i < h * w; i++)
  {
    result += uf.group_pw[i] * uf.group_pb[i];
  }
  cout << result << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
struct Node{
    int x,y;
};
Node arr[100000];
int dis[100000]={0};
int fbs(int x)
{
    if(x>0) return x;
    else return -x;
}
int main()
{
    int h,m,d;
    cin>>h>>m>>d;
    int xx;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf(" %d",&xx);
            arr[xx].x=i;
            arr[xx].y=j;
        }
    }
    for(int i=d+1;i<=h*m;i++)
    {
        dis[i]=dis[i-d]+fbs(arr[i].x-arr[i-d].x)+fbs(arr[i].y-arr[i-d].y);
    }
    int q;
    cin>>q;
    int x,y;
    for(int i=0;i<q;i++)
    {
        scanf(" %d %d",&x,&y);
        cout<<dis[y]-dis[x]<<endl;
    }
    return 0;
}


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

int main(){
  int A,B,C,D;cin>>A>>B>>C>>D;
  while(A>0&&C>0){
    A-=D;
    C-=B;
  }
  cout<<(A>0||C<=0?"Yes":"No")<<endl;
}

Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#define N 100100

//head

int n;
vi G[N];
P dp[N][2];

P dfs(int i, int j, int one) {
  if(dp[i][one].second != -1) return dp[i][one];
  P &res = dp[i][one] = P(0, 0);
  if(G[i].size() == 1) {
    return res = P(1, 0);
  }
  if(G[i].size() == 2) {
    for(int ne:G[i]) {
      if(ne == j) continue;
      return res = dfs(ne, i, one);
    }
  }
  vi info(G[i].size());
  rep(id, G[i].size()) {
    int ne = G[i][id];
    if(ne == j) continue;
    auto[ichi, zero] = dfs(ne, i, true);
    res.first += ichi;
    info[id] = ichi-zero;
  }
  if(one) {
    res.first -= *max_element(all(info));
  }
  res.second = res.first;
  return res;
}

int main() {
  scanf("%d", &n);
  rep(i, n-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int z, u;
  rep(i, n) if(G[i].size() == 1) {
    z = i;
    u = G[i][0];
  }
  memset(dp, -1, sizeof(dp));
  printf("%d\n", min(dfs(u, z, false).first, 1+dfs(u, z, true).first));
}

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

int main()
{
    string s;
    cin >> s;
    int x = 0;
    for(const auto &si: s)x += (si - '0');
    if (x % 9 == 0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    string s; cin >> s;

    int ans = 0;
    int i = 0;
    while (i < (int)(s.length())) {
        int res = 0;
        int j = i;
        while (s[j] == 'A' || s[j] == 'T' || s[j] == 'C' || s[j] == 'G' ) {
            res += 1;
            j += 1;
        }
        ans = max(ans, res);
        i += 1;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
N = int(input())
l = list(map(int,input().split()))
ans = 0
if N < 3 :
    ans = ans
else :
    for m in range(N-2) :
        for n in range(m+1,N-1) :
            for k in range(n+1,N) :
                if len(set([l[m],l[n],l[k]])) == 3 and 2 * max(l[m],l[n],l[k]) < sum([l[m],l[n],l[k]]) :
                    ans += 1
                else :
                    continue
print(ans)

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)   
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 1e18;

void solve()
{
 int n;
 cin>>n;
 cout<<(10 - n/200);
}
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
  /*#ifndef DLOCAL
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif*/
  /* int t;
   cin>>t;
   while(t--)*/
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}


Measured memory_bytes: 3628
// 速度比較のためにkeymoonさんの提出をお借りしました。
// https://atcoder.jp/contests/abc141/submissions/7717102

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        int curMaxLength = 0;
        var hash = new RollingHash(s);
        for (int i = 0; i < s.Length; i++)
            for (int j = i; j < s.Length; j++)
                while (curMaxLength < j - i && j + curMaxLength < n && hash.Slice(i, curMaxLength + 1) == hash.Slice(j, curMaxLength + 1)) curMaxLength++;
        Console.WriteLine(curMaxLength);
    }
}

class RollingHash
{
    const ulong MASK30 = (1UL << 30) - 1;
    const ulong MASK31 = (1UL << 31) - 1;
    const ulong MOD = (1UL << 61) - 1;
    const ulong POSITIVIZER = MOD * ((1UL << 3) - 1);
    static uint Base;
    static ulong[] powMemo = new ulong[5000 + 1];
    static RollingHash()
    {
        Base = (uint)new Random().Next(129, int.MaxValue);
        powMemo[0] = 1;
        for (int i = 1; i < powMemo.Length; i++)
            powMemo[i] = CalcMod(Mul(powMemo[i - 1], Base));
    }

    ulong[] hash;

    public RollingHash(string s)
    {
        hash = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash[i + 1] = CalcMod(Mul(hash[i], Base) + s[i]);
    }

    public ulong Slice(int begin, int length)
    {
        return CalcMod(hash[begin + length] + POSITIVIZER - Mul(hash[begin], powMemo[length]));
    }

    private static ulong Mul(ulong l, ulong r)
    {
        var lu = l >> 31;
        var ld = l & MASK31;
        var ru = r >> 31;
        var rd = r & MASK31;
        var middleBit = ld * ru + lu * rd;
        return ((lu * ru) << 1) +
            ld * rd +
            ((middleBit & MASK30) << 31) +
            (middleBit >> 30);
    }

    private static ulong CalcMod(ulong val)
    {
        val = (val & MOD) + (val >> 61);
        if (val > MOD) val -= MOD;
        return val;
    }
}


Measured memory_bytes: 18428
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll a, b, k;
	cin>>a>>b>>k;
	if(a>=k) cout<<a-k<<" "<<b<<endl;
	else cout<<0<<" "<<max(0ll, b-k+a)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int d,r;
		double f;

		d = a / b;
		r = a % b;
		f =1.0 * a / b;

		System.out.println(d + " " + r + " " + String.format("%.5f",f));

	}

}


Measured memory_bytes: 26608
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		int[] b = new int[3];
		for(int i = 0; i < 3; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
		}
		sc.close();
		int[] v = new int[4];
		for(int i = 0; i < 3; i++) {
			v[a[i]]++;
			v[b[i]]++;
		}
		int c1 = 0;
		int c2 = 0;
		for(int i = 0; i < 4; i++) {
			if(v[i] == 0) {
				System.out.println("NO");
			}else {
				if(v[i] % 2 == 1) {
					c1++;
				}else {
					c2++;
				}
			}
		}
		if(c2 == 4) {
			System.out.println("YES");
		}else {
			if(c1 == 2 &&c2 == 2) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#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;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 1e5 + 10; 
int x,y,a,b,c;
ll p[maxn],q[maxn],r[maxn];

int main()
{
	fastIO;
	cin >> x >> y >> a >> b >> c;
	rep(i,0,a) cin >> p[i];
	rep(i,0,b) cin >> q[i];
	rep(i,0,c) cin >> r[i];
	ll ans = 0;
	sort(p,p + a); reverse(p,p + a);
	rep(i,0,x) ans += p[i];
	sort(q,q + b); reverse(q,q + b);
	rep(i,0,y) ans += q[i];
	sort(r,r + c); reverse(r,r + c);
	int ll = x - 1, rr = y - 1;
	for(int i = 0; i < c; ++i){
		if(rr < 0 && ll < 0) break;
		if(r[i] <= p[ll] && r[i] <= q[rr]) break;
		if(ll >= 0 && rr >= 0) {
			if(r[i] - p[ll] > r[i] - q[rr]) {
				ans -= p[ll];
				ll--;
			}
			else {
				ans -= q[rr];
				rr--;
			}
			ans += r[i];
		}
		else if(ll >= 0) {
			if(r[i] <= p[ll]) break;
			ans -= p[ll];
			ans += r[i];
			ll--;
		}
		else if(rr >= 0){
			if(r[i] <= q[rr]) break;
			ans -= q[rr];
			ans += r[i];
			rr--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#define DEBUG 0
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2019/9/1 21:01:50
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using ll = long long;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a)
  {
    mint b{a};
    return *this *= b.power(MOD - 2);
  }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
class combination
{
public:
  vector<mint> inv, fact, factinv;
  static int MAX_SIZE;
  combination() : inv(MAX_SIZE), fact(MAX_SIZE), factinv(MAX_SIZE)
  {
    inv[1] = 1;
    for (auto i = 2; i < MAX_SIZE; i++)
    {
      inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for (auto i = 1; i < MAX_SIZE; i++)
    {
      fact[i] = mint(i) * fact[i - 1];
      factinv[i] = inv[i] * factinv[i - 1];
    }
  }
  mint operator()(int n, int k)
  {
    if (n >= 0 && k >= 0 && n - k >= 0)
    {
      return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
  }
};
int combination::MAX_SIZE = 3000010;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// constexpr double epsilon = 1e-10;
// constexpr ll infty = 1000000000000000LL;
// constexpr int dx[4] = {1, 0, -1, 0};
// constexpr int dy[4] = {0, 1, 0, -1};
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}

int main()
{
  int A, B;
  cin >> A >> B;
  --A;
  --B;
  cout << (B + A - 1) / A << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int a[] = new int[n];
		int alice = 0;
		int bob = 0;

		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);

		for(int i = 0; i < n; i++){
			if(i % 2 == 0){
				alice += a[n - i - 1];
			}
			else {
				bob += a[n - i - 1];
			}
		}

		System.out.println(alice - bob);
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <math.h>

int main(void) {
	double x[2], y[2];
	scanf("%lf%lf%lf%lf", &x[0], &x[1], &y[0], &y[1]);
	printf("%lf", sqrt((x[0] - y[0])*(x[0] - y[0]) + (x[1] - y[1]) * (x[1] - y[1])));
	return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,z,k,l;
  cin >> x >> y >> z >> k >> l;
  if(x==0)cout << 1;
  if(y==0)cout << 2;
  if(z==0)cout << 3;
  if(k==0)cout << 4;
  if(l==0)cout << 5;
}

Measured memory_bytes: 3588
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int current = Integer.parseInt(sc.next());
		int end = Integer.parseInt(sc.next());
		int result = 0;
		for (; current <= end; current++) {
			char[] arr = Integer.toString(current).toCharArray();
			if (arr[0] == arr[4] && arr[1] == arr[3]) {
				result++;
			}
		}
		System.out.println(result);
	}
}



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

typedef pair<int, int> P;
ll mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    if(n%2==1){
        cout << n/2+1 << endl;
    }else{
        cout << n/2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

vector<bool> IsPrime;
void sieve(ll max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(ll i=2; i*i<=max; ++i)
        if(IsPrime[i])
            for(ll j=2; i*j<=max; ++j)
                IsPrime[i*j] = false;
}

int a[100010];

int main(){
    int q;
    cin >> q;
    vector<int> ans;

    sieve(100010);
    for(int i = 1; i <= 100010; i += 2){
        if (IsPrime[i] && IsPrime[(i+1)/2]) {
            a[i]++;
        }
    }
    rep(i, 100009) a[i+1] += a[i];

    rep(i, q){
        int l, r;
        cin >> l >> r;
        ans.push_back(a[r] - a[l-1]);
    }

    // rep(i, 10) cout << a[i] << endl;

    rep(i, q) cout << ans[i] << endl;

    return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	while(cin>>n,n!=0){
		set<P> s;
		rep(i,n){
			int x,y;
			cin>>x>>y;
			s.insert(P(x,y));
		}
		int pos_x=10,pos_y=10;
		int m;
		cin>>m;
		rep(i,m){
			char c;
			int v;
			cin>>c>>v;
			int step=1;
			if(c=='S') c='N',step*=-1;
			if(c=='W') c='E',step*=-1;
			
			if(c=='N'){
				while(v--){
					pos_y+=step;
					s.erase(P(pos_x,pos_y));
				}
			}
			if(c=='E'){
				while(v--){
					pos_x+=step;
					s.erase(P(pos_x,pos_y));
				}
			}
		}
		cout<<(s.empty()?"Yes":"No")<<endl;
	}
	return 0;
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int aa[100010];

int main(){
    int n,k,q;
    cin>>n>>k>>q;

    rep(i,q){
        int a;
        cin>>a;
        a--;
        aa[a]++;
    }
    rep(i,n){
        if(k-(q-aa[i])>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

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

int main(void) {
	int W, a, b, tmp;
	cin >> W >> a >> b;

	if (a < b) {
		tmp = b - a - W;
	}
	else {
		tmp = a - b - W;
	}

	if (tmp <= 0) {
		printf("0");
	}
	else printf("%d", tmp);
	return 0;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int contest[27] = {0};
int satisfact[366][27] = {0};
int ans[366] = {0};
int t[366] = {0};
int last[27] = {0};
int last_day(int i)
{
	int ret = last[i];
	return ret;
}

int query[100002][2] = {0};
int ans2[100002] = {0};
int main()
{
	int D = 0;
	scanf("%d", &D);
	memset(satisfact, 0, sizeof(satisfact));

	int i = 1, d = 1;
	for (i = 1; i <= 26; i++ ) {
		scanf("%d", &contest[i]);
	}
	for (d = 1; d <= D; d++) {
		for (i = 1; i <= 26; i++ ) {
			scanf("%d", &satisfact[d][i]);
		}
	}
	for (d = 1; d <= D; d++ ) {
		scanf("%d", &t[d]);
	}
	int M = 0, m = 0;
	scanf("%d", &M);
	for (m = 1; m <= M; m++ ) {
		scanf("%d %d", &query[m][0], &query[m][1]);
	}

	// day 1 stisfact = 0
	// contest open .. day d, contest type i statisfact(d,i) increase
	// if contest type not open, test never open last(d,i) = 0.
	for (m = 1; m <= M; m++) {
		int tmp = t[query[m][0]];
		t[query[m][0]] = query[m][1];
		for (d = 1; d <= D; d++) {
			ans[d] = satisfact[d][t[d]] + ans[d - 1];
			for (i = 1; i <= 26; i++ ) {
				if (i != t[d]) {
					ans[d] -= contest[i] * (d - last_day(i));
				}
			}
			last[t[d]] = d;
		}
		for (d = 1; d <= D; d++) {
			//printf("%d\n", ans[d]);
			ans2[m] = ans[d];
		}
		//t[query[m][0]] = tmp;
		memset(last, 0, sizeof(last));
	}
	for (d = 1; d <= M; d++) {
		printf("%d\n", ans2[d]);
	}
	return 0;
}


Measured memory_bytes: 2884
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
	
	while(true){
		int num = 0;
		int n, x;
		cin>>n>>x;
		int N[n];
		if(n==0&&x==0)
			break;
		for(int i=0;i<n;i++)	//初始化数组 
			N[i]=i+1;
		
		int a, b, c;
		for(int i=0;i<n-2;i++){
			a = N[i]; 
			for(int j=i+1;j<n-1;j++){
				b = N[j];
				for(int k = j+1;k<n;k++){
					c = N[k];
					if((a+b+c)==x)
						num++;
				}
			}
		}
		printf("%d\n", num);
	}
	
	return 0;
}



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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;
using Pll = P<LL,LL>;
using Pdd = P<double,double>;
using Psi = P<string,double>;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T>
T SUM(V<T> v, T init_val=0){return accumulate(ALL(v),T(init_val));}

LL f(LL n){
    LL even_num = (n+1)/2;
    LL t = ((n+1)%2==0)?0:n;
    return even_num%2 ^ t;
}

int main(){
    LL a,b;
    cin>>a>>b;

    cout<<(f(a-1) ^ f(b))<<endl;

    return 0;
}

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

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

int main(){
    int N,*d,i;
    cin >> N;
    d = new int[N];
    for(i=0;i<N;i++){
        cin >> d[i];
    }
    qsort(d,N,sizeof(int),compare_int);
    int tmp = d[0],count=1;
    for(i=1;i<N;i++){
        if(tmp!=d[i]){
            count++;
            tmp = d[i];
        }
    }
    cout << count << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
const int maxn=2e5+5;
char str[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",str);
    int res=0;
    int ans=0;
    for(int i=0;i<n;++i)
    if(str[i]=='R')
    res++;
    for(int i=0;i<n;++i)
    if(str[i]=='R'&&i>=res)
    ans++;
    printf("%d\n",ans);
    return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    for (auto i = 1; i <= 100; i++) {
        if((i * a) % b == c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

int main(){
    int dish[5],save = 10,index,sum = 0;
    for(int i=0;i<5;i++){
        cin >> dish[i];
        if((dish[i]-1) % 10 < save){
            save = (dish[i]-1) % 10;
            index = i;
        }
    }
    for(int i=0;i<5;i++){
        if(i == index){
            sum += dish[i];
        }else{
            sum += ((dish[i]-1) / 10 + 1) * 10;
        }
    }
    cout << sum;
}

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

int main() {
  
  int n, m; cin >> n >> m; int vec1[n][m]; vector<int> vec2(m);
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> vec1[i][j];
    }
  }
  
  for (int i = 0; i < m; i++) cin >> vec2.at(i);
  
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = 0; j < m; j++) {
      tmp += vec1[i][j] * vec2.at(j);
    }
    cout << tmp << endl;
  }
  
}


Measured memory_bytes: 3124
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	cin>>n;
	vector<string>in(n);
	map<string,int>tmp;
	vi ne(n);
	rep(i,n)cin>>in[i]>>ne[i];
	rep(i,n)tmp[in[i]]=i;
	int m;
	cin>>m;
	vi in1,in2;
	rep(i,m){
		string a,b;
		cin>>a>>b;
		int c=tmp[a],d=tmp[b];
		in1.pb(c);
		in2.pb(d);
	}
	rep(i,m){
		rep(j,m){
			if(ne[in1[j]]>ne[in2[j]])ne[in1[j]]=ne[in2[j]];
			else if(ne[in1[j]]<ne[in2[j]])ne[in2[j]]=ne[in1[j]];
		}
	}
	int sum=0;
	rep(i,n)sum+=ne[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 1876
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        long sum = 0;
        long tmp = 0;
        for (int i = 0; i < n; i++) {
            final long current = scanner.nextInt();
            if (current == 0) {
                sum += tmp / 2;
                tmp = 0;
            } else {
                tmp += current;
            }
        }

        sum += tmp / 2;
        System.out.println(sum);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

Measured memory_bytes: 36440