akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int k;
  string s;
  cin>>k>>s;
  if(s.size()<=k) cout<<s;
  else
  {
    for (int i = 0; i < k; ++i)
    {
      cout<<s[i];
    }
    cout<<"...";
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int main() {
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<PP> T;
    for (int i = 0;i < M;i++) {
    	int a, b;
    	cin >> a >> b;
    	a--;
    	b--;
    	if (a > b) swap(a, b);
    	T.push_back(make_pair(a, b));
    }
    bool R[400][400];
    bool OK[400];
    memset(R, 0, sizeof(R));
    memset(OK, 0, sizeof(OK));
    for (int i = 0;i < N;i++) {
    	R[i][i] = 1;
    	for (int j = M - 1;j >= 0;j--) {
    		int a = T[j].first;
    		int b = T[j].second;
    		if (R[i][a] && R[i][b]) OK[i] = 1;
    		if (!R[i][a] && !R[i][b]) continue;
    		R[i][a] = 1;
    		R[i][b] = 1;
    	}
    }
    int op = 0;
    for (int i = 0;i < N;i++) {
    	if (OK[i] == 1) continue;
    	for (int j = i + 1;j < N;j++) {
    		if (OK[j] == 1) continue;
    		bool ok = 1;
    		for (int n = 0;n < N;n++) {
    			if (R[i][n] && R[j][n]) ok = 0;
    		}
    		if (ok) op++;
    	}
    }
    cout << op << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int cnt = 1;
	for(int i = 0;i < N;i++) {
		if(vec.at(i) % 2 == 0) {
			cnt = cnt * 2;
		}
	}
	cout << pow(3,N) - cnt << endl;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    string a, b;
    cin >> a >> b;
    ll n = stoll(a+b);
    ll tmp = floor(sqrt(n));
    if (n == tmp*tmp) {
        yes;
    } else no;
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k; vector<int>rsp(4); string t;
	cin>>n>>k>>rsp.at('s'%7)>>rsp.at('p'%7)>>rsp.at('r'%7)>>t;
	int64_t ans=0;
	for(int i=0;i<n;++i){
		if(t.at(i)=='-')break;
		char prev='-';
		for(int j=i;j<n;j+=k){
			char&a=t.at(j);
			if(prev==a)prev='-';
			else{
				ans+=rsp.at(a%7);
				prev=a;
			}
			a='-';
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x;
        ArrayList<Integer> A = new ArrayList<Integer>();
        for (;;) {
            x = sc.nextInt();
            if (x != 0) {
                A.add(x);
            }
            else {
                for (int j=0; j<A.size(); j++) {
                    System.out.printf("Case %d: %d\n", j+1, A.get(j));
                }
                break;
            }
        }
    }
}


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

int main() {
    
    string s;
    long long count = 0;
    cin >> s;
    
    if ( s.length() == 1 ) {
        cout << 0 << endl;
        return 0;
    }
    
    for ( long long l = 1; l < s.length(); l++ ) {
       
        if ( s.substr( l,1 ) != s.substr( l-1, 1 ) ) { count++; }
       
    }
    
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 512
// finish date: 2018/07/23
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, s.length()) mp[s[i]]++;
    int ans = INF;
    for (auto e :mp) {
        char c = e.first;
        rep(i, s.length()) {
            if (s[i] != c) break;
            if(i == s.length()-1){
                cout<<0<<endl;
                return 0;
            }
        }
        int k = 1;
        string prev = s;
        string temp = "";
        int cnt = 0;
        while (true) {
            cnt++;
            temp = "";
            rep(i, prev.length() - 1) {
                if (prev[i] == c || prev[i + 1] == c) {
                    temp += c;
                } else {
                    temp += prev[i];
                }
            }
            prev = temp;
            rep(i, temp.length()) {
                if (temp[i] != c) break;
                if (i == temp.length() - 1) {
                    ans = min(ans, cnt);
                    goto outer;
                }
            }
        }
        outer:;
    }
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	
	if(N%2==0)cout<<N<<endl;
	else cout<<N*2<<endl;
	
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e2 + 10;

int a[N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

int main() {

	int m = read(),n = read(),cnt = 0,flag = true;
	For(i,1,n) a[i] = read(),cnt += a[i] & 1;
	if(n == 1 && m == 1) return printf("%d\n%d\n%d\n",a[1],1,a[1]),0;
	if(n == 1) return printf("%d\n%d\n%d %d\n",a[1],2,a[1] - 1,1),0;

	if(cnt > 2) return puts("Impossible"),0;

	For(i,1,n) if(a[i] & 1) {
		if(cnt == 2) swap(a[1],a[i]);
		if(cnt == 1) swap(a[n],a[i]);
		cnt--;
	}

	For(i,1,n) printf("%d%c",a[i],i == iend ? '\n' : ' ');
	if(a[n] == 1) n--,flag = false;
	printf("%d\n",n);
	For(i,1,n) printf("%d%c",a[i] + (i == 1) - (i == n && flag),i == iend ? '\n' : ' ');

	return 0;
}

Measured memory_bytes: 256
S = str(input())

A = int(S[:2])
B = int(S[2:4])

if A > 0 and A < 13:
    aa = True
else:
    aa = False

if B > 0 and B < 13:
    bb = True
else:
    bb = False

if aa == True and bb == True:
    print('AMBIGUOUS')
elif aa == True and bb == False:
    print('MMYY')
elif aa == False and bb == True:
    print('YYMM')
else:
    print('NA')

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

typedef long long ll;

void solve() {
    int N, a, b;
    cin >> N;
    vector<int> edge[N];
    rep(i, N - 1) {
        cin >> a >> b;
        edge[a - 1].push_back(b - 1);
        edge[b - 1].push_back(a - 1);
    }
    int d[2][N];
    rep(i, 2) rep(j, N) d[i][j] = -1;
    rep(i, 2) {
        d[i][i * (N - 1)] = 0;
        deque<int> q{i * (N - 1)};
        while (!q.empty()) {
            int u = q.front();
            q.pop_front();
            rep(j, edge[u].size()) {
                int v = edge[u][j];
                if (d[i][v] > -1) continue;
                d[i][v] = d[i][u] + 1;
                q.push_back(v);
            }
        }
    }
    int S = 0, F = 0;
    rep(i, N) {
        if (d[0][i] > d[1][i]) S++;
        else F++;
    }
    if (F > S) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
long long l, r;
int main() {
    cin >> l >> r;
    long long ans = 1e+9;
    long long Rmax = min(r, l+2019);
    for(long long i = l; i <= Rmax; ++i) {
        for(long long j = i+1; j <=Rmax; ++j) {
            ans = min(ans, (i%2019)*(j%2019)%2019);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
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)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n, m;
    cin >> n >> m;
    VI h(n);
    REP(i,n) h[i] = in();
    VVI e(n);
    REP(i,m){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int ans = 0;
    REP(i,n){
        bool f = true;
        for (int j : e[i]){
            if (h[i] <= h[j]) f = false;
        }
        ans += f;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int a, b, c; cin >> a >> b >> c;
    cout << (a + b + c >= 22 ? "bust" : "win") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
    static int VMAX=10000;
    public static void main (String args[]){

        //初期処理
//String配列として読みだしてintに変換する方式だとTLEがどうあがいても取れない
//ダメ→int[] array=Arrays.stream(sElementArray).mapToInt(Integer::parseInt).toArray()
//これもダメ→for文でInteger.parseInt()してint[]に変換
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.nextLine());
        int[] array=new int[n];
        for(int o = 0;o<n;o++){
            array[o]=Integer.parseInt(sc.next());
        }
        sc.close();

            int[] B = new int[n+1]; //出力用
            int[] C = new int[VMAX+1]; //カウント用
            int i;

            for(i=0;i<n;i++){
                C[array[i]]++;
            }
            for(i=1;i<=VMAX;i++){
                C[i]+=C[i-1];
            }
            for(i=n-1;i>=0;i--){
                B[C[array[i]]]=array[i];
                C[array[i]]--;
            }

            StringBuffer sb=new StringBuffer();
            for(i=1;i<n;i++){
                sb.append(B[i]).append(" ");
            }
            System.out.println(sb.append(B[n]));
        }
    }
    


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

int main() {
    map<string,int> dat; dat.clear();

    int n; scanf("%d", &n);
    int maxx = 0;
    for (int i=1; i<=n; i++) {
        char s[15]; scanf("%s", s);

        if (dat.find((string)s) == dat.end()) {
            dat[(string)s] = 0;
        }
        dat[(string)s] += 1;

        maxx = max(maxx, dat[(string)s]);
    }

    vector<string> res; res.clear();

    for (auto x: dat) if (x.second == maxx) {
        res.push_back(x.first);
    }

    sort(res.begin(), res.end());

    for (auto x: res) {
        printf("%s\n", x.c_str());
    }
    return 0;
}


Measured memory_bytes: 25584
# B
a, b, k = map(int, input().split())
ans_list = []
for i in range(a, a+k):
    if i <= b:
        ans_list.append(i)
for i in range(b-k+1, b+1):
    if i >= a:
        ans_list.append(i)
ans_list = list(set(ans_list))
ans_list.sort()

for i in ans_list:
    print(i)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC141A
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            if (S == "Sunny")
            {
                Console.WriteLine("Cloudy");
            }
            else if (S == "Cloudy")
            {
                Console.WriteLine("Rainy");
            }
            else
            {
                Console.WriteLine("Sunny");
            }
        }
    }
}


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

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

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll powermod(ll a,ll b,ll m){
	if(b==0){
		return 1LL;
	}
	if(b%2){
		return (a*powermod(a,b-1LL,m))%m;
	}
	return powermod((a*a)%m,b/2LL,m);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N=in();
	string S=in<string>();

	int P=0;
	REP(i,1000){
		int V=i;
		int A,B,C;
		C=V%10,V/=10;
		B=V%10,V/=10;
		A=V;

		int pos=0,find=0;
		for(int j=pos;j<N;j++){
			if(S[j]==(char)('0'+A)){
				pos = j+1;
				find++;
				break;
			}
		}
		for(int j=pos;j<N;j++){
			if(S[j]==(char)('0'+B)){
				pos = j+1;
				find++;
				break;
			}
		}
		for(int j=pos;j<N;j++){
			if(S[j]==(char)('0'+C)){
				pos = j+1;
				find++;
				break;
			}
		}
		if(find==3) P++;
	}
	out(P);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
 
struct Puddle{
    int start, end, area;
};
 
int main(){
    string str;
    cin >> str;
    int n = str.size(), overall = 0;
    stack<Puddle> S;
    stack<int> slope;
 
    for(int i = 0; i < n; i++){
        if(str[i] == '\\'){
            slope.push(i);
        } else if(str[i] == '/'){
            if(!slope.empty()){
                Puddle temp;
                temp.start = slope.top();
                slope.pop();
                temp.end = i;
                temp.area = (temp.end - temp.start);
                overall += temp.area;
                while( !S.empty() ){
                    if(temp.start < S.top().start){
                        temp.area += S.top().area;
                        S.pop();
                    } else {
                        break;
                    }
                }
                S.push(temp);
            }
        }
    }
    cout << overall << endl;
    int m = S.size(), A[m];
    cout << m;
    for(int i = 0; i < m; i++){
        A[m - i - 1] = S.top().area;
        S.pop();
    }
    for(int i = 0; i < m; i++)
        cout << " " << A[i];
    cout << endl;
}

Measured memory_bytes: 1312
#include<stdio.h>
int main(){
int n,m,i,count=0,pos=0;
int me[1000];
int number[1000];

while(1){
scanf("%d %d\n",&n,&m);
if(n==0 && m==0)break;

for(i=0;i<n;i++){
scanf("%d\n",&me[i]);
}
for(i=0;i<m;i++){
scanf("%d\n",&number[i]);
}
for(i=0;i<m;i++){
count++;
pos = pos + number[i];
pos = pos + me[pos];
if(pos>=n) break;
}
printf("%d\n",count);
count=0;
pos=0;
}

return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
inline int readuint(){
    char x;int r=0;
    while(1){x=getchar();if(x>' ')break;}
    while(1){
        r=r*10+x-'0';
        x=getchar();
        if(!isdigit(x))break;
    }
    return r;
}

const int maxn=1e5+9;
int n;
int a[maxn],s[maxn];
int init(){
    n=readuint();
    for(int i=0;i<n;++i)a[i]=readuint();
}

int solve(){
    for(int i=0;i<n;++i)s[i]=-1;
    int c=0;
    for(int i=0;i<n;++i){
        int p=lower_bound(s,s+n,a[i])-s-1;
        if(s[p]==-1)c++;
        s[p]=a[i];
    }
    return c;
}
int main(){
	init();
	cout<<solve()<<endl;
    return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
l = []
sum = 0

for i in range(n):
    array = list(map(int, input().split()))
    l.append(array)

l.sort()

for i, j in l:
    if j >= m:
        sum += i * m
        m = 0
    else:
        sum += i * j
        m -= j
    if m == 0:
        break

print(sum)



Measured memory_bytes: 27760
#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int INF = 0x3f3f3f3f;
const int MAXN = 2550;
struct Node{
    int fr, to, nx; ll dis;
}E[MAXN << 2];
int n, m, p;
int vis[MAXN];
int head[MAXN]; int tot = 0;
ll dis[MAXN];
void add(int fr, int to, int dis) {
    E[tot].fr = fr; E[tot].to = to; E[tot].dis = dis; E[tot].nx = head[fr]; head[fr] = tot ++;
}


bool bellman_ford() {
    for (int i = 0; i <= n; i++) dis[i] = 1e18;  //初始化
    dis[1] = 0;
    bool ok;     
    ll tmp;                                     //判断是否发生了松弛
    for (int i = 1; i <= 2 * n; i++) {
        ok = false;
        for (int j = 0; j < tot; j++) {
            if (dis[E[j].fr] + E[j].dis < dis[E[j].to]) {
                dis[E[j].to] = dis[E[j].fr] + E[j].dis;
                ok = true;
            }
        }
        if (!ok)  //没有发生松弛，及时退出
            break;
        if(i <= n) {
            tmp = dis[n];
        }
    }
    if(dis[n] != tmp) return false; 
    // for (int i = 0; i < tot; i++)                                 //寻找负权回路
    //     if (dis[E[i].fr] + E[i].dis < dis[E[i].to]) return false;  //存在负权回路
    return true;
}

int main() {
    
    while(~scanf("%d %d %d", &n, &m, &p)) {
        tot = 0;
        memset(head, -1, sizeof(head));

        for(int i = 0; i < m; ++i) {
            int a,b,c;
            scanf("%d %d %d", &a, &b, &c);
            add(a, b, -c + p);
        }

        bool suc = bellman_ford();
        if(!suc) printf("-1\n");
        else printf("%lld\n", max(1ll * 0, -dis[n]));
        
    }
    return 0;
}

Measured memory_bytes: 384
import itertools

n, k = [int(i) for i in input().split()]
top, *a = [int(i) for i in input().split()]

ans = float("inf")
for pp in itertools.product((0, 1), repeat=n-1):
    now = top
    v = 1
    cost = 0
    for i, p in enumerate(pp):
        if p == 0:
            if a[i] > now:
                now = a[i]
                v += 1
            continue
        now = max(now+1, a[i])
        cost += max(now-a[i], 0)
        v += 1
    if v >= k:
        ans = min(ans, cost)
print(ans)

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

int main(){
    int n, tmp;
    cin >> n;
    for (int i = 1; i <= n; i++){
        if (i%3 == 0) printf(" %d", i);
        else{
            tmp = i;
            while (tmp != 0){
                if (tmp%10 == 3){
                    printf(" %d", i);
                    break;
                } else{
                    tmp /= 10;
                }
            }
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3200
import sys
input = lambda: sys.stdin.readline().strip()

def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    # A, B, C, X = map(int,open(0))

    cnt = 0
    for i_a in range(min(int(X/500),A)+1):
        X_a = X-500*i_a
        for i_b in range(min(int(X_a/100),B)+1):
            X_b = X_a - 100*i_b
            for i_c in range(min(int(X_b/50),C)+1):
                X_c = X_b - 50*i_c
                if X_c==0:
                    cnt += 1
    print(cnt)

main()


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
    //1200 abc
    //2800 arc
    //agc
    int n;

    cin >> n;
    if(n < 1200)cout << "ABC" << endl;
    if(n >= 1200 && n < 2800)cout << "ARC" << endl;
    if(n >= 2800)cout << "AGC" << endl;

    return 0;

}

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

std::string trim(const std::string& str)
{
    size_t first = str.find_first_not_of(' ');
    if (std::string::npos == first)
    {
        return str;
    }
    size_t last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}



int main(int argc, char* argv[]){
    std::array< std::array< std::array< int, 10 >, 3 >, 4> buildings = {0};
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int build, floor, room, visitor;
        scanf("%d %d %d %d", &build, &floor, &room, &visitor);
        buildings[build-1][floor-1][room-1] += visitor;
    }

    for(int bi = 0; bi < buildings.size(); ++bi){
        for(auto floor: buildings[bi]){
            for(int i = 0; i < floor.size(); ++i){
                printf(" %d", floor[i]);
            }
            printf("\n");
        }
        if(bi != buildings.size()-1) printf("####################\n");
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAXN (2*1000)

int N;
int L[MAXN+5];

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);
	cin >> N;
	FOR(n,N) {
		cin >> L[n];
	}

	sort(&L[0], &L[N]);

	int ans = 0;
	FOR(a,N) {
		for(int b=a+1;b<N; b++) {
			for(int c=b+1; c<N; c++) {
				// DOUT << "L["<<a<<"]="<<L[a]<<", L["<<b<<"]="<<L[b]<<", L["<<c<<"]="<<L[c]<<endl;
				if(L[c]-L[b]>=L[a]) {
					break;
				}
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
inline long long po(int n) {
	long long ans = 1;
	for (int i = 0;i < n;i++) {
		ans *= 2;
	}
	return ans;
}

inline long long bac(vector<bool> ju) {
	long long ans = 0;
	long long di = 1;
	for (int i = 0;i < ju.size();i++) {
		if (ju[i]) {
			ans += di;
		}
		di *= 2;
	}
	return ans;
}

inline void cha(long long n, vector<bool> &ju) {
	for (int i = 0;i < ju.size();i++) {
		ju[i] = n % 2;
		n /= 2;
	}
}

int main() {
	int n;
	cin >> n;
	vector<vector<int> > da(n, vector<int>(n));
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			cin >> da[i][j];
		}
	}
	vector<long long> mo(n);
	mo[0] = 1;
	for (int i = 0;i < n - 1;i++) {
		mo[i + 1] = mo[i] * 2;
	}
	int x = po(n);
	vector<long long> dp(x, 0);
	dp[0] = 1;
	for (long long i = 1;i < x;i++) {
		vector<bool> ju(n);
		cha(i, ju);
		int co = -1;
		long long me = 0, gg = 0;
		for (int j = 0;j < n;j++) {
			if (ju[j]) {
				gg += mo[j];
				co++;
			}
		}
		for (int j = 0;j < n;j++) {
			if (ju[j] & da[co][j]) {
				me += dp[gg-mo[j]];
			}
		}
		dp[i] = me % 1000000007;
	}
	cout << dp[x - 1] << endl;
}


Measured memory_bytes: 16640
N = int(input())

res = 100000

for i in range(N+1):
  cc = 0
  t = i
  while t>0:
    cc += t%6
    t = int(t/6)
  t = N-i
  while t>0:
    cc += t%9
    t = int(t/9)
  if res > cc:
    res = cc

print(res)
  

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

int main()
{
  long long int n,count = 1;
  cin >> n;
  
  if(n == 1)
  {
    cout << 1;
    return 0;
  }
  
  vector<string> s(n);
  for(long long int i = 0; i < n; i++)
  {
    cin >> s[i];
  }
  
  sort(s.begin(),s.end());
  
  for(long long int i = 0; i < n-1; i++)
  {
    if(s[i] != s[i+1])
    {
      count++;
    }
    else
    {
      continue;
    }
  }
  
  cout << count;
  
  return 0;
}

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

int N;
long long K;
int go[200005][62];

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

  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> go[i][0];
  }

  for (int j = 1; j < 62; j++) {
    for (int i = 1; i <= N; i++) {
      go[i][j] = go[go[i][j - 1]][j - 1];
    }
  }

  int cur = 1;
  for (long long j = 0; j < 62; j++) {
    if (K & (1ll << j)) {
      cur = go[cur][j];
    }
  }

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

Measured memory_bytes: 52056
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;
int main(){
  ll n; cin >> n;
  cout << (n<1200 ? "ABC" : (n<2800 ? "ARC" : "AGC"));
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    ll num[100];
    memset(num,0,sizeof(num));
    ll a,b;
    for(int i=0;i<m;i++){
    	cin>>a>>b;
    	num[a]++;
    	num[b]++;
    }
    for(int i=1;i<=n;i++){
    	cout << num[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N, T;
    cin >> N >> T;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    // iで売ったときの利益
    vector<ll> B(N);
    ll min_price = A[0];
    B[0] = 0;
    FOR(i, 1, N){
        min_price = min(min_price, A[i]);
        B[i] = A[i] - min_price;
    }

    sort(ALL(B));
    ll max_profit = B.back();
    ll count = 0;
    for(ll b : B){
        if(b==max_profit){
            count++;
        }
    }

    p(count);
    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int digitSum(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}
int main(){
    int n,a,b;cin>>n>>a>>b;
    ll ans=0;
    rep1(i,n){
        int c=digitSum(i);
        if(c>=a&&c<=b)ans+=i;
    }
    co(ans);
}

Measured memory_bytes: 256
o=->a,n{n<1?1:a**n[0]*o[a,n/2]**2%M}
f=f=1,*(1..M=1000003).map{|i|f=f*i%M}
gets
$<.map{|s|x,d,n=s.split.map &:to_i
p d<1?o[x,n]:(u=f[n+t=x*o[d,M-2]%M-1])?u*o[f[t],M-2]*o[d,n]%M: 0}

Measured memory_bytes: 19452
# -*- coding:utf-8 -*-
H,W=map(int,input().split())
nx=[1,0,-1,0]
ny=[0,1,0,-1]

field=[]
for i in range(H):
  field.append(list(input()))

for n in range(W):
  for m in range(H):
    if field[m][n]=='.':
      continue
    
    hope=0
    for j in range(4):
      x=n+nx[j]
      y=m+ny[j]
      
      if x<0 or W<=x or y<0 or H<=y:
        continue

      if field[y][x]=='#':
        hope=1
      
    if hope==0:
      print('No')
      exit()

print('Yes')

Measured memory_bytes: 3064
std_n = int(input())
std_list = tuple(map(int, input().split()))
std_set = set(std_list)

if std_set == {0}:
    print("Yes")
    exit()
elif len(std_set) == 2:
    if 0 in std_set:
        if std_list.count(0) * 3 == std_n:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
elif len(std_set) == 3:
    a, b, c = tuple(std_set)
    if (std_list.count(a) == std_list.count(b)) and (std_list.count(b) == std_list.count(c)):
        if a ^ b == c:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
else:
    print("No")
    exit()


Measured memory_bytes: 15108
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, m; cin >> n >> m;
    cout << (1900 * m + 100 * (n - m)) * (1<<m) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  ll dp[10][10] = {};
  int n;
  cin >> n;
  FOR(i, 1, n + 1) {
    int matu = i % 10;
    int tmp = i;
    while (tmp >= 10) {
      tmp /= 10;
    }
    int front = tmp;
    dp[front][matu]++;
  }

  ll ans = 0;
  FOR(i, 1, n + 1) {
    int front = i % 10;
    int tmp = i;
    while (tmp >= 10) {
      tmp /= 10;
    }
    int matu = tmp;
    ans += dp[front][matu];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
    int x1,x2,luas,luas1;
    scanf("%d %d", &x1,&x2);
    luas=x1*x2;
    luas1=(x1+x2)*2;
    printf("%d %d\n",luas,luas1);
    
    return 0;
}


Measured memory_bytes: 2608
N=int(input())
a=list(map(int,input().split()))

d = [0]*(10**5+1)
for i in range(N):
  d[a[i]]+=1

ans=0
for i in range(10**5):
  ans = max(ans, d[i-1]+d[i]+d[i+1])

print(ans)

Measured memory_bytes: 20808
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;

const int N=5050;
int n, a, b, p[N];
s64 f[N];
int main() {
	n=rd(), a=rd(), b=rd();
	for(int i=1; i<=n; ++i) p[i]=rd();
	p[n+1]=n+1;
	for(int i=1; i<=n+1; ++i) {
		s64 sum=0;
		f[i]=1e18;
		for(int j=i; j--; ) {
			if(p[j]<p[i]) cmin(f[i], f[j]+sum);
			sum+=p[j]<p[i]?b:a;
		}
	}
	printf("%lld\n", f[n+1]);
	return 0;
}


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

string n;
int digitsum = 0;

int main() {
  cin >> n;
  rep (i, n.size()) {
    digitsum += n[i] - '0';
  }
  cout << (digitsum%9 == 0 ? "Yes" : "No") << endl;
  return 0;
}


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

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            if (s[0] != 'A')
            {
                Console.WriteLine("WA");
                return;
            }

            var cCount = 0;
            var cPos = -1;
            for (var i = 2; i < s.Length - 1; i++)
            {
                if (s[i] == 'C')
                {
                    cCount++;
                    cPos = i;
                }
            }
            if (cCount != 1)
            {
                Console.WriteLine("WA");
                return;
            }

            for (var i = 0; i < s.Length; i++)
            {
                if (i == 0 || i == cPos) continue;
                if (!Char.IsLower(s[i]))
                {
                    Console.WriteLine("WA");
                    return;
                }
            }

            Console.WriteLine("AC");
        }
    }
}


Measured memory_bytes: 25892
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);

int main(){
  int n;
  cin >>n;
  vector<string>s(n);
  rep(i,n)cin >> s[i];
  
  ll ans=0;
  rep(k,n){
    vector<string>t(n,string(n,' '));
    rep(i,n){
      rep(j,n){
        t[i][(j+k)%n]=s[i][j];
      }
    }
    bool ok=true;
    rep(i,n){
      rep(j,n){
        if(t[i][j]!=t[j][i])ok=false;
      }
    }
    if(ok)ans++;
  }
  cout << ans*n << endl;
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int main()
{
    int N,i,j,k;
    scanf("%d",&N);

    long long int a[N];
    for(i=0; i<N; i++)
    {
        scanf("%lld",&a[i]);
    }
    int sum=0;

    for(i=0; i<N; i++)
    {
        for(j=i+1; j<N; j++)
        {
            for(k=j+1; k<N; k++)
            {
                if((a[i]+a[j]>a[k])&&( a[j]+a[k]>a[i]) && (a[k]+a[i]>a[j])&& a[i]!=a[j]&& a[j]!=a[k] && a[k]!=a[i])
                {
                    sum++;
                }
            }
        }
    }
    printf("%d\n",sum);


    return 0;

}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}

void solve(){
    string s;
    cin >> s;
    ll l = 0;
    ll ans = 0;
    fo(i, 3){
        if(s[i] == 'R')l++;
        else{
            ans = max(l, ans);
            l = 0;
        }
    }
    ans = max(ans, l);
    ANS;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    //pre();
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

int main(){
  string s,t;
  cin>>s;
  cin>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  if(s<t) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int A[][] = new int[H][W];
		int x[] = new int[H * W];
		int y[] = new int[H * W];
		int ans[] = new int[H * W];
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				A[i][j] = Integer.parseInt(sc.next()) - 1;
				x[A[i][j]] = j;
				y[A[i][j]] = i;
			}
		}
		int Q = Integer.parseInt(sc.next());
		int L[] = new int[Q];
		int R[] = new int[Q];
		for(int i = 0; i < Q; i++) {
			L[i] = Integer.parseInt(sc.next()) - 1;
			R[i] = Integer.parseInt(sc.next()) - 1;
		}
		
		for(int i = 0; i < D; i++) {
			int now = i;
			while(now < H * W - D) {
				ans[now + D] = Math.abs(x[now] - x[now + D]) + Math.abs(y[now] - y[now + D]) + ans[now];
				//System.out.println(ans[now]);
				now += D;
			}
		}
		
		for(int i = 0; i < Q; i++) {
			System.out.println(ans[R[i]] - ans[L[i]]);
		}
	}
}


Measured memory_bytes: 70796
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,i,s,d;
    scanf("%d",&a);
    b=a%10;
    a=a/10;
    c=a%10;
    a=a/10;
    d=a%10;
    if(b==7||c==7||d==7)
    {
        printf("Yes\n");
    }
    else printf("No\n");
}

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

int main(){
    int n,a[101];
    cin>>n;
    for(int t=0;t<n;t++)cin>>a[t];
    sort(a,a+n);

    int cont=1;
    for(int t=1;t<n;t++){
        if(a[t-1]!=a[t])cont++;
    }
    cout<<cont<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mk make_pair
#define f first
#define s second
using namespace std;
int n,m,p1,p2;
map<pair<int,pair<int,int> >,int >m1;

vector<pair<int,int> >v;

int dfs(int d,int h,int w){
  int res=0;
  if(m1[mk(d,mk(h,w))])return m1[mk(d,mk(h,w))];
  if(d==v.size()) return 0;
  if(v[d].f<h&&v[d].s<w)
    res=max(res,dfs(d+1,v[d].f,v[d].s))+1;
  res=max(res,dfs(d+1,h,w));
  return m1[mk(d,mk(h,w))]=res;
}

main(){
  while(cin>>n,n){
    m1.clear();
    v.clear();
    for(int i=0;i<n;i++){
      cin>>p1>>p2;
      v.push_back(mk(p2,p1));
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>p1>>p2;
      v.push_back(mk(p2,p1));
    }
    stable_sort(v.begin(),v.end(),greater<pair<int,int> >());
    for(int i=0;i<v.size();i++)swap(v[i].f,v[i].s);
    stable_sort(v.begin(),v.end(),greater<pair<int,int> >());
    cout<<dfs(0,1001,1001)<<endl;
  }
}

Measured memory_bytes: 3872
#include <cstdio>
#include <iostream>

using namespace std;

typedef unsigned long long ullong;

ullong power(ullong m, ullong n, ullong M) {
	ullong res = 1;
	if (n > 0) {
		res = power(m, n / 2, M);
		if (n % 2 == 0) {
			res = (res * res) % M;
		} else {
			res = (((res * res) % M) * m) % M;
		}
	}
	return res;
}

int main() {

	int m, n;
	scanf("%d %d", &m, &n);

	cout << power(m, n, 1000000007) << endl;

	return 0;
}

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

using namespace std;
class CReplacingInteger {
public:
	void solve(std::istream& in, std::ostream& out) {
	    long long int N = 0;
	    long long int K = 0;
	    in >> N >> K;

	    long long int div = N / K;
	    long long int res1 = llabs(N - (div * K));
	    long long int res2 = llabs(N - (div * K) - K);
	    out << min(res1, res2) << endl;
	}
};


int main() {
	CReplacingInteger solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
    int n;
    cin>>n;
    string ans;
    rep(i,64){
        if(n==0)break;
        if(n%2==1){
            ans+="1";
            if(i%2)n+=1;
            n/=2;
        }else if(n%2==-1){
            ans+="1";
            if(i%2==0)n-=1;
            n/=2;
        }else{
            ans+="0";
            n/=2;
        }
    }
    if(ans=="")ans="0";
    reverse(all(ans));
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

inf = float("inf")


def count(S):
    ret = 0
    for s in S:
        if s in 'AGCT':
            ret += 1
        else:
            return 0
    return ret

def main():
    S = input()
    length = len(S)
    ret = 0
    
    for i in range(length):
        if i == 0:
            ret = count(S)
        else:
            for j in range(i+1):
                _S = S[j:length-(i-j)]        
                ret = max(ret, count(_S))
                
    print(ret)
        
      
if __name__=='__main__':
    main()

Measured memory_bytes: 40336