akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b,int m) {
    if (b==0) return 1;
    ll c = power(a,b>>1,m);
    c = (c*c)%m;
    if (b&1) return (c*a)%m;
    return c;
}
ll powerwithoutmod(ll a,ll b) {
    if (b==0) return 1;
    ll c = powerwithoutmod(a,b>>1);
    c = (c*c);
    if (b&1) return (c*a);
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)3e5+5;
const int M = (1<<21);
const int Q = 301;
const int logN = 16;

ll dp[110][110][2];
string s[110];
void solve() {
    int h,w;
    cin>>h>>w;
    REP(i,1,h){
        cin>>s[i];
        s[i] = "0"+s[i];
    }
    if (s[h][w]=='#') {
        dp[h][w][0] = INT_MAX;
        dp[h][w][1] = 1;
    }
    else {
        dp[h][w][0] = 0;
        dp[h][w][1] = INT_MAX;
    }
    REP(i,1,w+1){
        dp[h+1][i][0] = dp[h+1][i][1] = INT_MAX;
    }
    REPN(i,h,1){
        dp[i][w+1][0] = dp[i][w+1][1] = INT_MAX;
        REPN(j,w,1){
            if(i==h && j==w) {
                continue;
            }
            if(s[i][j]=='#'){
                dp[i][j][0] = INT_MAX;
                dp[i][j][1] = min(1+min(dp[i+1][j][0],dp[i][j+1][0]),min(dp[i+1][j][1],dp[i][j+1][1]));
            }
            else{
                dp[i][j][0] = min(min(dp[i+1][j][0],dp[i][j+1][0]),min(dp[i+1][j][1],dp[i][j+1][1]));
                dp[i][j][1] = INT_MAX;
            }
        }
    }
    cout<<min(dp[1][1][0],dp[1][1][1]);
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 512
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
import bisect
con = 998244353; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	def __init__(self, N):
		self.N0 = 2 ** (N - 1).bit_length()
		self.data = [0] * (2 * self.N0)

	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = max(self.data[2 * k + 1], self.data[2 * k + 2])

	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = 0
		while L < R:
			if R & 1:
				R -= 1
				m = max(m, self.data[R - 1])
			if L & 1:
				m = max(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N = int(input())
	XD = [None] * N
	for i in range(N):
		X, D = getlist()
		XD[i] = [X, D]
	XD.sort()
	Xl = [XD[i][0] for i in range(N)]
	Xl.append(INF)

	Seg = SegmentTree(N)
	IND = [None] * N
	for i in range(N):
		ind = bisect.bisect_left(Xl, XD[i][0] + XD[i][1]) - 1
		Seg.update(i, ind)
		IND[i] = ind

	#DP初期化
	DP = [[0] for i in range(N + 1)]
	DP[N] = 1
	# print(Xl)
	# print(IND)

	for i in range(N - 1, -1, -1):
		ind = Seg.query(i, IND[i])
		Seg.update(i, ind)
		DP[i] = DP[i + 1] + DP[ind + 1]
		DP[i] %= con

	ans = DP[0]
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 111116
import java.io.FileNotFoundException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] a = new char[H][W];
		for (int i = 0; i < H; ++i) {
			a[i] = sc.next().toCharArray();
		}
		int o = Math.max(H, W);
		MF mf = new MF(2 * o + 3);
		int s = 2 * o + 1;
		int t = 2 * o + 2;
		int INF = 999999;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (a[i][j] == 'S') {
					mf.ae(s, i, INF);
					mf.ae(s, o + j, INF);
				} else if (a[i][j] == 'T') {
					mf.ae(i, t, INF);
					mf.ae(o + j, t, INF);
				} else if (a[i][j] == 'o') {
					mf.ae(i, o + j, 1);
					mf.ae(o + j, i, 1);
				}
			}
		}
		int tot = mf.solve(s, t);
		if (tot >= INF) {
			System.out.println(-1);
		} else {
			System.out.println(tot);
		}
	}

	class MF {
		int n;
		int[][] cap;
		int[][] flow;
		ArrayList<Integer>[] g;

		public MF(int n) {
			this.n = n;
			cap = new int[n][n];
			flow = new int[n][n];
			g = new ArrayList[n];
			for (int i = 0; i < n; ++i) {
				g[i] = new ArrayList<>();
			}
		}

		void ae(int a, int b, int w) {
			cap[a][b] = w;
			g[a].add(b);
		}

		int solve(int s, int t) {
			int tot = 0;
			int[] pre = new int[n];
			while (true) {
				Arrays.fill(pre, -1);
				ArrayDeque<Integer> que = new ArrayDeque<>();
				que.add(s);
				out: while (!que.isEmpty()) {
					int v = que.poll();
					for (int i = 0; i < n; ++i) {
						if (cap[v][i] - flow[v][i] > 0 && pre[i] == -1 && i != s) {
							pre[i] = v;
							que.add(i);
							if (i == t) {
								break out;
							}
						}
					}
				}
				if (pre[t] == -1)
					break;
				int inc = Integer.MAX_VALUE / 16;
				for (int i = t; pre[i] != -1; i = pre[i]) {
					inc = Math.min(inc, cap[pre[i]][i] - flow[pre[i]][i]);
				}
				for (int i = t; pre[i] != -1; i = pre[i]) {
					flow[pre[i]][i] += inc;
					flow[i][pre[i]] -= inc;
				}
				tot += inc;
			}
			return tot;
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 25240
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,w,v,d[11],mxd,mx,ans;
	while(cin>>n>>w,n){
		rep(i,11)d[i]=0;
		ans=mxd=mx=0;
		rep(i,n){
			cin>>v,v/=w,d[v]++;
			if(mxd<v)mxd=v;
		}
		rep(i,mxd+1){
			if(mx<d[i])mx=d[i];
			ans+=d[i]*(mxd-i);
		}
		cout<<ans*1./mxd/mx+.01<<endl;
	}
	return 0;
}

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

int dp[3030][6030];

int main(){
  int n, t;
  cin >> n >> t;
  vector<P> p(n);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    p[i] = {a,b};
  }
  sort(p.begin(), p.end(), greater<P>());
  for (int i = 0; i < n; i++) {
    dp[i+1][0] = p[i].second;
    for (int j = 0; j < t; j++) {
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
      if (j + p[i].first < t) dp[i+1][j + p[i].first] = max(dp[i+1][j + p[i].first], dp[i][j] + p[i].second);
    }
  }
  int res = 0;
  for (int i = 0; i <= t; i++) {
    res = max(dp[n][i], res);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 69888
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  cin >> n;
  int ans = (n+1)/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define debug1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"
#define INF (int)10000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 1000000007

vector <vector <int>> adj[401];

int n, m;
int node(int i, int j)
{
	return i*m+j;
}

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

	cin>>n>>m;
	int x  = n*m;
	char a[n][m];
	for (int i=0;i<n;++i)
	{
		for (int j=0;j<m;++j)
		{
			cin>>a[i][j];
		}
	}
	int dist[x][x];
	for (int i=0;i<x;++i)
		{
			for (int j=0;j<x;++j)
			{
				dist[i][j] = INF;
			}
			dist[i][i]=0;
		}
	for (int i=0;i<n;++i)
	{
		for (int j=0;j<m;++j)
		{
			int u = node(i,j);
			if (a[i][j]=='#')
				continue;
			if (i+1<n && a[i+1][j]=='.')
			{
				dist[u][node(i+1, j)]=1;
				dist[node(i+1, j)][u]=1;
			}
			if (i-1>=0 && a[i-1][j]=='.')
			{
				dist[u][node(i-1, j)]=1;
				dist[node(i-1, j)][u]=1;

			}
			if (j+1<m && a[i][j+1]=='.')
			{
				dist[u][node(i, j+1)]=1;
				dist[node(i, j+1)][u]=1;

			}
			if (j-1>=0 && a[i][j-1]=='.')
			{
				dist[u][node(i, j-1)]=1;
				dist[node(i, j-1)][u]=1;

			}
		}
	}
	for (int k=0;k<x;++k)
	{
		for (int i=0;i<x;++i)
		{
			for (int j=0;j<x;++j)
			{
				if (dist[i][k]==INF || dist[k][j]==INF)
					continue;
				if (dist[i][j]>dist[i][k]+dist[k][j])
					dist[i][j] = dist[i][k]+dist[k][j];
			}
		}
	}
	int ans = 0;
	for (int i=0;i<x;++i)
	{
		for (int j=0;j<x;++j)
		{
			if (dist[i][j]==INF)
				continue;
			ans = max(ans, dist[i][j]);
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		char[] s = sc.next().toCharArray();
		int n = sc.nextInt();

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length; i += n) {
			sb.append(s[i]);
		}

		System.out.println(sb);

		sc.close();
	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	string res = "AC";
	if (S[0] != 'A') {
		res = "WA";
	}
	else {
		int N = S.size();
		int c = 0;
		for (int i = 2; i < N - 1; i++) {
			if (S[i] == 'C') {
				c++;
			}
		}
		if (c != 1) {
			res = "WA";
		}
		else {
			for (int i = 1; i < N; i++) {
				if (S[i] != 'C' && !(S[i] >= 'a' && S[i] <= 'z')) {
					res = "WA";
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++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(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int x;
    cin >> x;
    if(x == 3 || x == 5 || x == 7)
        cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long A, B, C, K;
  cin >> A >> B >> C >> K;

  cout << (A - B) * (K % 2 == 0 ? 1 : -1) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef vector<int,vector<int>> vvec;
typedef long double ld;

//----***Like a Pythonista***----
#define REP(i,j,n) for (ll i=j;i<(n);i++)
#define RREP(i,n,j) for (ll i = n; j<i;i--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1000000007;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define HERE  cout<<"Here"<<endl;

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,Q,a,b;cin>>N>>Q;
  vector<vector<int>> G(N);
  REP(i,0,N-1){
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  vector<int> P(N,0);
  REP(i,0,Q){
    cin>>a>>b;
    --a;
    P[a]+=b;
  }
  vector<int> ans(N);
  vector<bool> visited(N,false);

  queue<int> que;
  ans[0]=P[0];
  visited[0]=true;
  que.push(0);
  while(que.size()){
    int v=que.front();que.pop();
    each(e,G[v]){
      if(visited[e])continue;
      visited[e]=true;
      ans[e]=ans[v]+P[e];
      que.push(e);
    }
  }
  REP(i,0,N){
    print(ans[i])
  }


}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    if (A * B == C * D) cout << A * B << endl;
    else cout << max(A * B, C * D) << endl;
    
    return 0;
}


Measured memory_bytes: 256
K, N = map(int, input().split())
An = list(map(int, input().split()))

An_1 = [A for A in An if A <= K/2]
An_2 = [A-K for A in An if A > K/2]
An_new = An_1 + An_2

ans = 0
for i in range(len(An)-1):
    ans = max(ans, An[i+1]-An[i])
    
ans = max(ans, An_new[0] - An_new[-1])

print(K-ans)

Measured memory_bytes: 26420
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool map[21][21];
	int px,py,N,x,y,M,dir;
	char c;
	while(cin>>N,N){
		int cnt=0;
		px=py=10;
		rep(i,21)rep(j,21)map[i][j]=false;
		rep(i,N){
			cin>>x>>y;
			map[y][x]=true;
		}
		cin>>M;
		rep(i,M){
			cin>>c>>dir;
			if(c=='E'){
				rep(j,dir){
					px++;
					if(map[py][px]){
						cnt++;
						map[py][px]=false;
					}
				}
			}else if(c=='N'){
				rep(j,dir){
					py++;
					if(map[py][px]){
						cnt++;
						map[py][px]=false;
					}
				}
			}else if(c=='W'){
				rep(j,dir){
					px--;
					if(map[py][px]){
						cnt++;
						map[py][px]=false;
					}
				}
			}else if(c=='S'){
				rep(j,dir){
					py--;
					if(map[py][px]){
						cnt++;
						map[py][px]=false;
					}
				}
			}
		}
		if(cnt==N)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1148
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int w,n,b,c;
  cin>>w>>n;
  int a[w];
  for(int i=0;i<w;i++){
    a[i]=i+1;
  }
  for(int i=0;i<n;i++){
    scanf("%d,%d",&b,&c);
    int temp=a[b-1];
    a[b-1]=a[c-1];
    a[c-1]=temp;
  }
  for(int j=0;j<w;j++)cout<<a[j]<<endl;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int x;
  cin >> x;
  int m = x % 100;
  int c = (m+4)/5;
  int l = 100*c;
  // cerr << x << " " << m << " " << c << " " << l << endl;
  if(l > x) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a[2];
	int Count;
	int i[3];
	while (1)
	{
		Count = 0;
		scanf("%d %d", &a[0], &a[1]);
		if (a[0] == 0 && a[1] == 0)
		{
			break;
		}
		for (i[0] = 1; i[0] <= a[0]; i[0]++)
		{
			for (i[1] = i[0]; i[1] <= a[0]; i[1]++)
			{
				for (i[2] = i[1]; i[2] <= a[0]; i[2]++)
				{
					if (i[0] != i[1] && i[1] != i[2] && i[0] != i[2])
					{
						if (i[0] + i[1] + i[2] == a[1])
						{
							Count = Count + 1;
						}
					}

				}
			}
		}
		printf("%d\n", Count);
	}
}


Measured memory_bytes: 2104
h, w = map( int, input().split() )
s = []
for _ in range( h ):
    s_i = list( str( input() ) )
    s.append( s_i )

def connect( v ):
    con_v = []
    if v[ 0 ] > 0:
        if s[ v[ 0 ] - 1 ][ v[ 1 ] ] == ".":
            con_v.append( ( v[ 0 ] - 1, v[ 1 ] ) )
    if v[ 1 ] > 0:
        if s[ v[ 0 ] ][ v[ 1 ] - 1 ] == ".":
            con_v.append( ( v[ 0 ], v[ 1 ] - 1 ) )
    if v[ 0 ] < h - 1:
        if s[ v[ 0 ] + 1 ][ v[ 1 ] ] == ".":
            con_v.append( ( v[ 0 ] + 1, v[ 1 ] ) )
    if v[ 1 ] < w - 1:
        if s[ v[ 0 ] ][ v[ 1 ] + 1 ] == ".":
            con_v.append( ( v[ 0 ], v[ 1 ] + 1 ) )
    return con_v

from heapq import heappush, heappop
INF = 10 ** 10
VISITED = 1
NOT_VISITED = 0
def longest_bfs( i, j ):
    cost = [ INF for _ in range( h * w ) ]
    cost[ i * w + j ] = 0
    visit = [ NOT_VISITED for _ in range( h * w ) ]
    queue = [ ( 0, ( i, j ) ) ]
    while len( queue ) > 0:
        c, v = heappop( queue )
        visit[ v[ 0 ] * w + v[ 1 ] ] = VISITED
        for u in connect( v ):
            if visit[ u[ 0 ] * w + u[ 1 ] ] == VISITED:
                continue
            if cost[ u[ 0 ] * w + u[ 1 ] ] > cost[ v[ 0 ] * w + v[ 1 ] ] + 1:
                cost[ u[ 0 ] * w + u[ 1 ] ] = cost[ v[ 0 ] * w + v[ 1 ] ] + 1
                heappush( queue, ( cost[ u[ 0 ] * w + u[ 1 ] ], u ) )
    return cost

longest_path = 0
for i in range( h ):
    for j in range( w ):
        if s[ i ][ j ] == "#":
            continue
        path_length = longest_bfs( i, j )
        for p in path_length:
            if p < INF and p > longest_path:
                longest_path = p
print( longest_path )

Measured memory_bytes: 9308
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
x, y = map(int, input().split())
if (x in a) and (y in a):
    print("Yes")
elif (x in b) and (y in b):
    print("Yes")
elif (x in c) and (y in c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define maxx 1000001
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
    FASTIO
    ll n,ans=0;
    cin>>n;
    n--;
    for(int i=1;i<=n;i++)
        ans+=n/i;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
///#pragma GCC optimize("O3,unroll-loops")
///#pragma GCC target("avx,avx2,fma")

#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 ull unsigned long long
#define ld long double
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX5 100005
#define MAX6 1000006
#define MAX7 10000007
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define mod 1000000007
#define Mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }

inline int Set(ll N, ll pos){return N=N | (1LL<<pos);}
inline int Reset(ll N, ll pos){return N=N & ~(1LL<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline bool Equal(ld x, ld y) { return fabs(x-y) < eps; } ///x==y
inline bool Greater(ld x, ld y) { return (x - eps) > y; } /// x>y
inline bool Lesser(ld x, ld y) { return (x + eps) < y; }  /// x<y

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/// Memory Efficient
inline ll fast_exp(ll x, ll n, ll m) { ll res = 1; while(n>0) { if(n%2==1) res = (res * x) % m; x = (x * x) % m; n/=2; } return res%m; }

// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

void err(istream_iterator<string> it) {}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); }

inline void Time() { cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; }

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

const int N = 2*MAX6;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    FASTIO;
    ll a;
    cin>>a;
    cout<<(a+(a*a)+(a*a*a))<<endl;

    //Time();
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

template<typename ISTREAM>
void readGraphList(ISTREAM& cin, vector< vector<int> >& graphList) {
	size_t n;
	cin >> n;
	graphList = vector< vector<int> >(n);
	for (size_t i = 0; i != n; ++i) {
		size_t u;
		size_t k;
		cin >> u;
		cin >> k;
		vector<int>& v = graphList.at(u - 1);
		v.resize(k);
		for (size_t j = 0; j != k; ++j) {
			cin >> v.at(j);
			v.at(j)--;
		}
	}
}
#if 1
void widthSearch(const vector<vector<int>>& graphList) {
	const size_t n = graphList.size();
	queue<int> nodeQueue;
	vector<int> distanceList(n, -1);
	distanceList.front() = 0;
	nodeQueue.push(0);
	while (!nodeQueue.empty()) {
		const int id = nodeQueue.front();
		const int distanceOfNextNode = distanceList.at(id) + 1;
		const vector<int>& adjList = graphList.at(id);
		for (const auto& adjID : adjList) {
			int& nextNodeDistance = distanceList.at(adjID);
			if (nextNodeDistance != -1)continue;
			nodeQueue.push(adjID);
			nextNodeDistance = distanceOfNextNode;
		}
		nodeQueue.pop();
	}
	for (int i = 0; i != n; ++i) {
		cout << i + 1 << " " << distanceList.at(i) << endl;
	}
}
#endif

template<typename T>
void execute(T& cin) {
	vector< vector<int> > graphList;
	readGraphList(cin, graphList);
	widthSearch(graphList);
}

int main()
{
	execute(cin);

	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    int N;
    
    cin >> N ;
  
    cout << N*N*N << endl;
    
    return 0;
    

}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N = parseInt(arg[0]);
    const A = arg.slice(1, N + 1).map(n=>parseInt(n)).sort((a,b)=>a-b);
    
    let cnt = 0;
    
    for(let i=0; i<N; i++) {
        if(A[i] === A[parseInt(i) + 1]) {
            i++;
        } else {
            cnt++;
        }
    }
    
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 28860
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = 0;
        int N = sc.nextInt();
        int a[] = new int[N + 1];
        for(int i = 1; i < N + 1; i ++){
            a[i] = sc.nextInt();
            if(i % 2 != 0 && a[i] % 2 != 0){
                n = n + 1;
            }
        }

        System.out.println(n);

    }
}

Measured memory_bytes: 35804
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
const ll MOD=1000000007;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K,Q;
    cin>>N>>K>>Q;
    vector<int>point(N);
    int a;
    REP(i,Q){
        cin>>a;
        point[a-1]++;;
    }
    REP(i,N){
        cout<<(K-Q+point[i]>0?"Yes":"No")<<endl;
    }
}

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

#define ar array
#define ll long long int

const ll mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
       string s;
       cin >> s;
       ll sum = 0;
       for (char &ch : s) {
           sum = (sum + (ch - '0')) % 9;
       }
       cout << (sum % 9 == 0 ? "Yes" : "No");
    }

    return 0;
}

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

int main(){
  int n,m;
  long long k;
  cin >> n >> m >> k;
  long long a[n+1];
  long long b[m+1];
  int counta=0;
  int countb=0;
  long long timea=0;


  for(int i=1;i<=n;i++) {
    cin >> a[i];
  }

  for(int i=1;i<=n;i++){
    if(timea<=k-a[i]){
      timea +=a[i];
      counta =i;
    }
    else break;
  }


  for(int i=1;i<=m;i++) {
    cin >> b[i];
  }

  int j=1;
  long long count = counta;
  long long counti = counta;
  long long ans = counta;
  long long time = timea;
  long long timei = timea;

  while(timei<=k-b[j]&&j<=m){
    timei +=b[j];
    j++;
    counti ++;
  }
  ans = counti;
j=1;
  for(int i=counta;1<=i;--i){
     time -= a[i];
     count --;
     while((time<=k-b[j])&&j<=m){
       time +=b[j];
       j++;
       count ++;
     }
     ans = max(ans,count);
     if(j==m+1) break;
  }


  cout << ans <<endl;


}

Measured memory_bytes: 6760
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    char s[A+B+1+1];
    for(int i=1;i<=A+B+1;i++){
        cin >>s[i];
    }
    int ans=0;
    for(int i=1;i<=A+B+1;i++){
        if(i==A+1 && s[i]!='-'){
            ans=-1;
        }
        else if(i!=A+1 && s[i]=='-')
    ans=-1;
    }
    if(ans>=0){
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int w=0,n=0,i,a,b,box;
    scanf("%d",&w);
    int ab[w];
    for(i=0;i<w;i++){
        ab[i]=i+1;
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d,%d",&a,&b);
        box=ab[a-1];
        ab[a-1]=ab[b-1];
        ab[b-1]=box;
    }
    for(i=0;i<w;i++){
        printf("%d\n",ab[i]);
    }
return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << ' ' << y << ' ' << z << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k,x,i;
	cin>>k>>x;
	for(i=x-k+1;i<=x;i++)
	{
		cout<<i<<" ";
	}
	for(i=1;i<k;i++)
	{
		cout<<x+i<<" "; 
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int memory[ 1000 ];
  int dice[ 1000 ];
  int i;

  for ( ; ; )
  {
    int N, M;
    int c, p;

    scanf ( "%d%d", &N, &M );
    if ( !( N || M ) ) break ;

    for ( i = 0; i < N; ++i ) scanf ( "%d", memory + i );
    for ( i = 0; i < M; ++i ) scanf ( "%d", dice + i );

    for ( c = p = 0; p < N - 1; )
    {
      p += dice[ c++ ];
      if ( p >= N - 1 )  break ;
      p += memory[ p ];
    }

    printf ( "%d\n", c );
  }

  return ( 0 );
}

Measured memory_bytes: 0
// atcoder/abc164/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n, m, s;
  while (cin >> n >> m >> s) {
    const int N = 50 + 5;
    lli c[N];
    lli d[N];

    vec<pair<lli, pair<int, int>>> g[N];
    for (int i = 0; i < m; ++i) {
      int u, v, a, b;
      cin >> u >> v >> a >> b;
      --u;
      --v;
      g[u].push_back(make_pair(v, make_pair(a, b)));
      g[v].push_back(make_pair(u, make_pair(a, b)));
    }

    for (int i = 0; i < n; ++i) {
      cin >> c[i] >> d[i];
    }

    const int M = N * 50;
    static lli cost[N][M];
    const lli inf = 1LL << 60;
    fill(&cost[0][0], &cost[N - 1][M - 1] + 1, inf);
    setmin(s, M - 1);

    priority_queue<pair<lli, pair<int, lli>>> q;
    cost[0][s] = 0;
    q.push(make_pair(0, make_pair(0, s)));
    while (q.size()) {
      auto p = q.top();
      q.pop();
      lli w = -p.first;
      int curr = p.second.first;
      lli silver = p.second.second;
      if (cost[curr][silver] != w) continue;
      each (e, g[curr]) {
        for (int ch = 0; ch < 100; ++ch) {
          lli x = min<lli>(M - 1, silver + ch  * c[curr] - e.second.first);
          lli y = w + ch * d[curr] + e.second.second;
          if (0 <= x && cost[e.first][x] > y) {
            cost[e.first][x] = y;
            q.push(make_pair(-y, make_pair(e.first, x)));
          }
        }
      }
    }

    for (int i = 1; i < n; ++i) {
      lli mn = inf;
      for (int j = 0; j < M; ++j) {
        setmin(mn, cost[i][j]);
      }
      cout << mn << endl;
    }
  }

  return 0;
}


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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define        sqr(a)       ((a)*(a))
//int dx[] = {0,1,0,-1};
//int dx[] = {0,1,0,-1};
//int dy[] = {-1,0,1,0};

//   cout<<std::setprecision(12)<<

int main()
{
    int i,j,k,l,m,n,r;

    cin >> n >> m;

    vector<pll>v;

    for(i=0;i<m;i++)
    {
        cin >> k >> l;
        v.pb({l,k});
    }

    sort(all(v));

    l = v[0].S;
    r = v[0].F;

    for(i=1;i<m;i++)
    {
        k = v[i].S;
        l = max(l,k);
        k = v[i].F;
        r = min(r,k);
    }

    int mn = 0;
    mn = max(mn,r-l+1);

    cout << mn << endl;


}


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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); 
  const int mod = 1e9+7;
  int n;
  cin >> n;
  vector<int> c(1);
  cin >> c[0];
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    if (x != c.back()) c.push_back(x);
  }
  n = c.size();
  vector<int> ac(200001, 0), dp(n, 0);
  dp[0] = 1;
  ac[c[0]] = 1;
  for (int i = 1; i < n; i++) {
    dp[i] = dp[i-1] + ac[c[i]];
    if (dp[i] >= mod) dp[i] -= mod;
    ac[c[i]] += dp[i-1];
    if (ac[c[i]] >= mod) ac[c[i]] -= mod;
  }
  cout << dp[n-1] << endl;
  
}



Measured memory_bytes: 2804
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut s: Vec<char> = itr.next().unwrap().chars().collect();
    let t: Vec<char> = itr.next().unwrap().chars().collect();

    let n = s.len();
    let m = t.len();
    for i in (0..n - m + 1).rev() {
        let mut ok = true;
        for j in 0..m {
            if s[i + j] != '?' && s[i + j] != t[j] {
                ok = false;
                break;
            }
        }
        if ok {
            for j in 0..m {
                s[i + j] = t[j];
            }
            for j in 0..n {
                if s[j] == '?' {
                    s[j] = 'a';
                }
            }
            let s: String = s.into_iter().collect();
            println!("{}", s);
            return;
        }
    }
    println!("UNRESTORABLE");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, q, ls[800000];

struct LazySegTree { //参照は i + sz - 1 だよ～;
    ll sz;
    vector<ll> node, lazy;
    vector<bool> lazyFlag;
    LazySegTree(ll n) {
        sz = 1;
        while (sz < n) sz *= 2;
        node.resize(2 * sz - 1);//
        lazy.resize(2 * sz - 1);//
        lazyFlag.resize(2 * sz - 1);
    }
    void eval(ll k, ll l, ll r) {
        if (lazyFlag[k]) {
            node[k] += lazy[k];//
            if (r - l > 1) {
                lazy[2 * k + 1] += lazy[k] / 2;//
                lazy[2 * k + 2] += lazy[k] / 2;//
                lazyFlag[2 * k + 1] = lazyFlag[2 * k + 2] = true;
            }
            lazyFlag[k] = false;
            lazy[k] = 0;//
        }
    }
    void update(ll a, ll b, ll x, ll k = 0, ll l = 0, ll r = -1) {
        if (r < 0) r = sz;
        eval(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;//
            lazyFlag[k] = true;
            eval(k, l, r);

        }
        else {
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = node[2 * k + 1] + node[2 * k + 2];//
        }
    }
    void update(ll a, ll x) {
        update(a, a + 1, x);
    }
    ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
        if (r < 0) r = sz;
        eval(k, l, r);
        if (b <= l || r <= a) return 0;//
        if (a <= l && r <= b) return node[k];
        ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;//
    }
};

LazySegTree seg(800000);

int main() {
    cin >> n >> q;
    vector<ll> s(n), ans(q);
    vector<P> qu(q), v(q);
    REP(i, n){
        cin >> s[i];
    }
    REP(i, q){
        cin >> qu[i].first >> qu[i].second;
        v[i] = P(qu[i].second, i);
    }
    sort(ALL(v));
    ll ns = 0;
    REP(i, n){
        ll r = i + 1;
        seg.update(ls[s[i]] + 1, r + 1, 1);
        ls[s[i]] = r;
        while(ns < q and v[ns].first == r){
            ll id = v[ns].second;
            ll l = qu[id].first;
            ans[id] = seg.query(l, l + 1);
            ns++;
        }
    }
    REP(i, q){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 64204
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
    long long N;
    cin>>N;
    long long ans=0;
    for (int i = 1 ; i <(N/2+1) ; ++i) {
        if ((i + N-i) == N and i != N-i and i ){
            ans ++;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;


int main(int argc, char* argv[]){

	char S[30];
	scanf("%s", S);
	printf("%c", S[0]);
	printf("%c", S[1]);
	printf("%c\n", S[2]);




	return 0;
}





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

int main()
{
	long long int a, b, c,ans=0;

	cin >> a >> b >> c;

	if (a >= c) {
		ans += c;
		c = 0;
	}
	else {
		c -= a;
		ans += a;
	}

	if (b >= c) {
		ans += b + c;
	}
	else {
		ans += b + b + 1;
	}

	cout << ans << endl;

	return 0;
}

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

int m[810][810];
int rest[810][810];
int u[810][810];

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int main() {
    int h, w, k; cin >> h >> w >> k;
    int xst, yst = 0;
    for (int i = 0; i < h; i++) {
        string s; cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '#') m[i][j]++;
            if (s[j] == 'S') xst = i, yst = j;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int c = min({i, j, (h-i-1), (w-j-1)});
            rest[i][j] = (c+k-1) / k;
        }
    }
    queue<int> xq, yq; u[xst][yst] = 1;
    xq.push(xst), yq.push(yst);
    while (!xq.empty()) {
        int x = xq.front(); int y = yq.front();
        xq.pop(); yq.pop();
        if (u[x][y] > k) continue;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (m[nx][ny] || u[nx][ny]) continue;
            u[nx][ny] = u[x][y] + 1;
            xq.push(nx); yq.push(ny);
        }
    }
    int ans = 1e9;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (u[i][j]) ans = min(ans, rest[i][j] + 1); 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7936
#coding:utf-8

ans = []
while True:
    a, op, b = raw_input().split()
    if op == "?":
        break
    else:
        if op == "+":
            ans.append(int(a) + int(b))
        elif op == "-":
            ans.append(int(a) - int(b))
        elif op == "*":
            ans.append(int(a) * int(b))
        else:
            ans.append(int(a) / int(b))

for n in xrange(len(ans)):
    print(ans[n])

Measured memory_bytes: 6392
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	ll dp[M];
	int n,k,h[M];
	rep(i,0,M)dp[i]=inf;
	cin>>n>>k;
	dp[0]=dp[1]=0;
	rep(i,0,n)cin>>h[i];
	rep(i,1,n+1){
		rep(j,1,k+1){
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i-1]-h[i-1+j]));
		}
	}
	print(dp[n]);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 100;

int a[N];
int n;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (j - i > 1) {
			//	if (a[i] + a[j-1] <= a[j]) break;
				for (int k = i + 1; k < j; k++) {
					if (a[i] + a[k] > a[j] && a[i] + a[j] > a[k] && a[k] + a[j] > a[i]) ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
*> AtCoder My Practice
       *> author: Leonardone @ NEETSDKASU
       *>
       IDENTIFICATION DIVISION.
       PROGRAM-ID. Answer.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
              FUNCTION ALL INTRINSIC.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
              01 Input-Values.
                     05 n      BINARY-SHORT.
              01 Answer-Values.
                     05 disp   PIC Z(4)9.
       PROCEDURE DIVISION.
       AnswerMain SECTION.
       000-Start.
       
              ACCEPT n.
              DIVIDE 3 INTO n.
       
      	      MOVE n TO disp.
              DISPLAY TRIM(disp).
       END PROGRAM Answer.


Measured memory_bytes: 384
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n;
	cin >> n;
	cout << n * 800 - (n / 15) * 200 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int S;
	int h,m,s;
    scanf("%d", &S);

    h = S/3600;
    m = (S-h*3600)/60;
    s = S-h*3600-m*60;

    printf("%d:%d:%d\n", h ,m, s);

	return 0;
}

Measured memory_bytes: 592
n = input()
A = map(int, raw_input().split())

count = {}
for a in A:
    count[a] = count.get(a, 0) + 1
can = []
for a in count:
    can.extend([a]*(count[a]/2))
can.sort()
if len(can) < 2:
    print 0
else:
    print can[-1]*can[-2]



Measured memory_bytes: 16084
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int dp[2005][2005];

int main(void) {
    int N, M; cin >> N >> M;
    vector<int> S(N+1);
    vector<int> T(M+1);
    S[0] = 0;
    T[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> S[i];
    }
    for (int i = 1; i <= M; i++) {
        cin >> T[i];
    }
    for (int i = 0; i <= N; i++) {
        dp[i][0] = 1;
    }
    for (int i = 0; i <= M; i++) {
        dp[0][i] = 1;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            dp[i][j] += (dp[i-1][j] - dp[i-1][j-1] + MOD) % MOD;
            dp[i][j] %= MOD;
            dp[i][j] += (dp[i][j-1] - dp[i-1][j-1] + MOD) % MOD;
            dp[i][j] %= MOD;
            dp[i][j] += dp[i-1][j-1];
            dp[i][j] %= MOD;
            if (S[i] == T[j]) {
                dp[i][j] += dp[i-1][j-1];
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[N][M] << endl;

}   


Measured memory_bytes: 15872
h, n = gets.split.map(&:to_i)
 
dp = [10 ** 9] * (h + 1)
dp[0] = 0
 
n.times do
  a,b = gets.split.map(&:to_i)
  h.times do |ch|
    nh = (ch + a < h) ? ch + a : h
    dp[nh] = (dp[nh] < dp[ch] + b) ? dp[nh] : dp[ch] + b
  end
end
 
puts dp[h]


Measured memory_bytes: 1916