akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    #約数列挙
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)

        divisors.sort(reverse=True)
        return divisors
    mod=10**9+7
    N,K=MI()
    A=LI()
    S=sum(A)
    
    div=make_divisors(S)
    N2=len(div)
    
    ans=1
    for g in div:
        L=[0]*N
        for i in range(N):#とりあえず，マイナス分だけ考えて，全部gの倍数に寄せる
            diff=A[i]%g
            L[i]=diff
        S=sum(L)
        L.sort(reverse=True)
        
        #ここから足していく
        cost=0#かかった手数
        ii=0#Lの大きい順に見ていく
        while S!=0:#プラスとマイナスで合計が0になるようにする
            b=g-L[ii]
            cost+=b
            S-=g#g*1だけ合計値をあげたから
            ii+=1
        # print(g,L,cost)
            
        if cost<=K:
            ans=g
            break
        
    print(ans)

    
    
    

main()


Measured memory_bytes: 74256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string S;

	cin >> S;

	if (S == "Sunny") cout << "Cloudy";
	else if (S == "Cloudy") cout << "Rainy";
	else if (S == "Rainy") cout << "Sunny";

	cout << endl;

	return 0;
}

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

int main() {
    long double a,b,x;
    cin>>a>>b>>x;
    long double radian=0;
    long double degree = 0;
    if(x >= a*a*b/2){
        radian = atan2l(2*(a*a*b-x),a*a*a);
        degree = radian * 180.0 / PI;
        
    }else{
        radian = atan2l(2*x, a*b*b)* 180.0;
        degree = 90- radian / PI;
    }

    cout<< setprecision(12) <<degree <<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String inputs[] = str.split(" ");
		int h = Integer.parseInt(inputs[0]);
		int w = Integer.parseInt(inputs[1]);
		char table[][] = new char[h][w];
		for (int i = 0; i < h; i++) {
			String tmp = br.readLine();
			for (int j = 0; j < w; j++) {
				table[i][j] = tmp.charAt(j);
			}
		}
		if (resolution(table)) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}

	public static boolean resolution(char table[][]) {
		for (int i = 0; i < table.length; i++) {
			for (int j = 0; j < table[0].length; j++) {
				if (table[i][j] != '#') {
					continue;
				}
				if (i != 0 && table[i - 1][j] == '#') {
					continue;
				}
				if (j != 0 && table[i][j - 1] == '#') {
					continue;
				}
				if (i != table.length - 1 && table[i + 1][j] == '#') {
					continue;
				}
				if (j != table.length - 1 && table[i][j + 1] == '#') {
					continue;
				}
				return false;
			}
		}
		return true;
	}

}


Measured memory_bytes: 23380
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int Max = 0;
    int now = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'I') now++;
        else now--;
        Max = max(now, Max);
    }
    cout << Max << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();

        if (N - K < 0) {
            System.out.println(N * X);
        } else {
            System.out.println(K * X + (N - K) * Y);
        }
    }
}

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

int main(){
  int n;cin>>n;
  int ans = 0;
  rep(i,(n+1)/2){
    int a=2*i+1;
    int b=0;
    rep(j,a){
      if(a%(j+1)==0)b ++;
    }
    if(b==8)ans ++;
  }
  cout << ans;
}
      

Measured memory_bytes: 256
# 足す時は0~iまで一律に足し、返すのはi番目の値
class imosBIT():
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(self.N+1)]
    
    def __str__(self):
        ret = []
        for i in range(1, self.N+1):
            ret.append(self.__getitem__(i))
        return "[" + ", ".join([str(a) for a in ret]) + "]"

    def __getitem__(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.N:
            self.bit[i] += x
            i += i & -i


import sys
input = sys.stdin.readline

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

l = 0
r = max(A) + 1
while r-l > 1:
    x = (l+r)//2
    P = [0]
    for a in A:
        p = +1 if a >= x else -1
        P.append(P[-1]+p)
    score = 0
    bit = imosBIT(2*N+5)
    for p in P:
        p += N+1
        score += bit[p]
        bit.add(p, 1)
    
    if score >= (N*(N+1)//2+1)//2:
        l = x
    else:
        r = x

print(l)

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

int main(){
  string S, T;
  cin >> S >> T;

  int N = S.length();

  // Sの文字iはTの文字A[i]に対応, Tの文字ｊはSの文字B[j]に対応
  vector<int> A(26, -1), B(26, -1); 
  for(int i=0; i<N; i++){
    int s = S[i] - 'a', t = T[i] - 'a';
    if(A[s] == -1 && B[t] == -1){
      A[s] = t; B[t] = s;
    } else {
      if (A[s] != t || B[t] != s){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
} 

Measured memory_bytes: 776
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
bestH = (T - A) / 0.006
d = float('inf')
ans = 0
for i in range(N):
    if d > abs(H[i] - bestH):
        d = abs(H[i] - bestH)
        ans = i + 1
print(ans)


Measured memory_bytes: 3060
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
	int n,k;
	cin >> n;
	rep(i, n+1){
		rep(j,n+1){
			if(i*7+j*4==n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define P pair<int,int>
#define MAX_N 200002
using namespace std;

ll n;
ll p[MAX_N];

int main(){
    cin>>n;
    for(int i = 1; i<=n; i++){
        cin>>p[i];
    }
    ll min_p = p[1];
    int cnt = 1;
    
    for(int i = 2; i <=n; i++){
        if(p[i] <= min_p){
            cnt++;
            min_p = p[i]; 
        }
    }
    
    cout<< cnt <<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 1000000007
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define sz(x) int(x.size())
int main(){
	int n;
	cin>>n;
	vector<int> bn(n);
	ll sum=0;
	rep(i,n-1){
	cin>>bn.at(i);
	
	}
	sum+=bn.at(0);
	for(int i=0;i<n-1;i++){
		sum+=min(bn.at(i),bn.at(i+1));
	}
	sum+=bn.at(n-2);
	cout<<sum<<endl;
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a > b) a = b; }
template<class T> void chmin(T& a, T b) { if(a < b) b = a; }
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    map<int, int> ma;
    REP2(i, 1, n) ma[i] = 0;

    rep(i, n){
        int k; cin >> k;
        rep(j, k){
            int a; cin >> a;
            ma[a]++;
        }
    }

    int ans = 0;
    REP2(i, 1, m){
        if(ma[i] == n) ans++;
    }
    OP(ans);
}


Measured memory_bytes: 256
# -*- using utf8 -*-
import sys
inputlinevec = sys.stdin.readline().strip().split(' ')
n = int(inputlinevec[0])
x = int(inputlinevec[1])
m = int(inputlinevec[2])

sum_res = x
crcle_dict = dict()
crcle_list = list()
crcle_idx = 0
pre_a = x

for idx in range(1, n):
    #a范围在0-m之间，不会无限递增，因此很大概率会重复
    #a * a % m这种单变量的式子，一旦a出现了之前出现过的值
    #后续就会出现重复的序列，然后循环
    this_a = (pre_a * pre_a) % m
    pre_a = this_a
    
    if this_a not in crcle_dict:
        crcle_dict[this_a] = 1
        crcle_list.append(this_a)
        sum_res = sum_res + this_a
    else:
        crcle_step = len(crcle_list) - crcle_list.index(this_a)
        remain_crcle = int((n - idx) / crcle_step)
        remain_crcle_tail = int((n - idx) % crcle_step)
        
        crcle_sum = 0
        crcle_sum_tail = 0
        for a_item in crcle_list[crcle_list.index(this_a):]:
            crcle_sum = crcle_sum + a_item
            remain_crcle_tail = remain_crcle_tail - 1
            if remain_crcle_tail == 0:
                crcle_sum_tail = crcle_sum
        sum_res = sum_res + (remain_crcle * crcle_sum) + crcle_sum_tail
        break
    
print(sum_res)


Measured memory_bytes: 14204
import numpy as np
l_input = [int(e) for e in input().split()]
N = l_input[0]
K = l_input[1]
result = [N%K]
for i in range(1000000000000000000000000000000):
    result.append(abs(result[i]-K))
    ans = result[i+1] in result
    if result[i+1] < K/2:
        break
print(min(result))

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

int main() {
  int K;
  string S;
  cin >> K;
  cin >> S;
  if(S.size()<=K){ cout << S << endl; }
  else {
   for(int i = 0;i<K;i++){
    cout << S.at(i);
   }
   cout << "..." << endl; 
  }
  return 0;
}


Measured memory_bytes: 3628
import itertools

N, M = map(int, input().split())
adj_matrix = [[0]*N for _ in range(N)]

# 隣接行列を作る
for i in range(M):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0

for each in itertools.permutations(range(N)):
    if each[0] != 0:  # 始点は1でないといけないから
        break
    factor = 1
    for i in range(N-1):
        factor *= adj_matrix[each[i]][each[i+1]]
    cnt += factor

print(cnt)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long a = in.nextLong();
        long b = in.nextLong();
        out.println(a * b / gcd(a, b));

    }

    private long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer      tokenizer;

    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
using namespace std;
const int MAXN = 5010;
const ll INF = numeric_limits<ll>::max();
int n, k;
ll p[MAXN], c[MAXN], t[MAXN], d[MAXN], md[MAXN];
void work() {
  scanf("%d%d", &n, &k);
  int now;
  for(reg int i = 1; i <= n; ++i) scanf("%lld", &p[i]);
  for(reg int i = 1; i <= n; ++i) scanf("%lld", &c[i]);
  for(reg int i = 1; i <= n; ++i) {
    now = p[i];
    d[i] = c[now], t[i] = 1, md[i] = -INF;
    md[i] = max(md[i], d[i]);
    while(now != i) {
      ++t[i], now = p[now], d[i] += c[now];
      md[i] = max(md[i], d[i]);
    }
  }
  ll ans = -INF, tmp;
  int cnt = 0;
  for(reg int i = 1; i <= n; ++i) {
    if(k / t[i] > 0) {
      ans = max(ans, md[i]);
      if(k % t[i] == 0) {
        ans = max(ans, (k / t[i] - 1) * d[i] + md[i]);
        continue;
      }
    }
    tmp = k / t[i] * d[i], now = p[i], tmp += c[now];
    ans = max(ans, tmp), cnt = 1;
    while(k % t[i] != cnt) {
      ++cnt, now = p[now], tmp += c[now];
      ans = max(ans, tmp);
    }
  }
  printf("%lld\n", ans);
}
signed main() {
  int _ = 1;
  // scanf("%d", &_);
  while(_--) {
    work();
  }
  return 0;
}



Measured memory_bytes: 4004
#include<bits/stdc++.h>
#include<cassert>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds; 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define inf INT_MAX
#define llinf LONG_LONG_MAX

const int MAXN=2e6+1;
const int M=1e9+7;
const int N=6e6+6;

void solve(){
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;


	vector<ll> v1(a),v2(b);

	multiset<ll> s1,s2;

	f(i,0,a){
		cin>>v1[i];
		s1.insert(v1[i]);
	}

	f(i,0,b){
		cin>>v2[i];
		s2.insert(v2[i]);
	}

	while(s1.size()>x){
		s1.erase(s1.begin());
	}

	while(s2.size()>y){
		s2.erase(s2.begin());
	}

	multiset<ll> s;

	f(i,0,c){
		ll temp;
		sfl(temp)
		s.insert(-1ll*temp);
	}

	while(!s.empty() && (-1ll**s.begin())>min(*s1.begin(),*s2.begin())){
		//cout<<"**"<<endl;
		if(*s1.begin()<*s2.begin()){
			s1.erase(s1.begin());
			s1.insert(-1ll*(*s.begin()));
			s.erase(s.begin());
		}
		else{
			s2.erase(s2.begin());
			s2.insert(-1ll*(*s.begin()));
			s.erase(s.begin());
		}
	//	cout<<*s.begin()<<" "<<*s1.begin()<<" "<<*s2.begin()<<endl;
	}

	ll ans=0;

	for(ll x: s1){
		ans+=x;
		//cout<<x<<" ";
	}
	//cout<<endl;
	for(ll y: s2){
		ans+=y;
		//cout<<y<<" ";
	}

	pfln(ans)


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

Measured memory_bytes: 14976
#include <stdio.h>

int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a < b){
		int t = a;
		a = b;
		b = t;
	}
	if(a - b >= 1) printf("%d",a * 2 - 1);
	else printf("%d",a + b);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
typedef pair<ll, ll> P;

const int MAXN = 1e5 + 10;

int main(){
    ll N, C; cin >> N >> C;
    ll ans = 0;
    vector<ll> x(N+2,0), v(N+2,0);
    rep(i, N) cin >> x[i+1] >> v[i+1];
    x[N+1] = C;

    ll dpr1[MAXN], dpl1[MAXN], dpr2[MAXN], dpl2[MAXN];
    //vector<ll> right(N+1,0), left(N+1, 0);
    vector<ll> right1(N+1, 0), left1(N+1, 0), right2(N+1,0), left2(N+1,0);
    rep(i, N){
        right1[i+1] = right1[i] + v[i+1] - (x[i+1] - x[i]);
        right2[i+1] = right2[i] + v[i+1] - 2 * (x[i+1] - x[i]);
        left1[i+1] = left1[i] + v[N - i] - (x[N+1-i] - x[N-i]);
        left2[i+1] = left2[i] + v[N - i] - 2 * (x[N+1-i] - x[N-i]);
    }
    rep(i, N){
        dpr1[i+1] = max(dpr1[i], right1[i+1]);
        dpl1[i+1] = max(dpl1[i], left1[i+1]); 
        dpr2[i+1] = max(dpr2[i], right2[i+1]); 
        dpl2[i+1] = max(dpl2[i], left2[i+1]); 
    }
    for(int i = 0; i <= N; i++){
        ans = max(ans, dpr1[i] + dpl2[N-i]);
        ans = max(ans, dpl1[i] + dpr2[N-i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

int main()
{
	char c[3] ;
	scanf ("%s", c) ;
	
	int ans = 0 ;
	char bf = c[0] ;
	if (c[0] == 'R')
		ans = 1 ;
	
	for (int i=1; i<3; i++)
	{
		if (c[i] == 'R')
		{
			if (ans == 0 || c[i] == bf)
				ans++ ;
		}
		
		bf = c[i] ;
	}
	
	cout << ans << endl ;

	return 0 ;
}

Measured memory_bytes: 3244
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];for(int i=0;i<N;i++) {}
		//Ae2+Be2=Ce2
		//StringBuffer str = new StringBuffer(hoge1);
		//for(int i=0;i<N;i++) {}
		
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int N=sc.nextInt();
		int a[]=new int[N];
		int sum=0;
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		sum/=N;
		int tmp=0;
		int ans=10000009;
		//p(sum);
		//sum
		for(int i=0;i<N;i++) {
			tmp+=(sum-a[i])*(sum-a[i]);
		}
		ans=Math.min(ans, tmp);
	
		sum-=1;
		tmp=0;
		for(int i=0;i<N;i++) {
			tmp+=(sum-a[i])*(sum-a[i]);
		}ans=Math.min(ans, tmp);
		
		sum+=2;tmp=0;
		for(int i=0;i<N;i++) {
			tmp+=(sum-a[i])*(sum-a[i]);
		}ans=Math.min(ans, tmp);
		
		p(ans);
	}
	
		
	
	
		
	
	public static long modPow(long g,long N) {
		long T=1;
		for(int i=0;i<N;i++) {
			T*=g;
			T%=mod;
		}
		return T;
	}
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
  	Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    String res = "";
    
    if (r < 1200) {
      res = "ABC";
    } else if (r < 2800) {
      res = "ARC";
    } else {
      res = "AGC";
    }
    
    System.out.println(res);
  }
}

Measured memory_bytes: 21844
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n + 1];
		boolean[] check = new boolean[n + 1];
		Arrays.fill(check, true);
		for(int i = 1; i <= n; i++) {
			arr[i] = sc.nextInt();
		}
		for(int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(arr[a] > arr[b])
				check[b] = false;
			else if(arr[a] < arr[b])
				check[a] = false;
			else {
				check[a] = check[b] = false;
			}
		}
		int res = 0;
		for(int i = 1; i <= n; i++) {
			if(check[i])
				res++;
		}
		System.out.println(res);
    }
}

Measured memory_bytes: 60052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int maxn=1e6+10;
int n,a[maxn],sum[maxn],v[maxn],k=2,ans;
char s[maxn];
int main()
{
	scanf("%d%s",&n,s+1);
	for (int i=1;i<=n;i++)
	{
		a[i]=s[i]-'1';
		if (a[i]==1) k=1;
	}
	for (int i=1;i<=n;i++)
	{
		v[i]=(i&1?0:v[i/2]+1);
		sum[i]=sum[i-1]+v[i];
	}
	for (int i=1;i<=n;i++)
	if (sum[n-1]==sum[i-1]+sum[n-i]) ans=(ans+a[i]/k)%2;
	printf("%d\n",ans*k);
return 0;
}

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

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

  int N, M, C;
  cin >> N >> M >> C;
  int B[M];
  REP(i, M) cin >> B[i];
  int A[N][M];
  REP(i, N) REP(j, M) cin >> A[i][j];
  int ans = 0;

  for(int i = 0; i < N; i++) {
    int sum = 0;
    for(int j = 0; j < M; j++) {
      sum += A[i][j] * B[j];
    }
    sum += C;
    if(sum > 0) {
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n  = sc.nextInt();
        int res = 0;

        for(int i=1; i<=n; i++) {
            int l = Integer.toString(i).length();
            if(l % 2 == 1) res ++;
        }
        System.out.println(res);

    }


}


Measured memory_bytes: 28500
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;
        var p = io.Is(n).ToList();

        if (n % 2 != 0) { n++; p.Add(-1); }

        var t = new bool[n];
        for (var i = 0; i < n; i++) t[i] = p[i] == i + 1;
        var ans = 0;

        for (var i = 0; i < n; i++)
        {
            if (i == n - 1) { if (t[i]) ans++; break; }
            if (t[i] && !t[i + 1]) { ans++; i++; }
            if (t[i] &&  t[i + 1]) { ans++; i++; }
        }

        io.Write(ans);
    }
}

Measured memory_bytes: 21984
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}
//////////////
vector<vector<pair<int,int>>>G;
void bai() {
	int len = G.size();
	for (int i = 0; i < len; ++i) {
		int N = G[i].size();
		for (int j = 0; j < N; ++j) {
			G[i][j].second *= 2;
		}
	}
}
void solve() {
	int L;
	cin >> L;
	int N = 2;
	int E = 2;
	
	G.push_back({pair<int,int>(1,0),pair<int,int>(1,1)});
	G.push_back({});
	vector<int>A;
	int temp = L;

	while (temp) {
		if (temp & 1) {
			A.push_back(1);
		}
		else {
			A.push_back(0);
		}
		temp /= 2;
	}
	reverse(A.begin(), A.end());
	int len = A.size();
	int base = 2;
	int S = 0;
	int T = 1;
	
	for (int i = 1; i < len; ++i) {
		if (A[i] == 1) {
			G[S].push_back(pair<int, int>(T, base));
			E++;
			
			base += 1;
		}
		base *= 2;
		
		if (i + 1 < len) {
			bai();
			G[T].push_back(pair<int, int>(T + 1, 0));
			G[T].push_back(pair<int, int>(T + 1, 1));
			G.push_back({});
			T = T + 1;
			N++;
			E += 2;
		}
	}
	
	cout << N << " " << E << endl;
	for (int i = 0; i < N; ++i) {
		int len = G[i].size();
		for (int j = 0; j < len; ++j) {
			cout << i + 1 << " " << G[i][j].first + 1 << " " <<
				G[i][j].second << endl;
		}
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
strArr = input().split()
numArr = input().split()
nums = [int(s) for s in numArr]
which = input()
if (which == strArr[0]):
  print(str(nums[0] - 1) + " " + str(nums[1]))
else:
  print(str(nums[0]) + " " + str(nums[1] - 1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> P[100010];
int depth[100010];
int parent[30][100010];//parent[いくつ上の階層か][ノード]
int root;

void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0; i<P[v].size(); i++){
    if(P[v][i]!=p){
        dfs(P[v][i], v, d+1);
    }
  }
}
void init(int V){
  dfs(root, -1, 0);
  for(int k=0; k+1<30; k++){
    for(int v=0; v<V; v++){
      if(parent[k][v]<0) parent[k+1][v]=-1;
      else parent[k+1][v]=parent[k][parent[k][v]];
    }
  }
}

int lca(int u, int v){
    if(depth[u]>depth[v]) swap(u,v);//根から遠い位置にある方をvにする
    for(int k=0; k<30; k++){
        //cout << "k=" << k << "\n";
        //cout << "depth["<<v<<"], depth["<<u<<"]="<<depth[v]<<" "<<depth[u]<<"\n";
        if((depth[v]-depth[u])>>k&1){//深さはいくつ違うのか
            v=parent[k][v];
            //cout << v <<"\n";
        }
        if(u==v) return u;
    }
    for(int k=29; k>=0; k--){
        if(parent[k][u]!=parent[k][v]){
            u=parent[k][u];
            v=parent[k][v];
            //cout << "u, v=" << u <<", " << v <<"\n";
        }
    }
    return parent[0][u];
}

int main(){
  root=0;
  cin >> n;
  int k, c;
  for(int i=0; i<n; i++){
      cin >> k;
      while(k--){
          cin >> c;
          P[i].push_back(c);
      }
  }
  init(n);
  int q;
  cin >> q;
  while(q--){
      //cout << "----------------" <<"\n";
      int u, v;
      cin >> u >> v;
      cout << lca(u, v) << "\n";
  }
}


Measured memory_bytes: 26816
a, b, k = map(int, input().split())

for i in range(1,k+1):
	
	if i % 2 == 0:
		if b % 2 != 0:
			b -= 1
		c = int(b/2)
		b -= c
		a += c
	else:
		if a % 2 != 0:
			a -= 1
		c = int(a/2)
		a -= c
		b += c

print(str(a) + " " + str(b))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		ll a;
		cin >> a;
		cout << a + a*a + a*a*a << "\n";
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

signed main() {
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  if (((__int128_t)k) * ((__int128_t)d) <= (__int128_t)x) {
    cout << (x - k * d) << endl;
    return 0;
  }

  ll mv = x / d;
  x -= mv * d;
  k -= mv;
  k %= 2;
  if (k) x = abs(x - d);
  cout << x << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 200100;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] > i) {
            cout << -1;
            return 0;
        }
    }
    ll ans = a[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        if (a[i] + 1 < a[i + 1]) {
            cout << -1;
            return 0;
        }
        if (a[i] >= a[i + 1]) {
            ans += a[i];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
from collections import deque
n, m = map(int, input().split())
edges = [[] for i in range(3*n)]
for i in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append(v+n)
    edges[u+n].append(v+2*n)
    edges[u+2*n].append(v)

s,t = map(int, input().split())
s -= 1
t -= 1
INF = 1<<50
dists = [INF] * (3*n)

q = deque([])
q.append(s)
dists[s] = 0

while len(q)>0:
    v = q.popleft()
    for u in edges[v]:
        if dists[u] != INF: continue
        q.append(u)
        dists[u] = dists[v] + 1

if dists[t] == INF:
    print(-1)
else:
    print(dists[t]//3)


Measured memory_bytes: 61372
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(void){
    
    string s;
    cin >> s;

    for(int bit = 0; bit < 8; bit++){
        int sum = (int)(s[0] - '0');
        for(int i = 0; i < 3; i++){
            if(bit & (1 << i)){
                sum += (int)(s[i+1] - '0');
            }else{
                sum -= (int)(s[i+1] - '0');
            }
        }

        if(sum == 7){
            cout << s[0];
            for(int i = 0; i < 3; i++){
                if(bit & (1 << i)){
                    cout << '+';
                }else{
                    cout << '-';
                }
                cout << s[i+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
from collections import deque


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    que = deque()
    for i, a in enumerate(A):
        if (i + 1) % 2 == 1:
            que.append(a)
        else:
            que.appendleft(a)
    ans = list(que)
    if N % 2 == 1:
        ans.reverse()
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 30784
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
using namespace std;
const int mod=1e9+7;
const int MAX=1e6+7;
// ll a[MAX];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);
    ll a;
	cin>>a;
	cout<<a+a*a+a*a*a; 
    
    return 0;
}


Measured memory_bytes: 3584
from itertools import permutations

def main():
    n = int(input())
    s = input()
    res = 0
    r = 0
    g = 0
    b = 0
    for i, c in enumerate(s):
        if c == 'R':
            r += 1
        elif c == 'G':
            g += 1
        else:
            b += 1
    
    rgb = []
    for t in permutations('RGB'):
        rgb.append(''.join(t))

    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            k = 2*j - i 
            if k >= n:
                break
            if (s[i] + s[j] + s[k]) in rgb:
                cnt += 1
    print(r*g*b - cnt)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9228
#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;

int main() {
  int n;
  cin>>n;
  int a[200005];
  rep(i,n) cin>>a[i];
  int now=1,ans=0;
  rep(i,n){
    if(a[i]==now){
      now++;
    }
    else{
      ans++;
    }
  }
  if(now==1) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include"iostream"
#include"vector"
#include"algorithm"
using namespace std;

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

	long ans = 2*x[n-1]-2*x[0];
	for (int i = 0; i < n - k + 1; i++)
	{
		if (x[i] < 0 && x[i + k - 1] < 0)
		{
			ans = min({ ans,abs(x[i]) });
		}
		else if (x[i] > 0 && x[i + k - 1] > 0)
		{
			ans = min({ ans,abs(x[i + k - 1]) });
		}
		else
		{
			ans = min({ ans,2 * x[i + k - 1] - x[i],x[i + k - 1] - 2*x[i] });
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
s = input()

if not 'R' in s:
    print(0)
    quit()

wn = [0] * n
if s[0] == 'W':
    wn[0] = 1
for i in range(1, n):
    wn[i] = wn[i-1]
    if s[i] == 'W':
        wn[i] += 1
rn = [0] * n
if s[-1] == 'R':
    rn[-1] = 1
for i in range(n-2, -1, -1):
    rn[i] = rn[i+1]
    if s[i] == 'R':
        rn[i] += 1
rn.append(0)
min_val = n
for i in range(n):
    m = max(wn[i], rn[i+1])
    if min_val > m:
        min_val = m
print(min_val)



Measured memory_bytes: 72832
# -*- coding: utf-8 -*-
from itertools import product, accumulate
from math import gcd
from bisect import bisect
import sys
from sys import setrecursionlimit
setrecursionlimit(10**9)
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
def ask(p, q):
    print("? {} {}".format(p, q), end="\n", flush=True)
    return int(input())

N, s, t = inpl()
X = ask(s, t)
L = [0, X]
LD = {0: s}
LD[X] = t
ans = [s, t]

for p in range(1, N+1):
    if (p == s) or (p == t):
        continue
    l = ask(s, p)
    r = ask(p, t)
    if (l*r < 0) or (l+r != X):
        continue
    ai = bisect(L, l) - 1
    av = L[ai]
    ak = LD[av]
    if av == l:
        continue
    bv = L[ai+1]
    bk = LD[bv]

    dl = ask(ak, p)
    dr = ask(p, bk)
    if av + dl + dr + (X-bv) == X:
        LD[l] = p
        ans.insert(ai+1, p)
        L.insert(ai+1, l)

print("! " + " ".join(map(str, ans)))


Measured memory_bytes: 5768
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans = 'Yes'
x = [[-1, 0], [0, -1], [1, 0], [0, 1]]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = 0
            for k in x:
                if 0 <= i + k[0] < h and 0 <= j + k[1] < w and s[i + k[0]][j + k[1]] == '#':
                    flag = 1
            if flag < 1:
                ans = 'No'
print(ans)


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

int n; ll ans,A,B,f[109];
bool ok(ll x,ll y,int now){
	now=n-now;
	return x*f[now-1]+y*f[now]<=A && x*f[now]+y*f[now+1]<=B;
}
void solve(ll x,ll y,int now){
	if (!ok(x,y,now)) return;
	if (now==n){
		ans++; return;
	}
	if (now+1==n && y<=A && x<=B){
		ans+=max(0ll,(B-x)/y); return;
	}
	solve(y,x+y,now+1);
	solve(y,x+(y<<1),now+1);
}
int main(){
	int cas; scanf("%d",&cas);
	while (cas--){
		int i;
		scanf("%lld%lld",&A,&B);
		if (A>B) swap(A,B);
		f[1]=f[2]=1;
		for (i=3; ; i++){
			f[i]=f[i-1]+f[i-2];
			if (f[i]>A || f[i]+f[i-1]>B) break;
		}
		n=i-2; ans=n==1?min(A,B):0;
		solve(1,1,0);
		swap(A,B); solve(1,1,0);
		printf("%d %lld\n",n,ans%1000000007);
	}
	return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N;
	cin >> N;
	char S[N];
	string Ans = "Three";

	for(int i = 0; i < N; i++){
		cin >> S[i];
		if (S[i] == 'Y') {
			Ans = "Four";
		}
 	}
	cout << Ans << '\n'; //答えの出力

	return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<cstring>
#define INF 1000000000
using namespace std;
int n,m,x,yes=1,al[13],money[13],y,t,score[13][13],ans,mark[13][13],cash[13],gone[13],sum;
void dfs(int i,int time){
    if(i==n){
        return;
    }
    for(int g=i+1;g<=n;g++){
        t=1;
            for(int l=1;l<=m;l++)
        {
            if(gone[g])
                break;
            mark[l][time]=mark[l][time-1]+score[l][g];
            if(mark[l][time]<x)
                t=0;
            cash[time]=cash[time-1]+money[g];
            if(t&&l==m){
                ans=min(ans,cash[time]);
            }
            if(l==m){
                gone[g]=1;
                dfs(g,time+1);
                gone[g]=0;
            }
            
        }
    }
}
int main(){
    ans=INF;
    cin>>n>>m>>x;
    for(int i=1;i<=12;i++){
        mark[i][0]=0;
        cash[i]=0;
    }
    for(int g=1;g<=n;g++){
        cin>>money[g];
    for(int i=1;i<=m;i++)
        cin>>score[i][g];
    }
    dfs(0,1);
    for(int i=1;i<=m;i++){
        if(ans==INF){
            yes=0;
            break;
        }
    }
    if(yes)
    cout<<ans;
    else
        cout<<-1;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  ll n,t[100010],x[100010],y[100010];
  t[0]=0;
  x[0]=0;
  y[0]=0;
  cin>>n;
  reps(i,n+1)cin>>t[i]>>x[i]>>y[i];
  ll start=0;
  rep(i,n){
    if(t[i+1]-t[i]<abs(x[i+1]-x[i])+abs(y[i+1]-y[i])||(t[i+1]-t[i])%2!=abs(x[i+1]-x[i]+y[i+1]-y[i])%2){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 5964
#include <stdio.h>

int main(void){
	
	int i;
	int n;
	scanf("%d", &n);
	int min, pre;
	scanf("%d", &min);
	pre = min;

	int ans, r;
	scanf("%d", &r);
	ans = r - pre;
//	printf("!%d\n", ans);
	if(r<min){
		min = r;
		pre = r;
	}else if(r>pre){
		pre = r;
	}
	for(i=2; i<n; i++){
//		printf("i=%d\n", i);
		scanf("%d", &r);

			if(pre<=r){
				pre = r;
				if(ans < pre-min){
					ans = pre-min;
				}
//				printf("ans = %d\n", ans);
			}
			if(r<min){
				min=r;
				pre=r;
			}
	
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1852
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int INF = numeric_limits<int>::max() / 2;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int h,w,d;
	cin >> h >> w >> d;
	vector<pair<int, int> > area(h * w);
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			int a;
			cin >> a;
			a--;
			area[a] = make_pair(i,j);
		}
	}

	vector<int> requireMP(h*w,0);
	for(int i = d; i < h*w; i++){
		requireMP[i] = abs(area[i-d].first - area[i].first) + abs(area[i-d].second - area[i].second) + requireMP[i-d];
	}

	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int l,r;
		cin >> l >> r;
		l--; r--;
		cout << requireMP[r] - requireMP[l] << endl;
	}
	return 0;
}

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

int main(){
  uint64_t N, M;
  cin >> N >> M;
  vector<long> Height(N);
  vector<bool> good(N,true);
  for( uint64_t i = 0; i < N; ++i ){
    long tmp;
    cin >> tmp;
    Height.at(i) = tmp;
  }

  uint64_t goodCount = N;
  for( uint64_t j = 0; j < M; ++j ){
    uint64_t A, B;
    cin >> A >> B;

    if( Height.at(A-1) <= Height.at(B-1) ){
      good.at(A-1) = false;
    }
    if( Height.at(A-1) >= Height.at(B-1) ){
      good.at(B-1) = false;
    }

  }

  cout << count(good.begin(),good.end(), true ) << endl;
}

Measured memory_bytes: 4052
def resolve():
    n=int(input())
    h=list(map(int,input().split()))
    if n==1:
      print(0)
    else:
        ans=[0 for i in range(n)]
        if h[0]<h[1]:
            ans[0]=0
        else:
            ans[0]=1
        for i in range(1,n-1):
            if h[i]<h[i+1]:
                ans[i]=0
            else:
                ans[i]=ans[i-1]+1
        print(max(ans))
resolve()

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

using namespace std;

#define N 200003

string s;
int pot10[N], r[N], v[N], freq[2021];
int main()
{
    cin >> s;
    int n = s.size();

    pot10[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        pot10[i] = (pot10[i - 1]*10)%2019; 
    } 

    s = "0" + s;
    for (int i = 0; i <= n; i++)
        v[i] = (int)(s[i] - '0');

    r[0] = 0;
    for (int i = n; i >= 1; i--)
        r[i] = (r[i + 1] + v[i]*pot10[n - i])%2019;

    freq[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        freq[r[i]]++;
    }
    long long ans = 0;

    for (int i = 0; i < 2019; i++)
        if (freq[i] >= 2)
            ans+= (freq[i]*(freq[i] - 1))/2;

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 6088
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  int n ;
  cin >>n ;
  int ans = 0 ;
  vector<int> vec(n) ;
  REP(i,n){
    cin >> vec.at(i) ;
  }
  sort(ALL(vec)) ;
  
  REP(i,n-2){
    FOR(j,i+1,n-1){
      FOR(k,j+1,n){
        if(vec.at(k)<vec.at(i)+vec.at(j)){
          ans++ ;
        }
        else{
          break ; 
        }
      }
    }
  }
  
  cout << ans <<endl ;
    
  


  return 0 ;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int h = in.nextInt(), w = in.nextInt();

			int count = 0;
			char[][] s = new char[h][w];
			for (int i = 0; i < h; i++) {
				s[i] = in.nextString().toCharArray();
			}

			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (s[i][j] == '#') count++;
				}
			}

			out.println(count == h+w-1 ? "Possible" : "Impossible");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 23124