akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;

const int MAX_N=2600;
const ll INF=1e18;
int n,m,p;
vector<int>go[MAX_N],back[MAX_N];
vector<bool>go_state(MAX_N,false),back_state(MAX_N,false);

void dfs(int v, vector<int> way[], vector<bool> &state){
  if(state[v])return;
  state[v]=true;
  for(auto next:way[v]){
    dfs(next,way,state);
  }
}

int main(){
  cin>>n>>m>>p;
  vector<int>a(m),b(m),c(m);
  vector<T>edge(m);
  rep(i,m){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--; b[i]--;
    c[i]-=p;
    edge[i]=T(a[i],b[i],c[i]);
    go[a[i]].push_back(b[i]);
    back[b[i]].push_back(a[i]);
  }

  dfs(0,go,go_state);
  dfs(n-1,back,back_state);

  vector<bool>both(MAX_N,false);
  rep(i,n)both[i]=go_state[i]&back_state[i];

  vector<ll>dist(n,-INF);
  dist[0]=0;
  rep(i,n){
    for(auto &e: edge){
      int a,b,c;
      tie(a,b,c)=e;
      if(dist[a]!=-INF){
        dist[b]=max(dist[b],dist[a]+c);
      }
    }
  }

  vector<ll>dist_first=dist;
  rep(i,n){
    for(auto &e: edge){
      int a,b,c;
      tie(a,b,c)=e;
      if(dist[a]!=-INF){
        dist[b]=max(dist[b],dist[a]+c);
      }
    }
  }

  rep(i,n){
    if(both[i]&&dist_first[i]!=dist[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  
  cout<<max(0LL,dist[n-1])<<endl;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forn(i,a,n) for(int i =a; i < n; i++)
#define se second
#define fi first
#define pb push_back
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long int lli;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){__
	string s;
	cin >> s;
	int d =0;
	for(char c : s){
		d+= (c-'0');
		d%=9;
	}
	if(d == 0) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}



Measured memory_bytes: 3768
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		int i = sc.nextInt();
		int j = sc.nextInt();
		
		System.out.println(i * j);
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 25284
#include <iostream>

using namespace std;

int main(){

  int N, S = 0;

  cin >> N;

  int num = N;
  
  while(num){
    S += num % 10;
    num = num / 10;
  }

  if(N % S == 0){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve(){
	ll l,s=0,i;
    string n;
    cin>>n;
    for(i=0;i<n.length();i++){
        s+=n[i]-'0';
    }
    if(s%9){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }



}

int main() {
	ios_base::sync_with_stdio(0);
	int i,t=1;
	//cin>>t;
	for(i=1;i<=t;i++){
		solve();
	}
	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % mod;
		base = ((ll)base * base) % mod;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 111111;
const int mod = 1000000007;
long long fact[N], inv[N], invfact[N];
long long invsum[N];

long long C(int n, int k) {
	if (k < 0 || k > n) {
		return 0;
	}
	return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

void solve(int n) {
	vector<int> a(n);
	vector<int> p(n);
	iota(all(p), 0);
	do {
		vector<char> used(n);
		for (int x : p) {
			int i = x;
			while (i > 0 && !used[i - 1]) {
				--i;
			}
			while (i < n && !used[i]) {
				++a[i++];
			}
			used[x] = 1;
		}
		for (int i = 0; i < n; ++i) {
			a[i] -= 1;
		}
	} while (next_permutation(all(p)));
	for (int x : a) {
		cout << x << " ";
	}
	cout << "\n";
}

int main() {
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
	for (int n = 1; n <= 9; ++n) {
		solve(n);
	}
*/
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < N; ++i) {
		inv[i] = (i == 1) ? 1 : mod - mod / i * inv[mod % i] % mod;
		fact[i] = fact[i - 1] * i % mod;
		invfact[i] = invfact[i - 1] * inv[i] % mod;
		invsum[i] = (invsum[i - 1] + inv[i]) % mod;
	}

	int n = nxt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nxt();
	}

	vector<long long> pr(n + 1);
	for (int i = 0; i < n; ++i) {
		pr[i + 1] = pr[i] + a[i];
	}

	vector<long long> sum_segs(n + 1);
	for (int i = 1; i < n - 1; ++i) {
		if (n - i > i) {
			sum_segs[i] = (sum_segs[i - 1] + pr[n - i] - pr[i]) % mod;
		} else {
			sum_segs[i] = sum_segs[n - 1 - i];
		}
	}

	long long ans = fact[n] * (pr[n] % mod) % mod;
	for (int i = 1; i < n; ++i) {
		ans += (pr[i] + pr[n] - pr[n - i]) % mod * fact[n] % mod * inv[i + 1] % mod;
	}
	for (int i = 1; i < n - 1; ++i) {
		ans += sum_segs[i] * 2 * fact[n] % mod * inv[i + 1] % mod * inv[i + 2] % mod;
	}
	cout << ans % mod << "\n";

	return 0;
}

Measured memory_bytes: 5632
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;


public class Main{
   
   

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String S=sc.next();
        int a=Integer.parseInt(""+S.charAt(0));
        int b=Integer.parseInt(""+S.charAt(1));
        int c=Integer.parseInt(""+S.charAt(2));
        int d=Integer.parseInt(""+S.charAt(3));
        if(a+b+c+d==7){
            System.out.println(a+"+"+b+"+"+c+"+"+d+"=7");
        }
        else if(a+b-c+d==7){
            System.out.println(a+"+"+b+"-"+c+"+"+d+"=7");
        }
        else if(a+b+c-d==7){
            System.out.println(a+"+"+b+"+"+c+"-"+d+"=7");
        } 
        else if(a+b-c-d==7){
            System.out.println(a+"+"+b+"-"+c+"-"+d+"=7");
        }
        else if(a-b+c+d==7){
            System.out.println(a+"-"+b+"+"+c+"+"+d+"=7");
        }
        else if(a-b-c+d==7){
            System.out.println(a+"-"+b+"-"+c+"+"+d+"=7");
        }
        else if(a-b+c-d==7){
            System.out.println(a+"-"+b+"+"+c+"-"+d+"=7");
        }
        else if(a-b-c-d==7){
            System.out.println(a+"-"+b+"-"+c+"-"+d+"=7");
        }

        

        
        

    }

        
        
    }


Measured memory_bytes: 22100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = int(3e5), mod = int(1e9)  + 7; 

int n, a[N], mx;

bool check(int c){
	int unq = 0, x = 0;
	for(int i = 1; i <= n; i++){
		if(c - 1 == a[i]){
			unq++;
		}
		else if(c == a[i]){
			x++;
		}
		else return 0;
	}
	if(x == 1) return 0;
	return (unq + (x > 1) <= c && unq + x / 2 >= c);
}

int main () {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		mx = max(mx, a[i]);
	}
	if(check(mx) || check(mx + 1)){
		puts("Yes");
	}
	else{
		puts("No");
	}

return 0;
}

Measured memory_bytes: 640
//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

using lld = int64_t;
using llu = uint64_t;
using llf = long double;
using PII = pair<int,int>;
using PIL = pair<int,lld>;
using PLI = pair<lld,int>;
using PLL = pair<lld,lld>;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) (int)((x).size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, ans=0; cin >> n;
	for ( int i = 1 ; i <= n ; ++ i )
		for ( int j = i + 1 ; j <= n ; ++ j )
			ans += (i&1) ^ (j&1);
	cout<<ans<<'\n';
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<string, int> a;
  rep(i, n) {
    string s;
    cin >> s;
    a[s] = 1;
  }

  cout << a.size();
}


Measured memory_bytes: 19064
H, W = map(int, input().split())

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


U = [[0]*(W+1) for h in range(H+1)]
L = [[0]*(W+1) for h in range(H+1)]
for h in range(H):
  for w in range(W):
    if S[h][w] == '#':
      continue
    
    U[h+1][w+1] = U[h][w+1] + 1
    L[h+1][w+1] = L[h+1][w] + 1


ans = 0
D = [[0]*(W+1) for h in range(H+1)]
R = [[0]*(W+1) for h in range(H+1)]
for h in range(H-1, -1, -1):
  for w in range(W-1, -1, -1):
    if S[h][w] == '#':
      continue

    D[h][w] = D[h+1][w] + 1
    R[h][w] = R[h][w+1] + 1
    ans = max(ans, D[h][w]+R[h][w]+U[h+1][w+1]+L[h+1][w+1]-3)

print(ans)

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

using namespace std;

typedef long long ll;

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

const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10,mod = 1e9 + 7;

char str[N];
int dp[N];

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

inline void Add(int &x,int y) { if((x += y) >= mod) x -= mod; }
inline int chk(int v) { return v < 0 ? 0 : dp[v]; }
inline int val(int v) { return v & 1 ? v - 1 : v; }

int main() {

	int n = read(),m = read(),flag = true;
	scanf("%s",str + 1);
	For(i,1,m - 1) if(str[i] != str[i + 1]) flag = false;
	if(flag) {
		int v00 = 1,v11 = 1,v01 = 0,v10 = 0;
		For(i,2,n) {
			int c00 = v00,c10 = v10;
			Add(v00,v10),Add(v10,v11);
			v01 = c00,v11 = c10;
		}
		printf("%lld\n",(1ll * v00 + v10 + v01) % mod);
		return 0;
	}
	if(n & 1) return puts("0"),0;
	int v = INF,tot = 0;
	For(i,1,m) {
		if(str[i] == str[1]) tot++;
		else {
			if(tot == i - 1) chkmin(v,tot + (tot % 2 == 0));
			if(tot & 1) chkmin(v,tot);
			tot = 0;
		}
	}
	v++, dp[0] = 1;
	for(int i = 2;i <= n;i += 2) dp[i] = (2ll * dp[i - 2] - chk(i - 2 - v)) % mod;
	int ans = dp[n] - dp[n - 2];
	For(i,1,v - 1) ans = (ans + 1ll * dp[val(n - i - 1)] - dp[n - v - 2]) % mod;
	printf("%d\n",(ans + mod) % mod);
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	REP(i,n) cin >> a[i];
	int ans = 0;
	map<pair<int,int>, int> mp;
	REP(i,n){
		if(mp[make_pair(i,a[i])] != 0) continue;
		if(a[a[i]] == i){
			ans++;
			mp[make_pair(i,a[i])]++;
			mp[make_pair(a[i],i)]++;
		}
	}
	cout << ans << endl;
    return 0;
}




Measured memory_bytes: 6912
### a<=b<=cととることとし、a,bを固定すると
### cは　c<a+b
from bisect import bisect_left
N = int(input())
lst = list(map(int, input().split()))
sor = sorted(lst)
res = 0
for i in range(N):
    for j in range(i+1, N):##ここでa<=bを満たしている
        ab = sor[i] + sor[j]
        highbound = bisect_left(sor, ab)
        res += highbound - j - 1
print(res)
### ライブラリを使おう！！！

Measured memory_bytes: 3188
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v=0; v<n; v++){
    if(M[u][v] == 0){
      continue;
    }
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for(u=0; u<n; u++){
    if(color[u] == WHITE){
      dfs_visit(u);
    }
  }
  for(u=0; u<n; u++){
    printf("%d %d %d\n",u+1, d[u], f[u]);
  }
}

int main(){
  int u, v, k, i, j;

  scanf("%d",&n);
  for(i=0; i<n; i++){
   for(j=0; j<n; j++){
      M[i][j] = 0;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d%d",&u, &k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++) 

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	int a[60], b[60];
    int x[60] = {0};
	cin >> n >> m;
	REP(i, m) {
		cin >> a[i] >> b[i];
		x[a[i] - 1]++;
		x[b[i] - 1]++;
	}
	REP(i, n) cout << x[i] << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int a, t, b[] = {6000, 4000, 3000, 2000};

int main(){
    for(int i = 0; i < 4; i++){
        scanf("%d %d", &a, &t);
        printf("%d\n", b[a - 1] * t);
    }

    return 0;
}

Measured memory_bytes: 2760
import java.util.Scanner;
class Main {
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String str = s.next();
 	int j = Character.getNumericValue(str.charAt(0));
        int flag = 0;
 	 for(int i=1; i<str.length(); i++)
 	 {
  		int d= str.charAt(i)- '0';
                if(d == j){
                    System.out.println("Bad");
                    flag = 1;
                    break;
                }
                j = d;
  	}
        if(flag != 1)
            System.out.println("Good");
        
    }
    
}


Measured memory_bytes: 21332
N, M = list(map(int, input().split()))
ac = [0]*N
wrong = [0]*N
ans = 0
for i in range(M):
  temp = input().split()
  if temp[1] == "AC":
    ac[int(temp[0])-1] = 1
  elif ac[int(temp[0])-1] ==0:
    wrong[int(temp[0])-1] += 1

for i in range(N):
  if ac[i]==1:
    ans += wrong[i]
  
print(str(sum(ac)) + " " + str(ans))

Measured memory_bytes: 4596
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{   int N, K, X, Y;
    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;
    if (N < K)
    {
        cout << N * X;
    }
    else
    {
        cout << K * X + (N - K) * Y;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

//char arr[1003][1003];
string arr[1003];
//int dist[1003][1003];

int main() {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
	int m, n, x1, y1, x2, y2;	cin>>m>>n; //scanf("%d %d", &m, &n);
	//scanf("%d %d", &x1, &y1);	scanf("%d %d", &x2, &y2); 
	cin>>x1>>y1;	cin>>x2>>y2;
	x1--, y1--, x2--, y2--;
	
	int inf = INT_MAX - 100;
	vector<vector<int>> dist(m, vector<int>(n, inf));
	vector<vector<bool>> visited(m, vector<bool>(n, false));
	
	for(int i=0; i<m; i++)	cin>>arr[i];
	
	/*for(int i=0; i<m; i++) {
		for(int j=0; j<n; j++) printf("%c", arr[i][j]);
		printf(" [%d]\n", i);
	} */
	
	int ans = -1, f = 0;
	
	deque<pair<int, pair<int,int>>> Q;
	dist[x1][y1] = 0;	//visited[x1][y1] = true;
	Q.push_front({0, {x1, y1}});
	pair<int, pair<int,int>> temp;
	
	while(!Q.empty()) {
		temp = Q.front();	Q.pop_front();
		
		//printf("[%d, %d] -> dist:%d\n", temp.s.f, temp.s.s, temp.f);
		//if(visited[temp.s.f][temp.s.s]) continue;
		
		if(temp.s.f == x2 && temp.s.s == y2) {
			ans = temp.f;
			break;
		}
		
		int dir[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};

		for(int i=0; i<4; i++) {
			int r = temp.s.f + dir[i][0], c = temp.s.s + dir[i][1];
			
			if(r >= 0 && c >= 0 && r < m && c < n && arr[r][c] != '#' && !visited[r][c])
				if(dist[r][c] > dist[temp.s.f][temp.s.s]) {
					dist[r][c] = dist[temp.s.f][temp.s.s];
					//visited[r][c] = true;
					
					Q.push_front({dist[r][c], {r, c}});
				}
		}
		
		for(int i=-2; i<=2; i++) for(int j=-2; j<=2; j++) {
			if(abs(i) + abs(j) == 1) continue;
			
			int r = temp.s.f + i, c = temp.s.s + j;
			//printf("[%d, %d], ", r, c);
			if(r >= 0 && c >= 0 && r < m && c < n && arr[r][c] != '#' && !visited[r][c])
				if(dist[r][c] > 1 + dist[temp.s.f][temp.s.s]) {
					dist[r][c] = 1 + dist[temp.s.f][temp.s.s];
					//visited[r][c] = true;
					
					Q.push_back({dist[r][c], {r, c}});
				}
		}	//printf("\n");
		
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 8912
def green_bin(s)
  s.map! { |str| str.chars.sort.join }
  count = Hash.new(0)
  s.each { |str| count[str] += 1 }

  ans = 0
  count.each_value do |c|
    next if c == 1
    ans += c * (c - 1) / 2
  end
  ans
end

n = gets.to_i
s = []
n.times{ s << gets.chomp }

puts green_bin(s);


Measured memory_bytes: 32252
#include<bits/stdc++.h>
#define maxn 500005
#define pdi pair<double,int>
#define endl '\n'
using namespace std;
pdi deq[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,L;
	cin >> n >> L;
	int l = 0 , r = 0;
	double sum_t = 0 ;
	int sum_v = 0;
	for(int i=1;i<=n;i++) {
		double t;
		int v;
		cin >> t >> v;
		t *= v;
		sum_t += t;		sum_v += v;
		while(sum_v > L) {
			if(sum_v - deq[l].second < L) {
				int delta = sum_v - L;
				sum_t -= deq[l].first * delta / deq[l].second;
				sum_v -= delta;
				deq[l].first  -= deq[l].first * delta / deq[l].second;
				deq[l].second -= delta;
			}
			else {
				sum_t -= deq[l].first;
				sum_v -= deq[l].second;
				l++;
			}
		}
		while(l < r && deq[r-1].first/deq[r-1].second > t/v) {
			t += deq[r-1].first;
			v += deq[r-1].second;
			r--;
		}
		deq[r++] = pdi{t,v};
		cout << fixed << setprecision(7) << sum_t / sum_v << endl;
	}
	return 0;
}


Measured memory_bytes: 16896
#include <iostream>
#include <cmath>

#define MAXN 300

using namespace std;

struct {
  int i,j;
} typedef point;

typedef long long ll;

int H,W,D;
point A[MAXN*MAXN+1];
int B[MAXN*MAXN+1];

void cal ( void )
{
  for ( int i = 1; i <= D; ++i ) {
    B[i] = 0;
  }

  for ( int i = D+1; i <= H*W; ++i ) {
    B[i] = abs( A[i].i-A[i-D].i ) + abs(A[i].j-A[i-D].j)+B[i-D];
  }
}

int main()
{
  int Q,l,r;
  cin >> H >>W >> D;

  for ( int i = 1; i <= H; ++i ) {
    for ( int j = 1; j <= W; ++j ) {
      int tmp1;
      scanf("%d", &tmp1);
      A[tmp1] = {i,j};
    }
  }

  cal();

  cin >> Q;
  while(Q--) {
    scanf("%d%d", &l, &r);
    cout << B[r]-B[l] << "\n";
  }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)cin>>a[i];
    sort(a, a+n);
    int mini = a[0];
    int maxi = a[n-1];
    int ans = 0;
    for (int i=0; i<n; i++){
        ans += (a[i]-mini)*(a[i]-mini);
    }

    // int sum  = 0;
    for (int i=mini+1; i<=maxi; i++){
        int sum = 0;
        for (int j=0; j<n; j++){
            sum += (i-a[j])*(i-a[j]);
        }
        if (sum < ans)ans = sum;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    D = []
    short = 0
    count = 0
    for i in range(N):
        now = A[i]-B[i]
        D.append(now)
        if now < 0:
            short += now
            count += 1

    if sum(D)<0:
        print(-1)
        exit()
    
    D.sort(reverse=True)
    
    for i in range(N):
        if short>=0:
            print(count)
            exit()    
        short += D[i]
        count += 1
    print(N)
    

if __name__ == "__main__":
    main()

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

int V, K = 0;
vector<int> G[V_MAX];
int v_min[V_MAX];
bool visited[V_MAX];
map<pair<int, int>, int> mp;

void dfs(int v, int c) {
    visited[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        int t = G[v][i];
        if (visited[t]) continue;
        if (v_min[v] == c) v_min[v]++;
        dfs(t, v_min[v]);
        K = max(K, v_min[v]);

        int s = v;
        if (s > t) swap(s, t);
        mp[make_pair(s, t)] = v_min[v];

        v_min[v]++;
        if (v_min[v] == c) v_min[v]++;
    }
    return;
}

int main() {
    cin >> V;
    vector<pair<int, int>> p(V - 1);
    for (int i = 0; i < V - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
        p[i] = make_pair(a, b);
    }
    fill(v_min, v_min + V_MAX, 1);
    dfs(0, 0);
    cout << K << endl;
    for (int i = 0; i < V - 1; i++) {
        cout << mp[p[i]] << endl;
    }
    return 0;
}

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

#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(var,start,end) for(int var=start; var<end; var++)
#define repr(var,start,end) for(int var=start; var>=end; var--)
#define repi(var,start,end) for(int var=start; var<=end; var++)
#define debg(var) cerr<<#var<<" : "<<var<<" "
#define pb push_back
#define mp make_pair

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

void solve() {
    ull n;
    cin>>n;
    string ans = "";
    string s = "abcdefghijklmnopqrstuvwxyz";
    while(n>0) {
        int d = n%26;
        cerr<<"\nd = "<<d<<" n = "<<n<<'\n';
        if(d==0) {
            d = 26;
            n/=26;
            n--;
        } else {
            n/=26;
        }
        ans+=s[d-1];
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<'\n';

}
int main() {
    fastio
    int t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

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

using namespace std;

int main() {

    long int N, sum=0;
    cin >> N;

    for(int i=1; i<=N; i++) {

        if ((i%3)!=0&&(i%5)!=0) sum+=i;

    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll=long long;
using namespace std;
const int INF = 7+(1e+9);
int main()
{
    int n;cin>>n;
    vector<pair<int,int>> vec;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        vec.push_back(make_pair(x,i));
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
        if(i==n-1){
            cout<<vec[i].second+1;
        }else{
            cout<<vec[i].second+1<<" ";
        }
    }
    cout<<endl;
}

Measured memory_bytes: 1780
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W;
  cin>>H>>W;
  vector<string>S(H+2);
  S[0]=S[H+1]='.'*(W+2);
  for(int i=1;i<H+1;i++){
    string tmp;
    S[i].push_back('.');
    cin>>tmp;
    S[i]+=tmp;
    S[i].push_back('.');
  }
  bool ans=true;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(S[i][j]=='#' && S[i-1][j]=='.' && S[i+1][j]=='.' && S[i][j-1]=='.' && S[i][j+1]=='.'){
        ans=false;
      }
    }
  }
  if(ans){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

int n, m, ans = 0, c;
int b[105] = {0};

int main() {
  cin >> n >> m >> c;
  for(int i = 0; i < m; ++i) cin >> b[i];
  for(int i = 0; i < n; ++i) {
    int now = c;
    for(int j = 0; j < m; ++j) {
      int a;
      cin >> a;
      now += b[j] * a;
    }
    if(now > 0) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int x =sc.nextInt();
     
      System.out.println((x / 3600) + ":" + (x % 3600 / 60) + ":" + (x % 60));
   }
}



Measured memory_bytes: 26184
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    if (args.length > 0 && args(0) == "TEST") {
      println(test())
    } else {
      val input = io.Source.stdin.getLines().mkString("\n")
      println(solve(input).trim())
    }
  }

  def solve(input: String): String = {
    val sc: Scanner = new Scanner(input)
    val n = sc.nextInt
    def pow2(i: Int): Stream[Int] = i #:: pow2(2 * i)
    pow2(1).takeWhile(_ <= n).last.toString
  }

  val tests = List(
    """7""".stripMargin -> """4""",
    """32""".stripMargin -> """32""",
    "1" -> "1",
    "100" -> "64"
  )

  def test(): String = tests.map { case (i, o) => (i.trim(), o.trim()) }
    .zipWithIndex.map {
    case ((input, outputExpect), i) =>
      val output = solve(input).trim()
      val tnum = i + 1
      s"test$tnum:" + (
        if (output == outputExpect) "Passed"
        else s"Failed\nexpect:\n$outputExpect\noutput:\n$output")
  }
    .mkString("\n")
}

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

int main()
{
	int N;
	cin >> N;
	vector<string> s(N);
	vector<int> t(N);
	for (int i = 0; i < N; i++) {
		cin >> s[i] >> t[i];
	}
	string X;
	cin >> X;
	int res = 0;
	bool ok = false;
	for (int i = 0; i < N; i++) {
		if (ok) res += t[i];
		if (s[i] == X) {
			ok = true;
		}
	}
	cout << res << endl;
	return 0;
}


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

void solve() {
  int n, h, w; cin >> n >> h >> w;
  cout << (n - h + 1) * (n - w + 1) << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 3564
from itertools import accumulate

def equalfind(A):#配列中の等しい要素の組をカウント　オーダーはO(NlogN)
    A.sort()
    s=1
    count=0
    if len(A)==1:
        return count
    else:
        for i in range(0,len(A)-1):
            if A[i]==A[i+1]:
                s+=1
            else:
                count+=s*(s-1)//2
                s=1
        return count+s*(s-1)//2

def main():
    N=int(input())
    A=list(map(int,input().split()))
    X=list(accumulate(A))
    s=0
    for i in range(0,len(X)):
        if X[i]==0:
            s+=1
    print(s+equalfind(X))

if __name__ == '__main__':
    main()


Measured memory_bytes: 98896
def chkmax(ecnt):
    emax1=ecnt[0]
    vemax1=0
    if ecnt[1]>emax1:
        emax1=ecnt[1]
        vemax1=1
        emax2=ecnt[0]
    else:
        emax2=ecnt[1]
        
    for i in range(2,len(ecnt)):
        if ecnt[i]>emax1:
            emax2=emax1
            emax1=ecnt[i]
            vemax1=i
        elif ecnt[i]<=emax1 and ecnt[i]>emax2:
            emax2=ecnt[i]
    return emax1,emax2,vemax1    

n=int(input())
v=list(map(int,input().split()))
vmax=max(v)
vmin=min(v)

n2=n//2
ecnt=[0]*(vmax+1)
ocnt=[0]*(vmax+1)
for i in range(n2):
    ecnt[v[i*2]]=ecnt[v[i*2]]+1
    ocnt[v[i*2+1]]=ocnt[v[i*2+1]]+1

if vmax==vmin:
    print(n2)
else:
    emax1,emax2,vemax1=chkmax(ecnt)            
    omax1,omax2,vomax1=chkmax(ocnt)
    if vemax1!=vomax1:
        print(n-emax1-omax1)        
    elif emax1>omax1:
        print(n-emax1-omax2)        
    elif emax1<omax1:
        print(n-omax1-emax2)        
    else:
        if emax2<omax2:
            print(n-emax1-omax2)        
        else:
            print(n-omax1-emax2)        

Measured memory_bytes: 14236
#include <cstdio>
#include <iostream>
#define MN 155

int mod, n, l;
int inc(int a, int b) {return (a += b) >= mod ? a - mod : a;}

int qpow(int x, int p)
{
	if(p < 0) return 1;
	int ans = 1;
	for(; p; p >>= 1, x = 1ll * x * x % mod) if(p & 1) ans = 1ll * ans * x % mod;
	return ans;
}

namespace solve1{
	int f[MN];
	int calc(int n)
	{
		f[0] = 1;
		for(int i = 1; i <= n; i++)
			f[i] = ((2 * f[i - 1] - (i - l / 2 - 2 < -1 ? -1 : (i - l / 2 - 2 < 0 ? 0 : f[i - l / 2 - 2]))) % mod + mod) % mod;
		return f[n] - f[n - 1] + mod;
	}
}

namespace solve2{
	
	int f[MN][MN][MN];
	int calc()	
	{
		f[0][0][0] = 1;
		for(int i = 0; i < (n + 1 >> 1); i++)
			for(int j = 0; j <= l + 1; j++)
				for(int k = 0; k <= l + 1; k++)
				{
					if(!f[i][j][k]) continue;
					if(j && k && j + k >= l + 2) continue;
					if(j)
					{
						f[i + 1][j - 1][std::min(k + 1, l + 1)] = inc(f[i + 1][j - 1][std::min(k + 1, l + 1)], f[i][j][k]);
						f[i + 1][j - 1][0] = inc(f[i + 1][j - 1][0], f[i][j][k]);
						if(j == l + 1 && 2 * (i + 1) - 1 - l + 2 * (j - 1) <= n)
						{
							f[i + 1][j][std::min(k + 1, l + 1)] = inc(f[i + 1][j][std::min(k + 1, l + 1)], f[i][j][k]);
							f[i + 1][j][0] = inc(f[i + 1][j][0], f[i][j][k]);
						}
					}
					else
					{
						if(2 * (i + 1) - 1 - l >= 2)
						{
							for(int o = 1; o <= l + 1; o++)
							{
								if(2 * (i + 1) - 1 - l + 2 * (o - 1) > n) continue;
								f[i + 1][o][std::min(k + 1, l + 1)] = inc(f[i + 1][o][std::min(k + 1, l + 1)], f[i][j][k]);
								f[i + 1][o][0] = inc(f[i + 1][o][0], f[i][j][k]);
							}
						}
						f[i + 1][0][std::min(k + 1, l + 1)] = inc(f[i + 1][0][std::min(k + 1, l + 1)], f[i][j][k]);
						f[i + 1][0][0] = inc(f[i + 1][0][0], f[i][j][k]);
					}
				}
		int ans = 0;
		for(int j = 0; j <= l + 1; j++)
			for(int k = 0; k <= l + 1; k++)
			{
				if(j && k && j + k >= l + 2) continue;
				ans = inc(ans, 1ll * f[(n + 1) >> 1][j][k] * qpow(2, (n - ((n + 1) / 2 * 2 - 1 - l + 2 * j)) / 2) % mod);
			}
		return ans;
	}
}

int main()
{
	scanf("%d%d%d", &n, &l, &mod);
	if(l & 1) printf("%d\n", solve2::calc());
	else printf("%lld\n", 1ll * solve1::calc(n / 2) * solve1::calc(n - n / 2) % mod);
}


Measured memory_bytes: 6656
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,j=0;
    long long a[100005];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    sort(a,a+n);
    for(int i=0;i<n;)
    {
        if(a[i]!=a[i+1])
        {
            i++;
            j++;
        }
        else
            i+=2;
    }
    printf("%d\n",j);
    return 0;
}

Measured memory_bytes: 896
# -*- coding: utf-8 -*-

N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]

INF = 10 ** 9
def f(idx, a, b, c):
    if idx == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF

    ret0 = f(idx + 1, a, b, c)
    ret1 = f(idx + 1, a + l[idx], b, c) + 10
    ret2 = f(idx + 1, a, b + l[idx], c) + 10
    ret3 = f(idx + 1, a, b, c + l[idx]) + 10
    return min(ret0, ret1, ret2, ret3)

print(f(0, 0, 0, 0))


Measured memory_bytes: 3064
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toCharArray.map{it ⇒ it.asDigit}.toList
  println(
    solve(n)
  )
  def solve(cards: List[Int]): Int = {
    cards match {
      case a::b::t ⇒ f(t, a * 10 + b, b)
      case _ ⇒ ???
    }
  }
  def f(cards: List[Int], a: Int, b: Int): Int = {
    cards match {
      case Nil ⇒ Int.MaxValue
      case h::t ⇒ List(f(t, b * 10 + h, h), abs(a * 10 + h - 753)).min
    }
  }
  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}

Measured memory_bytes: 25548
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    ll sum=0;
    rep(i,k){
        sum+=a[i];
    }
    cout<<sum<<endl;
}


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

int main(){
    string str;
    cin >> str;
    int n = str.back() - '0';
    if(n == 3){
        cout << "bon\n";
    }
    else if(n == 0 || n == 1 || n == 6 || n == 8){
        cout << "pon\n";
    }
    else {
        cout << "hon\n";
    }
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    vector<int> d(n);


    for(int i=0; i < n; i++){
        d.at(i) = a[i+1] - a[i];
        if(i == n - 1) d.at(i) = a.at(0) + k - a.at(n-1);
    }

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

    cout << k - d.at(n-1) << endl;
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> l(m),r(m);
  rep(i,m) cin>>l[i]>>r[i];
  /////全てのl〜rに共通する数字の個数
  int ans=0;
 int  mx=1000000;int mn=0;
 rep(i,m){
    
      mx=min(r[i],mx);
   
     mn=max(l[i],mn);
   
 }
  ans=mx-mn+1;
  if(ans>0)
  cout<<ans<<endl;
  else cout<<0<<endl;
}







Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, h, w;
    cin >> n >> h >> w;

    int total = 0;
    for (int i=0; i < n; ++i){
        int a, b;
        cin >> a >> b;

        if (a >= h && b >= w) {
            ++total;
        }
    }

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    
    vector<string> vec(N);
    cin >> vec[0];
    for (int i=1;i<N;i++){
        cin >> vec[i];
        
            if(vec[i][0]!=vec[i-1][vec[i-1].size()-1]){
            cout <<"No"<<endl;
            return 0;
            }
        
        for(int k=0;k<i;k++){
            if(vec[i]==vec[k]){
                cout << "No"<<endl;
                return 0;
            }
        }
    }
     cout << "Yes"<<endl;
     
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];
        
        for(int i = 0; i < N; i++){
            x[i] = sc.nextInt();
        }
        
        long ans = Long.MAX_VALUE;
        for(int l = 0; l < N; l++){
            int r = l+K-1;
            if( r >= N ) break;
            if( l-1 >= 0 && x[l-1] > 0 ) break;
            if( r+1 < N && x[r+1] < 0 ) continue;
            
            long kyori = Long.MAX_VALUE;
            if( x[l] <= 0 && x[r] >= 0 ){
                kyori = Math.min(Math.abs(x[l]*2)+x[r], Math.abs(x[l])+x[r]*2);
            } else {
                kyori = Math.max(Math.abs(x[l]), Math.abs(x[r]));
            }
            
            ans = Math.min(ans, kyori);
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 49808
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main()
{
	int n, w, k;
	cin>>n>>w>>k;
	long long dp[105][9];
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1;
	if(w == 1)
	{
		cout<<1<<endl;
		return 0;
	}
	bool out = false;
	for(int i =0;i<n;i++)
	{ 
		for(int b = 0; b < (1<<(w-1));b++){
            out = 0;
            for(int m = 0; m <w-2;m++){
                if ((1<<m)&b && (1<<(m+1))&b) out = 1;
            }
            if (out) continue;
            for(int m = 0; m <w-1;m++){
                if ((1<<m)&b){
                    dp[i+1][m] += dp[i][m+1] % mod;
                    dp[i + 1][m] %= mod;
                    dp[i+1][m+1] += dp[i][m] % mod;
                    dp[i+1][m + 1] %=mod;
                }
                if (m == 0 && !((1<<m)&b)){
                    dp[i+1][0] += dp[i][0] % mod;
                    dp[i + 1][0] %=mod;
                }
                if (m == w-2 && !((1<<m)&b)){
                    dp[i+1][w-1] += dp[i][w-1] % mod;
                    dp[i + 1][w-1] %=mod;
                }
                if (m != w-2 && !((1<<m)&b) && !((1<<(m+1))&b)){
                    dp[i+1][m+1] += dp[i][m+1] % mod;
                    dp[i+1][m+1] %= mod;
                }
            }
        }
	}
	cout<<dp[n][k-1] % mod<<endl;
}

Measured memory_bytes: 256
for i in range(int(input())):
    x1, y1, x2, y2, x3, y3, x4, y4 = [float(x) for x in input().split()]
    s1 = round((y2 - y1) / (x2 - x1), 10) if x1 != x2 else float('inf')
    s2 = round((y4 - y3) / (x4 - x3), 10) if x3 != x4 else float('inf')
    
    print("YES" if s1 == s2 else "NO")



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

int main() {
  int n,c;
  cin>>n>>c;
  vector<vector<int>> a(c,vector<int>(c));
  rep(i,c) {
    rep(j,c){
      cin >> a.at(i).at(j);
    }
  }
  vector<vector<int>> b(n,vector<int>(n));
  vector<vector<int>> d(c,vector<int>(3));
  rep(i,n) {
    rep(j,n){
      cin >> b.at(i).at(j);
      b.at(i).at(j)--;
      d[b.at(i).at(j)][(i+j)%3]++;
    }
  }
  int ans=1001001001;
  rep(i,c){
    rep(j,c){
      rep(k,c){
        if(i!=j&&j!=k&&k!=i){
          int now=0;
          rep(x,c){
            now+=d[x][0]*a[x][i];
            now+=d[x][1]*a[x][j];
            now+=d[x][2]*a[x][k];
          }
          ans=min(ans,now);
        }
      }
    }
  }
  cout<<ans<<endl;  
}



Measured memory_bytes: 4580
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;


int main(int argc, char* argv[])
{
    int n,m;
    scanf("%d%d", &n, &m);
    if(n==m) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }


    return 0;
}


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

int main(){
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if((x-r)>=0 && (x+r)<=w && (y-r)>=0 && (y+r)<=h)
        cout << "Yes" <<endl;
    else
        cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

int main() {
	int l,r,d,k = 0, n, a[100] = { 0 }, ans = 0;
	char s[3], cas[4][4] = {"AC","WA","TLE","RE"};
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0 && a[i] % 2 == 1)ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#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 MAX 3000
typedef long long ll;
using namespace std;

int main(void){
  int n;  cin>>n;
  int a, ans=0;
  rep(i, n){
    cin >> a;
    ans += (a-1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=500005;

int N,K,A[MAXN];
int pos[MAXN];
vector<int> adj[MAXN];
set<int> L,R; //L存储pos上，比当前数小，绝对值差<K的下标；R存储比当前数大的下标
priority_queue<int,vector<int>,greater<int> > Q;
vector<int> stk;
int pri[MAXN];
int deg[MAXN];

int main()
{
    scanf("%d%d",&N,&K);
    for(int i=1;i<=N;i++)
        scanf("%d",&A[i]),pos[A[i]]=i;
    for(int i=1;i<=K;i++)
        R.insert(A[i]);
    set<int>::iterator x,y;
    for(int i=1;i<=N;i++)
    {
        x=L.upper_bound(A[i]);
        y=R.upper_bound(A[i]);
        if(x!=L.end())
        {
            adj[i].push_back(pos[*x]);
            deg[pos[*x]]++;
        }
        if(y!=R.end())
        {
            adj[i].push_back(pos[*y]);
            deg[pos[*y]]++;
        }
        L.insert(A[i]);
        if(i-K+1>0)
            L.erase(A[i-K+1]);
        if(i+K<=N)
            R.insert(A[i+K]);
        R.erase(A[i]);
    }

    for(int i=1;i<=N;i++)
        if(deg[i]==0)
            Q.push(i);
    while(!Q.empty())
    {
        int u=Q.top();
        Q.pop();
        stk.push_back(u);
        for(int i=0;i<(int)adj[u].size();i++)
        {
            deg[adj[u][i]]--;
            if(deg[adj[u][i]]==0)
                Q.push(adj[u][i]);
        }
    }
    for(int i=0;i<N;i++)
        pri[stk[i]]=i+1;
    for(int i=1;i<=N;i++)
        printf("%d\n",pri[i]);

    return 0;
}




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

int n;

void dfs(string s, char mx) {
	if (s.length() == n) {
    	cout << s.c_str() << '\n'; 
    }
  	else {
    	for (char c = 'a'; c <= mx; ++c) {
        	dfs(s + c, ((c == mx) ? (char) (mx + 1) : mx)); 
        }
    }
}

int main() {
	cin >> n;
  	dfs("", 'a');
}

Measured memory_bytes: 1536
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>

int solve(int n, std::vector<int>& values)
{
  std::sort(values.begin(), values.end());
  const auto max = values.back();

  std::vector<int> is_divisibles(max + 1, -1);

  for (auto v : values) {
    if (is_divisibles[v] == 1) continue;
    if (is_divisibles[v] == 0) {
      is_divisibles[v] = 1;
      continue;
    }
    is_divisibles[v] = 0;
    for (int x = v + v; x <= max; x += v) {
      is_divisibles[x] = 1;
    }
  }

  int result = 0;
  for (auto v : values) {
    if (is_divisibles[v] == 0) ++result;
  }
  return result;
}

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> values(n);
  for (auto& v : values) {
    std::cin >> v;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, values) << std::endl;
}


Measured memory_bytes: 7948
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=805;
int n,m,K,qx[N*N],qy[N*N];
const int mx[ ]={1,-1,0,0};
const int my[ ]={0,0,1,-1};
int d[N][N];char s[N][N];
inline void BFS(int sx,int sy)
{
  int i,j,x,y,xx,yy,h=1,t=1,ans=1e9;
  qx[1]=sx;qy[1]=sy;d[sx][sy]=1;
  while(h<=t)
    {
      x=qx[h];y=qy[h++];
      if(d[x][y]>K) break;
      for(i=0;i<=3;i++)
	{
	  xx=x+mx[i];yy=y+my[i];
	  if(xx>n||xx<1||yy>m||yy<1||s[xx][yy]=='#'||d[xx][yy]) continue;
	  d[xx][yy]=d[x][y]+1;qx[++t]=xx;qy[t]=yy;
	}
    }
  for(i=1;i<=t;i++)
    {
      x=qx[i];y=qy[i];
      j=min(min(x-1,n-x),min(y-1,m-y));
      ans=min(ans,j);
    }
  printf("%d",(ans/K)+(ans%K!=0)+1);
}
int main( )
{
  int i,j;
  n=read( );m=read( );K=read( );
  for(i=1;i<=n;i++) scanf("%s",s[i]+1);
  for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
      if(s[i][j]=='S') {BFS(i,j);break;}
  return 0;
}

Measured memory_bytes: 8448