akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=3e5+5,maxm=1e5+5;
int m,n;
struct Pair{
    int l,r;
}p[maxn];
bool Cmp(Pair a,Pair b){return a.r-a.l<b.r-b.l;}
class segTree{
    int a[maxn],s[maxn*4],tag[maxn*4];
public:
    segTree(){memset(a,0,sizeof(a));}
    void build(int node,int begin,int end){
        tag[node]=0;
        if(begin==end){
            s[node]=a[begin];
        }else{
            build(2*node,begin,(begin+end)/2);
            build(2*node+1,(begin+end)/2+1,end);
            s[node]=s[2*node]+s[2*node+1];
        }
    }
    void pushdown(int node,int begin,int end){
        if(begin==end){
            s[node]+=tag[node];
            a[begin]=s[node];
        }else{
            tag[2*node]+=tag[node];
            tag[2*node+1]+=tag[node];
            s[node]+=tag[node]*(end-begin+1);
        }
        tag[node]=0;
    }
    void Change(int node,int begin,int end,int left,int right,int add){
        if(begin>=left&&end<=right){
            tag[node]+=add;
        }else{
            pushdown(node,begin,end);
            int m=(begin+end)/2;
            if(!(right<begin||left>m)){
                Change(2*node,begin,m,left,right,add);
            }
            if(!(right<m+1||left>end)){
                Change(2*node+1,m+1,end,left,right,add);
            }
        }
    }
    int query(int node,int begin,int end,int idx){
        pushdown(node,begin,end);
        if(begin==end)return a[begin];
        int m=(begin+end)/2;
        if(idx<=m)return query(2*node,begin,m,idx);
        return query(2*node+1,m+1,end,idx);
    }
}st;
int main(){
    scanf("%d%d",&n,&m);
    st.build(1,1,m);
    for(int i=0;i<n;i++)
        scanf("%d%d",&p[i].l,&p[i].r);
    sort(p,p+n,Cmp);
    int i=0;
    for(int d=1;d<=m;d++){
        while(i<n&&p[i].r-p[i].l<d){
            st.Change(1,1,m,p[i].l,p[i].r,1);
            i++;
        }
        int ans=n-i;
        for(int k=d;k<=m;k+=d){
            ans+=st.query(1,1,m,k);
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

vi v(5);

void read() {
  cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4];
}

void solve() {
  int cmax = 1e9, ind = 0;
  for(int i = 0; i < 5; ++i)
    if (v[i] % 10 < cmax && v[i] % 10 != 0) {
      cmax = v[i] % 10;
      ind = i;
    }
  int sol = v[ind];
  for(int i = 0; i < ind; ++i) {
    sol += v[i];
    if (v[i] % 10 != 0)
      sol += 10 - v[i] % 10;
  }
  for(int i = ind + 1; i < 5; ++i) {
    sol += v[i];
    if (v[i] % 10 != 0)
      sol += 10 - v[i] % 10;
  }
  cout << sol;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


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

using namespace std;
#define ll long long
#define ld long double

set<int> s;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    int a[n];
    for(int i=0;i<n;i++) a[i] = -1;
    while(m--) {
        int idx, val;
        cin >> idx >> val;
        if(a[idx-1] != -1 && val != a[idx-1]) {
            cout << -1 << endl;
            return 0;
        }
        a[idx-1] = val;
    }
    string ans = "";
    for(int i=0;i<n;i++) {
        if(a[i] == -1) {
            if(i == 0 && n != 1) {
                a[i] = 1;
            }
            else a[i] = 0;
        }
        ans += to_string(a[i]);
    }
    if(ans[0] == '0' && n > 1) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) 
{ v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i]; }
template<class T, class U> void read_n(vector<pair<T, U>>& v, size_t n)
{ v = vector<pair<T, U>>(n); 
  for (lli i=0; i<n; ++i) cin >> v[i].first >> v[i].second; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
lli n, p[2], dx = 0;
vector<lli> vp[2];
bool dp[2][40001];
int main() {
  cin >> s >> p[0] >> p[1];
  n = s.size();
  lli i = 0;
  for (; i<n && s[i]=='F'; ++i) ++dx;
  p[0] -= dx;
  lli v = 0;
  lli f = 0;
  for (; i<n; ++i) {
    if (s[i] == 'T') {
      if (v>0) vp[f].push_back(v);
      v = 0;
      f = (f+1)&1;
    } else {
      v++;
    }
  }
  if (v>0) vp[f].push_back(v);
  bool res = true;
  for (lli f=0; f<=1; ++f) {
    for (lli i=0; i<=1; ++i) fill(&dp[i][0], &dp[i][40000], false);
    dp[0][20000] = true;
    lli i = 0;
    for (; i<vp[f].size(); ++i) {
      fill(&dp[(i+1)&1][10000], &dp[(i+1)&1][30000], false);
      for (lli j=10000; j<=30000; ++j) {
	if (dp[i&1][j]) {
	  dp[(i+1)&1][j + vp[f][i]] = true;
	  dp[(i+1)&1][j - vp[f][i]] = true;
	}
      }
    }
    if (!dp[i&1][p[f]+20000]) res = false;
  }
  auto ans = res ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}


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

int main(){
  int k; cin >> k;
  queue<ll> q;
  rep(i,9){
    q.push(i+1);
  }
  ll t=0;
  while(k>0){
    t = q.front();q.pop();
    for(ll i=-1;i<=1;i++){
      ll u = (t%10) + i;
      if(u<0||u>9)continue;
      q.push(t*10 + u);
    }
    k--;
  }
  printf("%lld\n",t);
  return 0;
}


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


void solve(long long L, long long R, long long d){
    long long ans = 0;
    for (auto i = L; i <= R; i++) {
        if (i % d == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3632
import java.util.*;
 
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int M1 = sc.nextInt();
		int D1 = sc.nextInt();
		int M2 = sc.nextInt();
		int D2 = sc.nextInt();
		int ans;
    if (M1 == M2) {
      ans = 0;
		}else {
			ans = 1;
		}
		System.out.println(ans);
  }
}

Measured memory_bytes: 35696
S = input()
n = len(S)
res = 1000

for i in range(n):
    if i>(n-1):
        pickup = int(S[i])
    elif i>(n-3):
        pickup = int(S[i:n])
    else:
        pickup = int(S[i:i+3])
    
    if (abs(753-pickup) < res):
        res = abs(753-pickup)
print(res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    ll ans = 0;
    
    ans=power(10,n)-2*power(9,n)+power(8,n);
    while(ans<0) ans+=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include<iostream>
using namespace std;
#include<stdio.h>
struct o
{
	int x,y,z;
};
int main(void)
{
	o d[1000];
	int a,b,c,n,m,g[3],s;
	a=0;
	scanf("%d",&b);
	for(c=0;c<b;c++)
	{
		for(n=0;n<3;n++)
		{
			scanf("%d",&g[n]);
		}
		for(n=0;n<3;n++)
		{
			for(m=n+1;m<3;m++)
			{
				if(g[n]>g[m])
				{
					s=g[n];
					g[n]=g[m];
					g[m]=s;
				}
			}
		}
		d[c].x=g[0];
		d[c].y=g[1];
		d[c].z=g[2];
		for(n=0;n<c;n++)
		{
			if(d[n].x==d[c].x&&d[n].y==d[c].y&&d[n].z==d[c].z)
			{
				a++;
				break;
			}
		}
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 3244
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	//int A, B, C;
	
	//cin >> A >> B >> C;

	string a, b;
	cin >> a >> b;

	cout << b << a <<endl;

	
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li n;
double dp[3000][3000], a[3000], tmp, ans;

int main () {
    fastIO;
    cin >> n;
    for(li i = 1; i <= n; i ++) cin >> a[i];
    dp[0][0] = 1;
    for(li i = 1; i <= n; i ++) {
        for(li j = 0; j <= i; j ++) {
            dp[i][j] = dp[i-1][j] * (1 - a[i]);
            if(j==0) continue;
            dp[i][j] += dp[i-1][j-1] * a[i];
        }
    }
    for(li i = n/2 + 1; i <= n; i ++) ans += dp[n][i];
    cout << fixed << setprecision(12) << ans;
}


Measured memory_bytes: 68992
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI(); /// skip this line for compile
    int n;
    string s;
    unordered_set<string>st;
    cin >> n;
    while(n--){
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}



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

int main() {
    int n;
    cin >> n;
    int a[n+1];
    rep(i,n+1) {
        cin >> a[i];
    }
    int64_t ans = 0;
    rep(i,n) {
        int b;
        cin >> b;
        if (i != n-1) {
            int at = min(a[i], b);
            a[i] -= at;
            ans += at;
            int at2 = min(a[i+1], b - at);
            a[i+1] -= at2;
            ans += at2;
        }
        else {
            int at = min(a[n], b);
            ans += at;
            int at2 = min(a[n-1], b - at);
            ans += at2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            var n = Cint();
            var m = Cint();

            var s = new int[m];
            var c = new int[m];

            Loop(m, i =>
            {
                s[i] = Cint();
                c[i] = Cint();
            });
            
            var num = new string('0', n).ToCharArray();
            var written = new List<Tuple<int, int>>();
            
            Loop(m, i =>
            {
                if (written.Any(w => w.Item1 == s[i] && w.Item2 != c[i]) || s[i] == 1 && c[i] == 0 && n > 1)
                {
                    Cout(-1);
                    Environment.Exit(0);
                }
                
                num[s[i] - 1] = c[i].ToString().First();
                written.Add(new Tuple<int, int>(s[i], c[i]));
            });
            
            if (num[0] == '0' && n > 1)
            {
                num[0] = '1';
            }
            
            Cout(int.Parse(new string(num)));
        }

        #region Input and Output

        private static readonly List<string> Buffer = new List<string>();

        private static string Cin()
        {
            ReadBuffer();

            var str = Buffer.First();
            Buffer.RemoveAt(0);

            return str;
        }

        private static IEnumerable<string> CinA() => Console.ReadLine()?.Split();
        private static int Cint() => int.Parse(Cin());
        private static int[] CintA() => CinA().Select(int.Parse).ToArray();
        private static void Cout(object obj) => Console.WriteLine(obj);

        private static void ReadBuffer()
        {
            if (Buffer.Any()) return;

            var line = Console.ReadLine();
            if (line != null && line.Contains(' '))
            {
                Buffer.AddRange(line.Split());
            }
            else
            {
                Buffer.Add(line);
            }
        }

        #endregion

        #region Loops

        private static void Loop(int count, Action<int> action) => Loop(0, count, action);

        private static void Loop(int init, int count, Action<int> action, int step = 1)
        {
            for (var i = init; i < count + init; i += step)
            {
                action(i);
            }
        }

        #endregion
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char s[1001];
    cin>>s;
    int l=strlen(s);
    for(int i=0;i<l;i++)
    {
        if(s[i]=='C')
        {
            for(int j=i+1;j<l;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;
int main()
{
    int n;
    ll a[87]={0};
    a[0]=2;
    a[1]=1;
    for(int i=2;i<=86;i++)
    {
        a[i]=a[i-1]+a[i-2];
    }
    scanf("%d",&n);
    printf("%lld\n",a[n]);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        cout << a.at(i);
        if(i!=n-1)cout << " ";
    }
    for(int i=1;i<n;i++){
        int j=i-1;
        int v=a[i];
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        cout << endl;
        for(int k=0;k<n;k++){
            if(k>0)cout << " ";
            cout << a[k];
        }
    }
    cout << endl;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,c=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n-2;i++)
    {
      if((a[i+1]>a[i] && a[i+1]<a[i+2]) || (a[i+1]<a[i] && a[i+1]>a[i+2]))
        c++;
  }
  cout<<c;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    #define COUT(N) cout<<fixed<<setprecision(N)
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    string N;
    cin >> N;
    if(N[0] == '7' ||N[1] == '7'||N[2] == '7' )cout <<"Yes";
    else cout <<"No";

    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define inf 1e9
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)
#define repfr(i, n, x) for (ll i = (ll)(n)-1; i >= (ll)(x); i--)
using ll = int64_t;

void Main() {
  int n;
  std::cin >> n;
  std::vector<ll> a(n);
  for (auto &x : a) {
    cin >> x;
  }

  int ans = 0;
  bool flag = true;

  while (flag) {
    for (auto &x : a) {
      if (x % 2 == 0) {
        x /= 2;
      } else {
        flag = false;
      }
    }
    if (flag) {
      ans++;
    }
  }

  std::cout << ans << '\n';
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

using namespace std;

string s;

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

    cin >> s;

    s = s.substr(0, 5) + ' ' + s.substr(6, 7) + ' ' + s.substr(14, 5);

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int h, w, d;
int a[310][310];
int q;
int l[100100], r[100100];

void solve() {
    P rev[h*w+1];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            rev[a[i][j]] = P(i, j);
        }
    }
    vector<int> sum[d];
    for (int i = 1; i <= d; i++) {
        const int im = i%d;
        sum[im].push_back(0);
        int j = i;
        while (j+d <= h*w) {
            P p0 = rev[j], p1 = rev[j+d];
            sum[im].push_back(abs(p0.first-p1.first)+abs(p0.second-p1.second));
            j += d;
        }
        
        for (int k = 1; k < (int)sum[im].size(); k++) {
            sum[im][k] += sum[im][k-1];
        }
    }

    for (int i = 0; i < q; i++) {
        int m = l[i] % d;
        int il = l[i] / d;
        int ir = r[i] / d;
        if (m == 0) {
            il--;
            ir--;
        }
        cout << sum[m][ir] - sum[m][il] << endl;
    }
}

void input() {
    cin >> h >> w >> d;
    for (int i = 0; i < h; i++) {
        for (int j  = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    cin >> q;
    for (int i = 0; i < q; i++) cin >> l[i] >> r[i];
}

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

    input();
    solve();
}


Measured memory_bytes: 7936
#include<cstdio>
using namespace std;
int n,h[100001],dp[100001];
int min(int a,int b){return a<b?a:b;}
int abs(int a){return a>0?a:-a;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&h[i]);
	dp[0]=0x3f3f3f3f;
	for(int i=2;i<=n;++i) dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
	printf("%d",dp[n]);
}

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

bool is_palindromic(int n) {
	int n1, n2, n4, n5;
	n5 = n / 10000;
	n %= 10000;
	n4 = n / 1000;
	n %= 100;
	n2 = n / 10;
	n1 = n % 10;
	if (n1 == n5 && n2 == n4) {
		return true;
	} else {
		return false;
	}
}


int main() {
	int A, B;
	int sum = 0;
	cin >> A >> B;
	for (int i = A; i <= B; i++) {
		if (is_palindromic(i)) sum++;
	}
	cout << sum << endl;
}



Measured memory_bytes: 256
def extgcd(a, b):
    x, y = 1, 0
    g, e = 1, 0
    while b != 0:
        q, r = divmod(a, b)
        m = x-q*e
        n = y-q*g
        a, b = b, r
        x, e = e, m 
        y, g = g, n 
    return x, y, g

a, b = map(int, input().split())
x, y, g = extgcd(a, b)

print(x, y)




Measured memory_bytes: 5600
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  ll N,M;
  cin >> N >> M;
  ll seikai = 0;
  ll out = 0;
  vector<ll> p(M);
  vector<string> s(M);
  rep(i,M){
    cin >> p.at(i);
    cin >> s.at(i);
  }
  vector<ll> ok(N, 0);
  rep(i,M){
    if(s.at(i)=="AC"){
      ok.at(p.at(i)-1)++;
    }
  }
  rep(i,N){
    if(ok.at(i)>0){
      seikai++;
    }
  }


  rep(i,M-1){
    if(p.at(i)==p.at(i+1) && s.at(i)=="AC"){
      s.at(i+1) = "AC";
    }
  }


vector<ll> ok2(N, 0);
  rep(i,M){
    if(s.at(i)=="WA"&&ok2.at(p.at(i)-1)==0&&ok.at(p.at(i)-1)>0){
      out++;
    }else{
      ok2.at(p.at(i)-1)++;
    }
  }

cout << seikai << " "<< out  <<endl;



}


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

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

const int maxn=307;

int n,k,m,f[maxn][maxn],g[maxn][maxn],C[maxn][maxn];

int main(){
	scanf("%d%d%d",&n,&k,&m);
	C[0][0]=1;
	for(int i=1;i<maxn;++i){
		for(int j=1;j<maxn;++j)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%m;
		C[i][0]=1;
	}
	for(int i=0;i<=k;++i)f[1][i]=1,g[1][i]=k-i+1;
	for(int i=2;i<=n+1;++i){
		for(int j=0;j<=k;++j){
			for(int t=1;t<i;++t)
				f[i][j]=(f[i][j]+1ll*f[t][j]*g[i-t][j+1]%m*C[i-2][t-1])%m;
//			printf("f[%d][%d]=%d\n",i,j,f[i][j]);
		}
		for(int j=k;j>=0;--j)g[i][j]=(g[i][j+1]+f[i][j])%m; 
	}
	printf("%d\n",f[n+1][0]);
	return 0;
}
/*
4 3 999999999

150 150 998244353
*/


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,N;cin>>X>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++)cin>>p[i];
  int m=-1000;
  for(int i=-300;i<300;i++){
    bool d=true;
  	for(int j=0;j<N;j++){
      if(i==p[j])d=false;
    }
    if(d){
      if(abs(m-X)>abs(i-X)){
        m=i;
      }
    }
  }
  cout<<m<<endl;
}


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

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i< n; i++) {
        cin >> A.at(i);
    }
    for(int i = 0; i < n; i++) {
        int note = i;
        for(int j = i; j < n; j++) {
            if(A.at(j) < A.at(note)) 
                note = j;
        }
        if(i != note) {
            swap(A.at(i), A.at(note));
            ans++;
          
        }
    }
    for(int i = 0; i < n; i++) {
        cout << A.at(i);
        if(i != n-1)cout << " ";
    }
    cout << endl << ans << endl;
}


Measured memory_bytes: 3108
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct Node{int p,l,r;}Node;

Node T[MAX];
int n,D[MAX];

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  c=T[u].l;
  for(i=0;c!=NIL;i++){
    if(i) printf(", ");
    printf("%d",c);
    c=T[c].r;
  }
  printf("]\n");
}

int rec(int u,int p){
  D[u] = p;
  if(T[u].r!=NIL) rec(T[u].r,p);
  if(T[u].l!=NIL) rec(T[u].l,p+1);
}

int main(){
  int i,j,d,c,v,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p=T[i].l=T[i].r=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) T[v].l = c;
      else T[l].r = c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p ==NIL) r=i;
  }
  rec(r,0);

  for(i=0;i<n;i++) print(i);
  return 0;
}



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

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

    int ans;
    if (a > 9 or b > 9){
        ans = -1;
    }
    else{
        ans = a * b;
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
typedef long long ll;
const ll m = 998244353;
ll v[1000000];
ll ksm(ll a, ll b) {
	ll c = 1;
	while (b) {
		if (b & 1) c = c * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return c;
}

using namespace std;
int main() {
	ll n,x,ma;
	cin >> n;
	ma = 0;
	cin >> x;
	v[x]++;
	if (x) {
		cout << "0\n";
		return 0;
	}

	for (int i = 1; i < n; i++) {
		cin >> x;
		v[x]++;
		if (ma < x) ma = x;
	}
	if (v[0] != 1) {
		cout << "0\n";
		return 0;
	}
		
	for (int i = 1; i <= ma; i++) {
		if (v[i] == 0) {
			cout << "0\n";
			return 0;
		}		
	}
	long long ans = 1;
	for (int i = 2; i <= ma; i++) {
		ans = (ans * ksm(v[i-1],v[i])) % m;
	}
	cout << ans << '\n';

	return 0;
}



Measured memory_bytes: 1024
n,m = map(int,input().split())
connections = sorted([list(map(int,input().split())) for _ in range(m)], key = lambda x: x[1])

cut = 0
ans = 0
for i in range(m):
    if connections[i][0] >= cut:
        ans += 1
        cut = connections[i][1]

print(ans)

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

int main() {
	int n;
	cin >> n;
	vector<int>d(n);
	for(int i=0;i<n;i++)
	{
		cin >> d.at(i);
	}
	sort(d.begin(),d.end());
	int d1=d.at((n/2)-1),d2=d.at(n/2),k=d2-d1;
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 3768
#include <iostream>

using namespace std;

char s[100010] = {};
long long int a = 99999, b[100001] = {}, c = 0, ans = 0;
bool flag = false;

int main() {
	cin >> s;
	for (int i = 0; i < 100000; i++) {
		if (s[i] != 'x') {
			c++;
			if (!flag) {
				for (int j = a; j > 0; j--) {
					if (s[j] != 'x' && s[j] != NULL) {
						if (i >= j) {
							flag = true;
							break;
						}
						if (s[j] == s[i]) {
							a = j - 1;
							break;
						}
						else {
							cout << -1 << endl;
							return 0;
						}
					}
				}
			}
		}
		if (s[i + 1] == NULL)break;
		b[c]++;
	}
	for (int i = 0; i < (c + 1) / 2; i++) {
		if (b[i] != b[c - i])
			ans += abs(b[i] - b[c - i]);
	}
	cout << ans << endl;
	return 0;
}

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

int x, y;

int sh(int i, int j) {
  int a, b;
  a = j - i;
  b = abs(x - i) + abs(y - j) + 1;
  return min(a, b);
}

int main() {
  int n;
  cin >> n >> x >> y;
  vector<int> k(n, 0);
  for(int i = 1; i < n; i++) {
    for(int j = i + 1; j <= n; j++) {
      k.at(sh(i, j))++;
    }
  }
  for(int i = 1; i < n; i++) cout << k.at(i) << endl;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>	
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int,LL> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int maxn = 2e5;
LL d[maxn], a[maxn]; 
int vis[maxn];
int n, m;
std::vector<int> G[maxn];
std::vector<LL> s1[maxn], s2[maxn];
LL ts1[maxn], ts2[maxn];

int dp(int r, int p){
	if(vis[r]) return d[r];
	d[r] = 1; 
	vis[r] = 1;
	for(int v : G[r]){
		if(v != p){
			d[r] = (d[r] * (1 + dp(v, r))) % m;
		}
	}
	// cout << r << ' ' << d[r] << endl;
	LL t = d[p];
	d[p] = 0;
	int num = (int)G[r].size();
	ts1[0] = (1 + d[G[r][0]]) % m;
	ts2[num - 1] = (1 + d[G[r][num - 1]]) % m;
	for(int i = 1; i < num; ++i){
		ts1[i] = ts1[i - 1] * (1 + d[G[r][i]]) % m;
	}
	for(int i = num - 2; i >= 0; --i){
		ts2[i] = ts2[i + 1] * (1 + d[G[r][i]]) % m;
	}
	for(int i = 0; i < num; ++i){
		s1[r].push_back(ts1[i]);
		s2[r].push_back(ts2[i]);
	}
	d[p] = t;
	/*cout << r << endl;
	for(int i = 0; i < num; ++i){
		cout << G[r][i] << ' ' << ts1[i] << ' ';
	}
	cout << endl;
	*/
	return d[r];
}
void dfs(int r, int p, int x){	
	if(p != 0){
		a[r] = a[p];
		if(x > 0) a[r] = a[r] * s1[p][x - 1] % m;
		if(x < (int)G[p].size() - 1) a[r] = a[r] * s2[p][x + 1] % m;
		++a[r];
	}

	for(int i = 0; i < (int)G[r].size(); ++i){
		if(G[r][i] != p)
			dfs(G[r][i], r, i);
	}
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	if(n == 1) {
		cout << 1 << endl;
		return 0;
	}
	for(int i = 1; i < n; ++i){
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	a[1] = 1;
	dp(1, 0);
	dfs(1, 0, 0);
	for(int i = 1; i <= n; ++i){
		cout << d[i] * a[i] % m << endl;
	}
	return 0;
}

Measured memory_bytes: 35968
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		long long int h1,m1,h2,m2,k=0;
      	cin >> h1 >> m1 >> h2 >> m2 >> k;
      	long long int h = h2-h1;
      	long long int m=0;
      	if(m2>m1){m = m2-m1;}
      	else{
        	m = 60 - (m1 - m2);
          	h--;
        }
      	m = h*60 + m;
      	cout << m - k <<endl;
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
/*********ANISH***********ANISH*************ANISH***********ANISH******/
#define pb push_back
#define ll long long
#define ff first
#define ss second
ll max(ll a,ll b)
{
    if(a>b) return a;
    return b;
}
ll min(ll a,ll b)
{
    if(a<b) return a;
    return b;
}
/********ANISH************ANISH*************ANISH**********ANISH*********/
int main()
{
    int t;
    t=1;
    while(t--)
    {
        int n;
        cin>>n;
        int arr[n];
        for(int i=0;i<n;++i) cin>>arr[i];
        int dp[n];
        dp[0]=0,dp[1]=abs(arr[1]-arr[0]);
        for(int i=2;i<n;++i)
        {
            dp[i]=min(abs(arr[i]-arr[i-2])+dp[i-2],abs(arr[i]-arr[i-1])+dp[i-1]);
        }
        cout<<dp[n-1];
    }
}


Measured memory_bytes: 1024
/* Author : samarth
   Handle : ssg_13 */

//----------------------template begins--------------------------------//
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono;

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back //faster than pb
#define pb push_back 
#define Db(x) cout << '>' << #x << ':' << x << endl;
#define forn(i,n) for(ll i=0;i<n;i++)
#define rforn(i,n) for(ll i=n-1;i>=0;i--)
#define forne(i,n) for(ll i=1;i<=n;i++)
#define forse(i,s,e) for(ll i=s;i<e;i++)
#define rforse(i,s,e) for(ll i=e;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define PT palindromeTest	//Input - string, int, ll, l
#define GS generateSubsets	//Input - n		//Return - vector<vector<int>>
#define GP generatePermutations //Input - int n 	//Return - vector<vector<int>>
#define PF primeFactorization	//Input - ll	//Return - vector<ll>
#define nCr nCrModPFermat   //Input - n, r, p	//Return - nCr mod p
// #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
// void err(istream_iterator<string> it) {}
// template<typename T, typename... Args>
// void err(istream_iterator<string> it, T a, Args... args) {
// 	cerr << *it << " = " << a << endl;
// 	err(++it, args...);
// }

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(i) return pointer to ith index in ordered set


const ll MOD = 1000000007;
ll modpow(ll a,ll b,ll m=MOD) {a%=m;ll res=1;while(b){if(b&1)res=res*a%m;a=a*a%m;b>>=1;}return res;}
ll bpow(ll a, ll b) {ll res = 1;while(b){if(b&1)res=res*a;a=a*a;b>>=1;}return res;}
ll modinv(ll a){return modpow(a,MOD-2,MOD);}
void graph(vector<ll> adj[], ll m){ll x, y; forn(i, m){cin>>x>>y;adj[x-1].pb(y-1);adj[y-1].pb(x-1);}}
ll sum() { return 0; }
template<typename T, typename... Args>
auto sum(T a, Args... args) { return a + sum(args...); }

const ll INF=(ll)1e18;
const int MAXN = 200001;
//----------------------template ends--------------------------------//

int main()
{
fast;
cout << fixed << setprecision(11);
cerr << fixed << setprecision(6);
auto start = high_resolution_clock::now();
ll T;
// cin>>T;
T=1;
while(T--)
{
    ll n;
    cin>>n;
    ll a[4]={0,0,0,0};
    forn(i,n)
    {
        string s;
        cin>>s;
        if(s=="AC") a[0]++;
        else if(s=="WA") a[1]++;
        else if(s=="TLE") a[2]++;
        else a[3]++;
    }
    cout<<"AC x "<<a[0]<<'\n';
    cout<<"WA x "<<a[1]<<'\n';
    cout<<"TLE x "<<a[2]<<'\n';
    cout<<"RE x "<<a[3]<<'\n';
}
auto stop = high_resolution_clock::now(); 
auto duration = duration_cast<microseconds>(stop - start);
// cout << "Time taken by function: "
//          << duration.count() << " microseconds" << endl; 
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//def   puts(a) printf("%s\n", a) 文字はこっち
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
//your code here!


int main(void){
    char A[110], B[110];
    ins(A); ins(B);
    if(strlen(A)>strlen(B)){
        puts("GREATER");
        return 0;
    }
    else if(strlen(A)<strlen(B)){
        puts("LESS");
        return 0;
    }
    else {
        rep(i,strlen(A)){
            ll a = A[i]-'0', b = B[i]-'0';
            if(a>b){
                puts("GREATER");
                return 0;
            }
            else if(a<b){
                puts("LESS");
                return 0;
            }
        }
    }
    puts("EQUAL");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<P,int>P2;
#define fi first
#define se second
int n,b[100009],ans[100009];
signed main(){
    cin>>n;
    int a[n+2];
    r(i,n)cin>>a[i+1];
    a[n+1]=0;
    a[0]=0;
    n+=2;
    r(i,n-1){
        ans[i+1]+=ans[i]+abs(a[i+1]-a[i]);
    }
    for(int i=1;i<n-1;i++){
        if(a[i-1]<=a[i]&&a[i]<=a[i+1]||a[i-1]>=a[i]&&a[i]>=a[i+1]){
            cout<<ans[n-1]<<endl;
        }
        else{
                cout<<ans[n-1]-abs(a[i-1]-a[i])-abs(a[i+1]-a[i])+abs(a[i-1]-a[i+1])<<endl;
            //}
        }
    }
}


Measured memory_bytes: 2816
d,g=gets.split.map(&:to_i)
q=[]
c=[]
d.times do
  qq,cc=gets.split.map(&:to_i)
  q << qq
  c << cc
end
m=1/0.0
[0,1].repeated_permutation(d) do |b|
  k=0
  d.times do |i|
    k+=b[i]*q[i]
  end
  next if k>=m
  v=0
  d.times do |i|
    v+=b[i]*(q[i]*(i+1)*100+c[i])
  end
  if v>=g
    m=k
  else
    (d-1).downto(0) do |i|
      if b[i]==0
        if v+(q[i]-1)*(i+1)*100>=g
          k+=(g-v-100)/((i+1)*100)+1
          m=k if k<m
        end
        break
      end
    end
  end
end
puts m


Measured memory_bytes: 14328
import Control.Monad (replicateM)

pointLength::[Int] -> [Int] -> Float
pointLength xa xb = sqrt $ fromIntegral $ sum $ zipWith (\a b -> (a - b) ^ 2) xa xb

isInt::Float->Bool
isInt x = x == fromInteger (ceiling x)

main = do
  [n,d] <- map read . words <$> getLine
  xn <- replicateM n $ map read . words <$> getLine::IO[[Int]]
  print $ length [True | i <- [0..(n-1)],j <- [i..(n-1)], i /= j, isInt $ pointLength (xn !! i) (xn !! j)]

Measured memory_bytes: 1020
import java.util.*;

public class Main{
    
    static final int MOD = (int)1e9 + 7;
    static int n;
    static int k;
    static ArrayList<Integer>[] g;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        n = Integer.parseInt(sc.next());
        k = Integer.parseInt(sc.next());
        
        g = new ArrayList[n];
        for(int i=0; i<n; i++){
            g[i] = new ArrayList<>();
        }
        
        for(int i=0; i<n-1; i++){
            int a = Integer.parseInt(sc.next())-1;
            int b = Integer.parseInt(sc.next())-1;
            g[a].add(b);
            g[b].add(a);
        }
        
        int idx = 0;
        for(int i=0; i<n; i++){
            if(g[i].size()==1){
                idx = i;
                break;
            }
        }
        
        System.out.println(dfs(idx, -1, k));
    }
    
    public static long dfs(int now, int pre, long c){
        long ret = c;
        
        int color = k-1;
        if(pre!=-1){
            color--;
        }
        
        for(int next : g[now]){
            if(next == pre){
                continue;
            }
            ret *= dfs(next, now, color);
            ret %= MOD;
            color--;
        }
        
        return ret;
    }
}


Measured memory_bytes: 89388
#include <iostream>
#include <vector>
#include <sstream>
#include <iomanip>

using namespace std;

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
        if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

double calc_y(double a, double b, double c, double d, double e, double f) {
    double y = (((d * c) / a) - f ) / (((d * b) / a) - e );
    return y;
}

int main() {
    string str;
    while(getline(cin, str)) {
        vector<string> splited = split(str, ' ');
        double a = stod(splited[0].c_str());
        double b = stod(splited[1].c_str());
        double c = stod(splited[2].c_str());
        double d = stod(splited[3].c_str());
        double e = stod(splited[4].c_str());
        double f = stod(splited[5].c_str());
        double y = calc_y(a, b, c, d, e, f);
        double x = (c - (b * y)) / a;
        cout <<  fixed << setprecision(3) << x << " " << fixed << setprecision(3)  << y << endl;
    }

    return 0;
}

Measured memory_bytes: 3152
import sys
input = sys.stdin.readline
 
n = int(input())
num_list = [ int(v) for v in input().split() ]
ans_list = [ 0 ] * n
for i in range(n-1,-1,-1):
 
    if sum(ans_list[i::i+1]) % 2 == num_list[i]:
        ans_list[i] = 0
    else:
        ans_list[i] = 1
 
print(sum(ans_list))
for i in range(n):
 
    if ans_list[i] == 1:
        print(i+1)


Measured memory_bytes: 68088
#include<stdio.h>
int main(void){
int a,b,c,d,e,f;

scanf("%d",&a);
scanf("%d""%d",&b,&c);
d=b%a;
e=c-b;
f=d+e;
if(a<=f){
    printf("OK");
}
if(a==1){
printf("OK");
}else
if(d==0){
printf("OK");
}
else
if(a>f){
    printf("NG");
}
}

Measured memory_bytes: 1728
from collections import deque

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

ANS = deque()
for i in range(N):
  if i % 2 == 0:
    ANS.append(A[i])
  else:
    ANS.appendleft(A[i])
    
ANS = list(ANS)
if N % 2 == 1:
  ANS = ANS[::-1]
  
print(" ".join(map(str,ANS)))


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



int main(){
	int n;
	cin >> n;
	vector<int> a(n);

	int num4=0, num2 = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] % 4 == 0) num4++;
		else if(a[i] % 2 == 0) num2++;
	}

	if(num4 >= n/2 || num2 == n|| n-num4-num2 == num4) cout << "Yes" << endl;
	else cout << "No" << endl;
	

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

using namespace std;

string S;
char ketame[200000];
char k;
int nagasa;
int kotae1;
int kotae2;


int main(){
  kotae1 = 0;
  kotae2 = 0;
  cin >> S;
  nagasa = S.length();
  for (int i=0;i < nagasa;i++){
    ketame[i] = S[i];
    //cout << ketame[i] << endl;
  }
  for (int i=0;i < nagasa;i++){
    if((ketame[i]=='0' && i%2 == 0)||(ketame[i]=='1' && i%2 == 1)){
      kotae1 ++;
    }
    if((ketame[i]=='1' && i%2 == 0)||(ketame[i]=='0' && i%2 == 1)){
      kotae2 ++;
    }
  }
  cout << min(kotae1,kotae2) << endl;
  return 0;
}

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



int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	if (s == "ABC")
	{
		cout<<"ARC"<<endl;
	}
	else
	{
		cout<<"ABC"<<endl;
	}
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
	}
	int counts =0;
	int minimum = a[0];
	rep(i,n){
		if(a[i] <= minimum) {
			minimum = a[i];
			counts ++;
		}
	}
	cout << counts << endl;
}

Measured memory_bytes: 4020
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>

typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
ll W = 1000000007;

using namespace std;
void omajinai() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}

class Main{
public:
    int N;
    int K,L;
    vector<pair<int,int> > p,r;
    map<pair<int,int> ,int> s;
    vector<int> ufp,ufq;
    
    int getunion(vector<int> &ar,int t){
        if(ar[t] == t ) return t;
        ar[t] = getunion(ar, ar[t]);
        return ar[t];
    }
    bool issameunion(vector<int> &ar, int a, int b){
        return getunion(ar,a) == getunion(ar,b);
    }
    
    Main(){
        cin>>N>>K>>L;
        p = vector<pair<int,int> >(K+1);
        r = vector<pair<int,int> >(L+1);
        FOR(i,1,K+1) cin>>p[i].first>>p[i].second;
        FOR(i,1,L+1) cin>>r[i].first>>r[i].second;
        ufp = vector<int>(N+1);
        ufq = vector<int>(N+1);
        FOR(i,1,N+1) ufp[i] = i,ufq[i] = i;
        FOR(i,1,K+1){int a = getunion(ufp,p[i].first), b = getunion(ufp,p[i].second);  if(a<b) swap(a,b); ufp[a] = b; }
        FOR(i,1,L+1){int a = getunion(ufq,r[i].first), b = getunion(ufq,r[i].second);  if(a<b) swap(a,b); ufq[a] = b; }
        FOR(i,1,N+1){
            pair<int,int> pp = make_pair(getunion(ufp,i),getunion(ufq, i));
            if(s.find(pp)== s.end()) s[pp] = 0;
            s[pp]++;
        }
        cout<<s[make_pair(getunion(ufp,1),getunion(ufq, 1))];
        FOR(i,2,N+1) cout<<" "<<s[make_pair(getunion(ufp,i),getunion(ufq, i))];
        cout<<endl;
    }
    
    void run(){
    }
};

int main(){
    omajinai();
    Main().run();
}


Measured memory_bytes: 15104
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};

ll gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<int> lat[100010];
vector<int> pet[100010];
bool rel[100010];
bool lal[100010];
void rec(int pe) {

	rel[pe] = true;
	for (int c : pet[pe])
	{
		if (lal[c]) continue;
		lal[c] = true;
		for (int ne : lat[c])
		{
			if (rel[ne]) continue;
			rec(ne);
		}
	}
}
void Solve() {
	
	int n;
	cin >> n;
	ll orit[301][301];
	ll wt[301][301];
	for (size_t i = 1; i <= n; i++)
	{
		for (size_t j = 1; j <= n; j++)
		{
			cin >> orit[i][j];
			wt[i][j] = orit[i][j];
		}
	}
	bool find[301][301];
	for (size_t i = 1; i <= n; i++)
	{
		for (size_t j = 1; j <= n; j++)
		{
			find[i][j] = false;
		}
	}

	for (size_t i = 1; i <= n; i++)
	{
		for (size_t j = 1; j <= n; j++)
		{
			for (size_t k = 1; k <= n; k++)
			{

				if (j != i && i != k && wt[j][k] == wt[j][i] + wt[i][k]) {
					find[j][k] = true;
				}
				wt[j][k] = min(wt[j][k], wt[j][i] + wt[i][k]);
			}
		}
	}

	ll res = 0;
	for (size_t i = 1; i <= n; i++)
	{
		for (size_t j = i + 1; j <= n; j++)
		{
			if (orit[i][j] > wt[i][j]) {
				cout << -1 << endl;
				return;
			}
			res += find[i][j] ? 0 : wt[i][j];
		}
	}
	cout << res << endl;
}


int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 7680