akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
vector<ll> a;

bool isOK(int index, int key) {
	if (a[index] > key) return true;
	else return false;
}

int binary_search(int key,ll i) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = i; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}


int main() {

	ll N,an=0;
	cin >> N;
	a.resize(N);
	rep(i, N) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	for (ll i = 1; i < N; i++) {
		for (ll j = i + 1; j < N; j++) {
			an +=i-binary_search(a.at(j) - a.at(i),ll(i));
		}
	}
	cout << an << endl;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long llong;

int N;
llong v_list[100001];
double tripartition;
	
inline llong searchOne(int n0, int n1_left, int n2_left);
inline llong getMinV(int n0, int n1_left, int n2_left);
inline int findIndexBinary(int from_n, int to_n, double target);
inline int findIndexSequential(int from_n, double target);

int main(){
	scanf("%lld", &N);
	v_list[0] = 0;
	llong A;
	for(int n=1; n<N+1; n++){
		scanf("%lld", &A);
		v_list[n] = v_list[n-1] + A;
	}

	tripartition = v_list[N] / 3.0;
	int n0_max = findIndexBinary(0, N, tripartition);
	int n1_left = n0_max;
	int	n2_left = findIndexBinary(n1_left, N,  2*tripartition);
	llong maxV = searchOne(0, n1_left, n2_left);
	for (int n0 = 1; n0 <= n0_max; n0++){
		n1_left = findIndexSequential(n1_left,   tripartition + v_list[n0]);
		n2_left = findIndexSequential(n2_left, 2*tripartition + v_list[n0]);
		
		llong tmp = searchOne(n0, n1_left, n2_left);
		if (tmp > maxV) maxV = tmp;
	}

	printf("%lld\n", maxV);
}

llong searchOne(int n0, int n1_left, int n2_left){
	llong V_ll = getMinV(n0, n1_left  , n2_left  );
	llong V_lr = getMinV(n0, n1_left  , n2_left+1);
	llong V_rl = getMinV(n0, n1_left+1, n2_left  );
	llong V_rr = getMinV(n0, n1_left+1, n2_left+1);
	return max( max(V_ll,V_lr), max(V_rl, V_rr));
}

llong getMinV(int n0, int n1, int n2){
	llong V0 = v_list[n1] - v_list[n0];
	llong V1 = v_list[n2] - v_list[n1];
	llong V2 = v_list[n0] - v_list[n2] + v_list[N];
	return min(min(V0,V1),V2);
}

int findIndexBinary(int from_n, int to_n, double target){
	while (to_n - from_n != 1) {
		int n_mid = (to_n + from_n) / 2;
		if (v_list[n_mid] > target) to_n = n_mid;
		else from_n = n_mid;
	}
	return from_n;
}

int findIndexSequential(int from_n, double target){
	for(int n=from_n; n<= N; n++)if(v_list[n] > target) return n-1;
	return N-1;
}

Measured memory_bytes: 1784
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int[] a = new int[3];
		int[] b = new int[3];
		for (int i = 0; i < 3; ++i) {
			String[] tokens = in.nextLine().split(" ");
			a[i] = Integer.parseInt(tokens[0]);
			b[i] = Integer.parseInt(tokens[1]);
		}
		in.close();
		int[] counts = new int[4];
		Arrays.fill(counts, 0);
		for (int i = 0; i < 3; ++i) {
			counts[a[i] - 1]++;
			counts[b[i] - 1]++;
		}
		int ones = 0;
		int twos = 0;
		for (int i = 0; i < 4; ++i) {
			if (counts[i] == 1) {
				ones++;
			} else if (counts[i] == 2) {
				twos++;
			}
		}
		if (ones == 2 && twos == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}

Measured memory_bytes: 23124
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

#define GREAT "GREATER"
#define LESS "LESS"
#define EQUAL "EQUAL"

int main(void)
{
	string A, B;
	cin >> A >> B;
	
	string ret;
	if(A.size() > B.size())
		ret = GREAT;
	else if(A.size() < B.size())
		ret = LESS;
	else
	{
		if(A > B)
			ret = GREAT;
		else if(A < B)
			ret = LESS;
		else
			ret = EQUAL;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
from fractions import gcd

n=int(input())
a=list(map(int,input().split()))

li=[0]*(n+1)
ri=[0]*(n+1)

for i in range(n):
    li[i+1]=gcd(li[i], a[i])
for i in range(n-1, -1, -1):
    ri[i]=gcd(ri[i+1], a[i])

ans=0

for i in range(n):
    ans=max(gcd(li[i], ri[i+1]),ans)
ans=max(ans, li[-1])
print(ans)

Measured memory_bytes: 16120
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int h,w,n;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d%d%d",&h,&w,&n);

	if(h>w) swap(h,w);

	printf("%d\n", n%w ? n/w+1 : n/w );

	return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int a, b, c, x, k;
	scanf("%d %d", &k, &x);
	int ans = 0;
	for(int i = 0; i <= k; i++) {
		for(int j = 0; j <= k; j++) {
			if((x - i - j) <= k && (x - i - j) >= 0) {
				ans++;
			}
			else continue;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
    int a[5],k;
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;

    sort(a,a + 3);
    for(int i=0;i<k;++i) a[2] *= 2;
    int sum = a[0] + a[1] + a[2];

    cout << sum << endl;
}





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

class Main{
	static int last;
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();//1日目から最大を取っていくのはありがちな貪欲の嘘解法っぽい	→　やっぱりそうだった1WA
		int[][] vc=new int[N][3];
		for(int i=0; i<N; i++) {
			for(int j=0; j<3; j++) {
				vc[i][j]=sc.nextInt();
			}
		}
		int[][] dp=new int[N][3];
		dp[0][0]=vc[0][0];
		dp[0][1]=vc[0][1];
		dp[0][2]=vc[0][2];
		for(int i=1; i<N; i++) {
			dp[i][0]=Math.max(dp[i][0], Math.max(dp[i-1][1]+vc[i][0],dp[i-1][2]+vc[i][0]));
			dp[i][1]=Math.max(dp[i][1], Math.max(dp[i-1][0]+vc[i][1],dp[i-1][2]+vc[i][1]));
			dp[i][2]=Math.max(dp[i][2], Math.max(dp[i-1][0]+vc[i][2],dp[i-1][1]+vc[i][2]));
		}
		pl(Math.max(Math.max(dp[N-1][0], dp[N-1][1]), Math.max(dp[N-1][1], dp[N-1][2])));
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 50400
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] c = new int[n];
        int[] s = new int[n];
        int[] f = new int[n];
        for (int i = 0; i < n - 1; i++) {
            c[i] = sc.nextInt();
            s[i] = sc.nextInt();
            f[i] = sc.nextInt();
        }

        int[] ans = new int[n];
        for (int i = 0; i < n - 1; i++) {
            ans[i] = c[i] + s[i];
            for (int j = i + 1; j < n - 1; j++) {
                int startTime = s[j];
                while (ans[i] > startTime) {
                    startTime += f[j];
                }
                ans[i] = c[j] + startTime;
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.println(ans[i]);
        }
    }

}


Measured memory_bytes: 25856
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;
#define PI 3.14159265

void solve()
{
	int n;
	int a,b,x;
	cin>>a>>b>>x;
	long double a1 = a;
	long double b1 = b;
	long double x1 = x;
	long double h = 2*x1;
	if((a1*a1*b1)/2.0 >= x1){
		h/=(a1*b1);
		h/=b1;
	}
	else{
		// _h
		long double p =  2.0*(x1/a1) - (a1*b1);
		p/=a1;
		h = a1/(b1-p);
	}
	// tr(h/b1);
	// h = 
	cout<<setprecision(20)<<90-atan(h)*180/PI<<endl;
	// cout<<setprecision(20)<<atan(h/b1)<<endl;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;

}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string tarou,hanako;
  cin>>n;
  int t=0,h=0;
  for(int i=0;i<n;i++){
    cin>>tarou>>hanako;
    if(tarou>hanako) t+=3;
    else if(hanako>tarou) h+=3;
    else{
      t++;
      h++;
    }
  }
  cout<<t<<" "<<h<<endl;
  return 0;
}
    



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  string o,e;cin>>o>>e;
  rep(i,o.size()){
    cout<<o[i];
    if(o.size()-e.size()==0||(o.size()-e.size()==1&&i!=o.size()-1))cout<<e[i];
  }
  cout<<endl;
    return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int64 A, B; 

int main()
{
	scanf("%lld%lld", &A, &B);
	int p = 60;
	if (A == B)
	{
		puts("1");
		return 0;
	}
	while (!((A ^ B) & (1LL << p))) --p;
	int q = p - 1;
	while ((~q) && !(B & (1LL << q))) --q;
	int64 x = (1LL << p) - (A & ((1LL << p) - 1));
	int64 yl = (1LL << p), yr = (1LL << p) + (1LL << (q + 1));
	int64 zl = (1LL << p) + (A & ((1LL << p) - 1)), zr = 2 * (1LL << p);
	int64 ans = x + yr - yl + zr - zl;
	if (zl <= yr)
		ans -= yr - zl;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int a,b;cin>>a>>b;
	if(b%a==0) cout<<a+b<<endl;else cout<<b-a<<endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict

INF = sys.maxsize

N, X, Y = map(int, input().split())

# インデックスと合わせる
X -= 1
Y -= 1

distance = [[INF] * N for _ in range(N)]

for i in range(N):
    for j in range(N):
        # X,Y を経由しない場合とする場合の小さい方
        distance[i][j] = distance[i][j] = min(
            abs(i - j),
            abs(i - X) + abs(j - Y) + 1,
            abs(i - Y) + abs(j - X) + 1
        )

counter = defaultdict(int)

for i in range(N):
    for j in range(N):
        counter[distance[i][j]] += 1

for k in range(1, N):
    print(counter[k] // 2)


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

int main()
{
  int n, k;
  cin >> n >> k;
  double ans(0);

  for (int i = 1; i <= n; i++) {
    double p = 1.0 / n;
    for (int x = i; x < k; x *= 2) {
      p *= 0.5;
    }
    ans += p;
  }
  printf("%.12f\n", ans);
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		for(;;){
			String input = scan.next();
			if(input.equals("-")){
				break;
			}
			int m = scan.nextInt();
			int len = input.length();
			String output = input;
			List<Character> listC = new LinkedList<Character>();
			for(int i = 0; i < len; i++){
				char c = output.charAt(i);
				listC.add(c);
			}
			for(int i = 0; i < m; i++){
				int h = scan.nextInt();
				for(int j = 0; j < h; j++){
					char c = listC.get(0);
					listC.remove(0);
					listC.add(c);
				}
			}
			for(char c : listC){
				System.out.print(c);
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 26312
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

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

	string s;
	cin >> s;
	char z = '0';
	int m = (s[5]-z)*10 + s[6]-z;
	int d = (s[8]-z) * 10 + s[9]-z;

	string ans = "Heisei";
	if (m == 4 && d == 30) {
		ans = "Heisei";
	}
	else if (m >= 5) {
		ans = "TBD";
	}
	cout <<ans << endl;
	
	

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;
const int N = 1e5+5;
int A[N];
int n,k;
int dp[N];

int solve(int i){
	if(i==n-1) return 0;
	if(i>=n) return INT_MAX;
	int a=INT_MAX,b=INT_MAX;
	if(dp[i]!=-1) return dp[i];
	for(int j=1;j<=k;j++){
		if(i+j<n)
		a = min(a, abs(A[i]-A[i+j]) +solve(i+j) ); 
	}
	return dp[i]=a;
	
}

int32_t main()
{
   
   
    crap;
    memset(dp,-1,sizeof(dp));
        cin>>n>>k;
        for(int i=0;i<n;i++) cin>>A[i];

    int ans = solve(0);
	cout<<ans<<endl;
   
   
   
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (i % 2 && x % 2) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var A = GetLongs(N);

		var dp = new long[N, 2];
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < 2; j++)
				dp[i, j] = long.MinValue / 2;
		}
		dp[0, 0] = 0;
		for(int i = 0; i < N - 1; i++)
		{
			for(int j = 0; j < 2; j++)
			{
				for(int k = 0; k < 2; k++)
				{
					long sign = ((j ^ k) == 0) ? 1 : -1;
					chmax(ref dp[i + 1, k], dp[i, j] + sign * A[i]);
				}
			}
		}

		WriteLine(Max(dp[N - 1, 0] + A[N - 1], dp[N - 1, 1] - A[N - 1]));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 31836
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i = 0; i< S.size(); i++){
    cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  int count = 1;
  string x = S.at(0);
  int i = 1;
  bool b = true;
  while(i < S.size()){
    if(x !=S.at(i)) {
      if (i == N-1){
      count++;
      b = false;
    }
    else{
      count++;
      x = S.at(i);
    }      
    }
    if(b ==false)break;
    else i++;
  }
      cout << count << endl;
  }



Measured memory_bytes: 9492
# n=3より10**nの全て回しても大した計算量にならない.
def main():
    n,m=map(int,input().split())
    L=[list(map(int,input().split())) for _ in range(m)]
    for i in range(10**n):
        k = str(i)
       # allは左から数えて s_i桁目は c_i という条件を全て満たすときTrue
        if len(k)==n and all(k[s-1]==str(c) for s, c in L):
            print(i)
            return
    print(-1)
main()

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

int main(){
	long long a,b,x,l,r,res=0;
	cin>>a>>b>>x;
	l=(a%x)?(a/x+1)*x:a;
	r=(b%x)?b/x*x:b;
	if(r<l)cout<<0<<endl;
	else cout<<(r-l)/x+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mar[100000];
int n,m;
void f(vector< int >a[],int u)
{
    mar[u]=1;
    vector <int> :: iterator it,ip;
    for(it=a[u].begin();it!=a[u].end();it++)
    {
        if(mar[*it]==0)
        {
            mar[*it]=1;
            f(a,*it);
        }
    }
}
int main()
{
    cin >> n >> m;
    vector <int> a[n+1];
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    f(a,1);
    int c=0;
    for(int i=1;i<=n;i++)
    {
        if(mar[i]==0)
        {
            c++;
            f(a,i);
        }
    }
    cout <<  c << endl;
}


Measured memory_bytes: 10356
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, S: str):
    abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    print("".join([abc[(abc.index(c)+N) % 26] for c in S]))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()


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

#define fi first
#define se second

const int N = 220;
const long long mod = 1e9 + 7;

using namespace std;

int main()
{
        ios_base::sync_with_stdio(0);

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

        int T;
        cin >> T;
        while(T--){
                int n;
                cin >> n;
                string s;
                vector < long long > a(n);
                for(int i = 0; i < n; i++){
                        cin >> a[i];
                }
                cin >> s;
                int res = 0;
                vector < long long > base(61, 0);
                for(int i = n - 1; i >= 0; i--){
                        if(s[i] == '0'){
                                for(int j = 0; j < 61; j++){
                                        if((a[i] >> j) & 1){
                                                if(base[j] == 0){
                                                        base[j] = a[i];
                                                        break;
                                                }
                                                a[i] ^= base[j];
                                        }
                                }
                        } else{
                                for(int j = 0; j < 61; j++){
                                        if((a[i] >> j) & 1){
                                                a[i] ^= base[j];
                                        }
                                }
                                if(a[i]){
                                        res = 1;
                                }
                        }
                }
                cout << res << "\n";
        }
}


Measured memory_bytes: 3660
nums = input()
nums = nums.split()
taka_hp = int(nums[0])
taka_pw = int(nums[1])
aoki_hp = int(nums[2])
aoki_pw = int(nums[3])

for i in range(0,200):
  if i%2 == 0 :
    aoki_hp -= taka_pw
  elif i%2 !=0:
    taka_hp -= aoki_pw
  if taka_hp <= 0:
    print("No")
    break
  elif aoki_hp <= 0:
    print("Yes")
    break

Measured memory_bytes: 9132
#include<iostream>
#include<stack>
using namespace std;
string str;

bool solve(){
  stack<char> st;
  for(int i=0;i<(int)str.size();i++){
    if(str[i]=='(')st.push(str[i]);
    else if(str[i]=='[')st.push(str[i]);
    else if(str[i]==')'){
      if(st.empty())return false;
      if(st.top()!='(')return false;
      st.pop();
    }else if(str[i]==']'){
      if(st.empty())return false;
      if(st.top()!='[')return false;
      st.pop();
    }
  }
  return st.empty();
}

int main(){
  while(1){
    getline(cin,str);
    if(str==".")break;
    if(solve())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    rep(i, s.length() - 6)
    {
        if (s.substr(i, 7) == "keyence")
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    for (int i = 1; i <= 6; i++)
    {
        string str1, str2, ans;
        str1 = s.substr(0, i);
        str2 = s.substr(s.length() - 7 + i, 7 - i);
        ans = str1 + str2;
        if (ans == "keyence")
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


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

int qmax(int a, int b){
	return (a > b) ? a : b; 
}

int n, m;
int dist[20][20];
int cost[33000];
int dp[20][33000];

int main(){
	scanf("%d %d", &n, &m);
	memset(dist, 0, sizeof(dist));
	rep(i, m){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		a--, b--;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	rep(mask, 1 << n){
		cost[mask] = 0;
		rep(i, n){
			if(!(mask & (1 << i))) continue;
			rep(j, i){
				if(!(mask & (1 << j))) continue;
				cost[mask] += dist[i][j];
			}
		}
	}
	int S = (1 << n) - 1;
	memset(dp, 0xc0, sizeof(dp));
	rep(mask, (1 << n)){
		if((mask & 1) && !(mask & (1 << (n-1)))){
			dp[0][mask] = cost[mask];
		}
	}
	rep(mask, (1 << n)){
		int rest_mask = S - mask;
		rep(i, n){
			if(dp[i][mask] < 0) continue;
			for(int add_mask = rest_mask; add_mask >= 0; add_mask = (add_mask - 1) & rest_mask){
				rep(j, n){
					if(!(add_mask & (1 << j))) continue;
					if(dist[i][j] > 0) dp[j][mask | add_mask] = qmax(dp[j][mask | add_mask], dp[i][mask] + dist[i][j] + cost[add_mask]);
				}
				if(add_mask == 0) break;
			}
		}
	}
	int ans = 0;
	rep(mask, 1 << n){
		ans = qmax(ans, dp[n-1][mask]);
	}
/*	rep(i, n){
		rep(mask, (1 << n)){
			cout << i << " "; 
			rep(j, n) cout << ((mask >> j) & 1);
			cout << " " << dp[i][mask] << endl;
		} 
	}*/
	cout << (cost[S] - ans) << endl;
	return 0;
} 

Measured memory_bytes: 3072
#include<stdio.h>
int main(){
    int a,b,c,d,e;
    scanf("%d%d%d",&a,&b,&c);
    d=b-a;
    e=c-b;
    if(d==e){
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String args []){
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        int [] X = new int[N];
        int [] Y = new int[N];
        double sum = 0;
        int time = 1;
        int n =1;
        for(int i=N-1;i>0;i--) time*=i;
        for(int i=N;i>0;i--) n*=i;
        time*=2;
        for(int i=0;i<N;i++){
            X[i] = sc.nextInt();
            Y[i] = sc.nextInt();
        }
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                double x = Math.pow(X[i]-X[j],2);
                double y = Math.pow(Y[i]-Y[j],2);
                double dis = Math.sqrt(x+y)*time;
                sum+=dis;
            }
        }
        sum/=n;
        System.out.println(sum);
    }
}

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

int n;
int a[6000];
vector<vector<lint> > v;
lint &at(int l, int r)
{
	return v[l][r - l];
}

lint calc(int l, int r)
{
	int i = (r - l) - 1;
	if (i == n) return at(l, r) = 0;
	if (~at(l, r)) return at(l, r);
	
	if (i & 1){
		if (a[l] > a[r]) return at(l, r) = calc(l - 1, r);
		else return at(l, r) = calc(l, r + 1);
	}
	else {
		return at(l, r) = max(a[l] + calc(l - 1, r), a[r] + calc(l, r + 1));
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		a[i + n] = a[i];
		a[i + n * 2] = a[i];
	}
	
	v.resize(n * 3);
	for (int i = 0; i < n * 3; i++){
		v[i].assign(n * 3 - i, -1);
	}
	
	lint res = 0;
	for (int i = 0; i < n; i++){
		lint r = a[i] + calc(i + n - 1, i + n + 1);
		res = max(res, r);
	}
	
	cout << res << endl;
	
	return 0;
}

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

using namespace std;

int main(){
          int N;
	cin>>N;
if(N==1)
 cout<<1<<endl;
else if(N==2)
 cout<<2<<endl;
else if(N==3)
 cout<<4<<endl;
else if(N==4)
 cout<<6<<endl;
else if(N==5)
 cout<<16<<endl;
else if(N==6)
 cout<<12<<endl;
else if(N==7)
 cout<<64<<endl;
else if(N==8)
 cout<<24<<endl;
else if(N==9)
 cout<<36<<endl;
else if(N==10)
 cout<<48<<endl;
else if(N==11)
 cout<<1024<<endl;
else if(N==12)
 cout<<60<<endl;
}


Measured memory_bytes: 3080
n, m, c = map(int,input().split())
B = list(map(int,input().split()))

A = [list(map(int,input().split())) for i in range(n)]
co = 0
for i in range(n) :
    ans = 0
    for j in range(m):
        ans += A[i][j] * B[j]
    if ans + c > 0 :
        co += 1
print(co)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define stp setprecision(15)
#define eps 0.000001
#define endl '\n'
#define ll lli
 
using namespace std ;
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define N 2000000

int main() 
{ 

/////////////////////////////////////
    
    fastio;

    lli n;
    cin>>n;

    lld a[n];

    loopl(i,0,n) cin>>a[i];

    sort(a,a+n);

    lld sum=a[0];

    loopl(i,1,n)
    {
        sum += a[i];
        sum/=2;
    }

    cout<<fixed<<stp<<sum<<endl;

} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cou=0;
  bool f=false;
  cin>>n;
  const int N=n;
  int d[N][2];
  for(int i=0;i<n;i++){
    cin>>d[i][0]>>d[i][1];
    if(d[i][0]==d[i][1])cou+=1;
    else cou=0;
    if(cou==3)f=true;
  }
  if(f)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 3636
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)

typedef pair<int, int> pii;

#define fi first
#define se second

const int inf = 1e9;

#define NR 101000

vector<int> e[NR];
pii f[NR];
int root, dep[NR], a[NR], n, K;

int abs(int x) { return x > 0 ? x : -x; }

pii dfs(int x, int fa) {
	if (a[x] != -1 && abs(a[x] - a[root]) % 2 != dep[x] % 2) {
		return pii(0, -1);
	}

	int l = -inf, r = inf;

	if (a[x] != -1) l = r = a[x];

	for (int v : e[x]) if (v != fa) {
		dep[v] = dep[x] + 1;
		pii tmp = dfs(v, x);
		if (tmp.fi > tmp.se) return pii(0, -1);
		l = max(l, tmp.fi - 1);
		r = min(r, tmp.se + 1);
	}

	return f[x] = pii(l, r);
}

void dfs1(int x, int fa, int t) {
	if (a[x] == -1) {
		if (f[x].fi <= t - 1 && t - 1 <= f[x].se) a[x] = t - 1;
		else a[x] = t + 1;
	}
	for (int v : e[x]) if (v != fa) dfs1(v, x, a[x]);
}

int main() {
	scanf("%d", &n);
	iter(i, n - 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y);
		e[y].push_back(x);		
	}
	scanf("%d", &K);
	memset(a, -1, sizeof(a));
	iter(i, K) {
		int x, y;
		scanf("%d%d", &x, &y);
		a[x] = y;
		root = x;
	}
	pii tmp = dfs(root, 0);
	if (tmp.fi > tmp.se) puts("No");
	else {
		puts("Yes");
		dfs1(root, 0, -1);
		iter(i, n) printf("%d\n", a[i]);
	}
	return 0;
}


Measured memory_bytes: 15744
n = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

ans = 1
B = [0,0,0]
for i in range(n):
    # print(B)
    ans = (ans * B.count(A[i])) % mod
    for j in range(3):
        if B[j] == A[i]:
            B[j] += 1
            break
    if ans == 0:
        break
print(ans)


Measured memory_bytes: 53644
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key))sum++;
  }
  printf("%d\n", sum);
  return 0;
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

struct edge {
	int to, length, data;
};

int N, M, S, T, U, V, D;
ll dis[100000], e[200000], t[100000], rt[100000], rdis[100000], res;
vector<edge>vec[100000];
priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>, greater<pair<ll, pair<int, int>>>>q;

int main(){
	cin >> N >> M >> S >> T;
	--S;
	--T;
	for (int i = 0; i < M; ++i) {
		cin >> U >> V >> D;
		--U;
		--V;
		vec[U].push_back({ V,D,i });
		vec[V].push_back({ U,D,i });
	}
	for (int i = 0; i < N; ++i) {
		dis[i] = rdis[i] = llmax;
	}
	t[S] = 1;
	q.push(mkp(0, mkp(S, S)));
	while (!q.empty()) {
		ll d = q.top().first;
		int to = q.top().second.first, from = q.top().second.second;
		q.pop();
		if (dis[to] == llmax) {
			t[to] = t[from];
			dis[to] = d;
			for (edge u : vec[to]) {
				if (dis[u.to] == llmax) {
					q.push(mkp(d + u.length, mkp(u.to, to)));
				}
			}
		}
		else if (dis[to] == d) {
			t[to] = (t[to] + t[from]) % mod;
		}
	}
	for (int i = 0; i < N; ++i) {
		for (edge u : vec[i]) {
			if (dis[i] + u.length == dis[u.to]) {
				e[u.data] = t[i];
			}
		}
	}
	rt[T] = 1;
	q.push(mkp(0, mkp(T, T)));
	while (!q.empty()) {
		ll d = q.top().first;
		int to = q.top().second.first, from = q.top().second.second;
		q.pop();
		if (rdis[to] == llmax) {
			rt[to] = rt[from];
			rdis[to] = d;
			for (edge u : vec[to]) {
				if (rdis[u.to] == llmax) {
					q.push(mkp(d + u.length, mkp(u.to, to)));
				}
			}
		}
		else if (rdis[to] == d) {
			rt[to] = (rt[to] + rt[from]) % mod;
		}
	}
	res = t[T] * rt[S] % mod;
	for (int i = 0; i < N; ++i) {
		if (dis[i] + rdis[i] != dis[T])continue;
		if (dis[i] * 2 == dis[T]) {
			res = (res + mod - t[i] * rt[i] % mod * t[i] % mod*rt[i] % mod) % mod;
		}
		for (edge u : vec[i]) {
			if (rdis[i] + u.length == rdis[u.to]) {
				if (rdis[i] * 2 < rdis[S] && rdis[S] < rdis[u.to] * 2 && dis[u.to] + rdis[u.to] == dis[T]) {
					res = (res + mod - e[u.data] * rt[i] % mod * e[u.data] % mod*rt[i] % mod) % mod;
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 17584
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  string ans="";
  int max;
  std::cin >> n>>m;
  if(n<=m){
    max =m;
    for (int i = 0; i < max; i++) {
      ans+=(n+'0');
    }
  }
  else{
    max =n;
    for (int i = 0; i < max; i++) {
      ans+=(m+'0');
    }
  }
  std::cout << ans << '\n';


  return 0;
}


Measured memory_bytes: 256
inp = input().split(' ')

A = int(inp[0])
B = int(inp[1])
K = int(inp[2])

ans = []

for i in range(1, min(A, B) + 1):
  if A % i == 0 and B % i == 0:
    ans.append(i)

# 降順ソート
ans.sort(reverse = True)

print(ans[K - 1])




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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

string S;

int main() {
    cin >> S;
    string ans;
    bool canMMYY = false;
    if (S[0] == '1') {
        if (S[1] >= '0' && S[1] <= '2')
            canMMYY = true;
    } else if (S[0] == '0') {
        if (S[1] >= '1')
            canMMYY = true;
    }

    bool canYYMM = false;
    if (S[2] == '1') {
        if (S[3] >= '0' && S[3] <= '2')
            canYYMM = true;
    } else if (S[2] == '0') {
        if (S[3] >= '1')
            canYYMM = true;
    }

    if (canMMYY) {
        if (canYYMM)
            cout << "AMBIGUOUS" << endl;
        else
            cout << "MMYY" << endl;
    } else {
        if (canYYMM)
            cout << "YYMM" << endl;
        else
            cout << "NA" << endl;
    }

    return 0;
}


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

typedef long long ll;

const int inf = 1000000;


int main() {
    int H, W, D, Q;
    cin >> H >> W >> D;
    int A[H][W];
    map<int, pair<int, int>>mp;
    vector<vector<ll>>v(D+1);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
            mp[A[i][j]] = make_pair(i+1, j+1);
        }
    }
    for (int i = 1; i <= D; i++) {
        ll sum = 0;
        v[i].push_back(0);
        for (int j = i; j+D <= H*W; j += D) {
            sum += abs(mp[j].first-mp[j+D].first) + abs(mp[j].second-mp[j+D].second);
            v[i].push_back(sum);
        }
    }

    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int L, R;
        ll total = 0;
        cin >> L >> R;
        if (L==R) {
            cout << 0 << endl;
            continue;
        }
        if (L % D == 0) {
            total = v[D][(R-D)/D] - v[D][(L-D)/D];
        } else {
            total = v[L%D][(R-(L%D))/D] - v[L%D][(L-(L%D))/D];
        }
        cout << total << endl;
    }
}


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

int main(){
  string s,t;
  cin >> s >> t;
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3920
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

const int MAX = 200000 + 5;

pair<int, int> a[MAX] = {};
int main() {
	int n, now;

	cin >> n;
	for(int i = 0;i < n;i++){
		scanf("%d", &now);
		a[now - 1] = make_pair(now, i);
	}

	set<int> st;
	st.insert(-1);
	st.insert(n);

	// cout << "OK" << endl;
	ll ans = 0;
	for(int i = 0;i < n;i++){
		pair<int, int> check = a[i];

		set<int>::iterator it = st.upper_bound(check.second);
		it--;

		ll l = check.second - *it;
		ll r = *(++it) - check.second;

		// cout << *it << ":" << l * r << endl;

		ans += (l * r) * check.first;

		st.insert(check.second);
	}

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

Measured memory_bytes: 11136
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<iostream>
#include<map>
#include<set>
#include<queue>
using namespace std;
int main(){
    string a,b;
    cin>>a;
    for(int i=1;i<a.size();i++){
        if(a[i]==a[i-1]){
            cout<<i<<" "<<i+1<<endl;
            return 0;
        }
    }
    for(int i=2;i<a.size();i++){
        if(a[i]==a[i-2]){
            cout<<i-1<<" "<<i+1<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    //LCS
    string s,t;
    cin>>s>>t;
    int n=s.length(),m=t.length();
    int dp[3001][3001]={};
    //dp[i][j]=i-1文字目まで見た時のLCSの長さ s[i]==t[i]だったらdp[i-1]
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else{
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
    /*
    rep(i,n+1){
        rep(j,m+1){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    string ans ="";
    int l=n,r=m;
    //line,raw
    while(dp[l][r]!=0){
        if(dp[l-1][r]<dp[l][r] && dp[l][r-1]<dp[l][r]){//両方減る
            ans += s[l-1];
            l--,r--;
        }
        else if(dp[l-1][r]==dp[l][r] && dp[l][r-1]<dp[l][r]){//上は減らない、左は減る
            l--;
        }
        else if(dp[l-1][r]<dp[l][r] && dp[l][r-1]==dp[l][r]){
            r--;
        }
        else{
            l--;
        }
    }
    Re(ans);
    //cout<<dp[n][m]<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,f=0;
string s,t,u;
cin>>s>>t>>a>>b>>u;
for(int i=0;i<s.size();i++){
	if(s[i]!=u[i]){
		f=1;
		break;
	}
}
if(f==1)cout<<a<<" "<<b-1;
else cout<<a-1<<" "<<b;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main()
{  
  int N;
  cin >> N;
  int A[N];

  for(int i = 0; i < N; i++)
  {
      int a;
      cin >> a;
      A[a - 1] = i + 1;
  }

  for(int i = 0; i < N; i++)
  {
      cout << A[i];
      if(i == N - 1)
      {
          cout << endl;
      }
      else
      {
          cout << " ";
      }      
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using Z=long;
Z S(vector<pair<int,int>> a){
sort(a.begin(),a.end());Z A=0;
priority_queue<int,vector<int>,greater<>> Q;
for(auto [k,d]:a){
Q.emplace(d);A+=d;
while(Q.size()>k)A-=Q.top(),Q.pop();
}return A;}
int main(){
	int q; scanf("%d",&q);
	rep(_,q){
		int n; scanf("%d",&n);
		Z sum=0;
		vector<pair<int,int>> L,R;
		rep(i,n){
			int k,l,r; scanf("%d%d%d",&k,&l,&r);
			if     (l>r) L.emplace_back( k ,l-r), sum+=r;
			else if(r>l) R.emplace_back(n-k,r-l), sum+=l;
			else         sum+=l;
		}
		cout<<sum+S(L)+S(R)<<endl;
	}
 
}

Measured memory_bytes: 7160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll A, B;
  cin >> A >> B;

  ll kosu = 0;
  ll sum = A * kosu - kosu + 1;
  while (sum < B){
    kosu++;
    sum = A * kosu - kosu + 1;
  }
  cout << kosu << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int cnt[26];
int main()
{
    char s[5];
    scanf("%s",s);
    for(int i=0;i<4;++i)
    {
        cnt[s[i]-'A']++;
    }
    int acc = 0;
    for(int i=0;i<26;++i)
    {
        if(cnt[i] == 2)
            acc++;
    }
    if(acc == 2)
    {
        puts("Yes");
    }else
    {
        puts("No");
    }
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int abs(int a){
	if(a<0) a=-a;
	return a;
}
int min(int a,int b){
	return a<b?a:b;
}
int GA[2003][2003],ans[2003];
int main(){
	int n,x,y;
	cin>>n>>x>>y;
	for (int i=1;i<=n;i++)
	{
		for (int j=i+1;j<=n;j++)  GA[i][j]=j-i;
	}
    for (int i=1;i<=n-1;i++)
	{
		for (int j=i+1;j<=n;j++)
		{
			int xx=abs(j-y)+1+abs(i-x),yy=abs(j-x)+1+abs(i-y);
			GA[i][j]=min(GA[i][j],min(xx,yy));
		}
	}
	for (int i=1;i<=n-1;i++)
	{
		for (int j=i+1;j<=n;j++)  ans[GA[i][j]]++;
	}
	for (int i=1;i<=n-1;i++)  cout<<ans[i]<<endl;
    return 0;
} 

Measured memory_bytes: 15360
from collections import deque
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

que = deque([0])
parent = [-1]*N
while que:
    node = que.pop()
    for v in graph[node]:
        if v == parent[node]:
            continue
        parent[v] = node
        que.append(v)
        ans[v] += ans[node] 

print(*ans)


Measured memory_bytes: 56480
n = int(input())
p = list(map(int, input().split()))
print(' '.join(map(str, range(n, n ** 2 + n, n))))
b = list(range(n, n ** 2 + n, n))[::-1]
for i, x in enumerate(p):
    b[x - 1] += i
print(' '.join(map(str, b)))


Measured memory_bytes: 71872
#!/usr/bin/env python3
import numpy as np


def main(a):
    a = np.diff(a)
    a = np.diff(a, axis=-1)
    a = np.diff(a, axis=0)
    a = np.diff(a, axis=0)
    if int(a[0]) == 0:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    a = np.empty(0)

    for i in range(3):
        a = np.append(a, list(map(int, (input().split()))))
    main(a.reshape(3,3))


Measured memory_bytes: 21380
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int x=0;
	int n;
	cin>>n;
	char s[n];
	int ans=-100;
	for(int i=0;i<n;i++)
	{
		ans=max(ans,x);
		cin>>s[i];
		if(s[i]=='I')
		x++;
		else
		x--;
		ans=max(ans,x);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
	
        int n = sc.nextInt();
        for (int i = 3; i<=n; i++) {
            if ((i % 3) == 0) {
		System.out.printf(" "+i);
            } else  {
                int x = i;
                while (x != 0) {
                    if ((x % 10) == 3) {
			System.out.printf(" "+i);
                        break;
                    }
                    x /= 10;
                }
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 30856