akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1000000000;
typedef pair<int, int> P;

int M, N, S, T;
vector<P> a;
vector<P> b;

bool input() {
  cin >> M >> N;
  if (!M && !N) {
    return false;
  }
  cin >> S;
  a.resize(S);
  for (int i = 0; i < S; ++i) {
    cin >> a[i].first >> a[i].second;
    --a[i].first;
    --a[i].second;
  }
  cin >> T;
  b.resize(T);
  for (int i = 0; i < T; ++i) {
    cin >> b[i].first >> b[i].second;
    --b[i].first;
    --b[i].second;
  }
  return true;
}

P conv1(P p) {
  int x = p.first - (p.second/2);
  int y = p.second;
  return P(x, y);
}

P conv2(P p) {
  P q = conv1(p);
  return P(-q.second, q.first + q.second);
}

P conv3(P p) {
  P q = conv1(p);
  return P(q.first + q.second, -q.first);
}

int dist_sub(P p, P q) {
  return abs(p.first - q.first) + abs(p.second - q.second);
}

int dist(P p, P q) {
  P p1 = conv1(p);
  P p2 = conv2(p);
  P p3 = conv3(p);
  P q1 = conv1(q);
  P q2 = conv2(q);
  P q3 = conv3(q);
  int d1 = dist_sub(p1, q1);
  int d2 = dist_sub(p2, q2);
  int d3 = dist_sub(p3, q3);
  if (d1 <= d2 && d1 <= d3) {
    return d1;
  }
  if (d2 <= d3) {
    return d2;
  }
  return d3;
}

int solve() {
  int ans = -1;
  vector<P> c;
  c.resize(S + 1);
  for (int i = 0; i < S; ++i) {
    c[i] = a[i];
  }
  vector<int> counter;
  counter.resize(S + 1);
  for (int i = 0; i < T; ++i) {
    c[S] = b[i];
    for (int j = 0; j <= S; ++j) {
      counter[j] = 0;
    }
    for (int j = 0; j < M; ++j) {
      for (int k = 0; k < N; ++k) {
        bool same_flag = false;
        int min_dist = INF;
        int min_id = -1;
        for (int l = 0; l <= S; ++l) {
          int d = dist(P(j, k), c[l]);
          if (min_dist == d) {
            same_flag = true;
          } else if (min_dist > d) {
            min_dist = d;
            min_id = l;
            same_flag = false;
          }
        }
        if (!same_flag) {
          ++counter[min_id];
        }
      }
    }
    if (ans < counter[S]) {
      ans = counter[S];
    }
  }

  return ans;
}

int main() {
  while (input()) {
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI   3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	ll a[n + 3]; ll m = 0;
	ll f = INT_MAX;
	ll b[n + 6];
	for(ll i = 1; i <= n; i ++){
		cin >> a[i];
		b[i] = a[i] -i-1;
	}
	sort(b + 1, b  + n + 1);
	for(ll i = 1; i<= n; i++){
		m += abs(b[i] - b[n/2 + 1] );
	}
	cout << m;
	return 0;
}

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int h, w;
  cin >> h >> w;
  char c[105][105];
  for (int i = 0; i<=h+1; i++){
    for (int j = 0; j <= w + 1; j++){
      c[i][j] = '#';
    }
  }

  for (int i = 1; i <= h; i++){
    for (int j = 1; j <= w; j++){
      cin >> c[i][j];
    }
  }
  for (int i = 0; i<=h+1; i++){
    for (int j = 0; j <= w + 1; j++){
      cout << c[i][j];
    }
    cout << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
  int n, k;
  cin>>n>>k;
  double ans=0.0;
  for(int i=1; i<=n; i++){
    int t=i;
    double tmp=1.0/n;
    while(t<k){
      t*=2;  tmp/=2.0;
    }
    ans+=tmp;
  }
  cout<<setprecision(12)<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll	        long long
#define all(v)      (v).begin() , (v).end()
#define vi          vector <ll>
#define vii         vector <pair<ll,ll>>
#define ii          pair<int,int>
#define lp(i,a,b)	for(int i=a;i<b;i++)
#define pb          push_back
#define F           first
#define S           second
const ll mod=1e9+7,MAX=2e3+5;

void fast();
int main()
{
    fast();
    int n;
    cin>>n;
    set<string>v;
    while(n--){
        string s;
        cin>>s;
        v.insert(s);
    }
    cout<<v.size();
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


Measured memory_bytes: 19248
#include<bits/stdc++.h>
using namespace std;
 int main(){
 	
	int n=0;
   int m = 0;
	string c;
	while(cin>>n){
      cin>>m;
	if(n==m) {
      cout<<"Yes";
    }
      else{ 
        cout<<"No";
      }
		
		n=0;
		m=0;
	}
 }

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

signed main() {
    SS(string,s,t);
    ll ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i])ans++;
    }
    p(ans);
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define lb long double
#define ll long long
#define N 3010
#define pi acos(-1)
using namespace std;
struct Po{lb x,y;}ans,y,x;
Po operator +(Po x,Po y){return (Po){x.x+y.x,x.y+y.y};}
Po operator -(Po x,Po y){return (Po){x.x-y.x,x.y-y.y};}
Po operator *(Po x,lb y){return (Po){x.x*y,x.y*y};}
Po operator *(Po x,Po y){return (Po){x.x*y.x-x.y*y.y,x.x*y.y+x.y*y.x};}
Po operator /(Po x,lb y){return (Po){x.x/y,x.y/y};}
ll s[N],a[N],n,l;
Po que(lb x){return (Po){cosl(2*pi*x/l),sinl(2*pi*x/l)};}
int main(){
	cin>>n>>l;
	for (int i=1;i<=n;i++)cin>>a[i];
	for (int i=n;i>=1;i--)s[i]=s[i+1]+a[i];
	for (int i=1;i<n;i++){
		y=(Po){0,0};
		for (int j=n-1;j>i;j--){
			Po x=que((a[i]+a[j])/2.0);y=y+que((a[j+1]+l-a[i])/2.0);
			ans=ans+x*(n-j)+(que(a[i])-x)*y;
		}
	}
	ans=ans/n/(n-1)/(n-2)*6;
	printf("%.15Lf %.15Lf",ans.x,ans.y);
	return 0;
}

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

int main(){
//srandom((unsigned long)time(NULL));

long long n,m;
cin>>n>>m;
long long a[m];
long long sum=0;
 for(long long i=0;i<m;i++){
     cin>>a[i];
     sum+=a[i];
 }
 long long ans=n-sum;
 if(ans>=0) cout<<ans<<endl;
 else cout<<-1<<endl;

return 0;
}



Measured memory_bytes: 3716
using System;
using System.Linq;

namespace atcoder.abc170.c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputArray = getIntParams();
            int X = inputArray[0];
            int N = inputArray[1];

            int ret = 0;
            if (N == 0)
            {
                ret = X;
            }
            else
            {
                int[] paramArray = getIntParams();

                if (!paramArray.Contains(X))
                {
                    ret = X;
                }
                else
                {
                    for (int i = 1; i <= N; i++)
                    {
                        if (!paramArray.Contains(X - i))
                        {
                            ret = X - i;
                            break;
                        }
                        if (!paramArray.Contains(X + i))
                        {
                            ret = X + i;
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(ret);
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
    }
}


Measured memory_bytes: 28140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
   	int n;
   	cin>>n;
   	string s;
   	cin>>s;
   	int cnt = 0;
   	rep(i,0,(int)s.length())
   		if(s[i] == 'R')
   			cnt++;
   	int ans = 0;
   	rep(i,0,cnt)
   	{
   		if(s[i] == 'W')
   			ans++;
   	}
   	cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int r,D,x;
  cin>>r>>D>>x;
  ll ans=0;
  for(int i=0;i<10;i++){
    x=r*x-D;
    cout<<x<<endl;
  }
  return 0;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, y, a=-1, b=-1, c=-1;
  cin >> n >> y;
  for(int i=0; 10000*i<=y; i++){
	for(int j=0; 5000*j<=y; j++){
	  if(i*10000+j*5000+(n-i-j)*1000==y && n-i-j>=0){
		a=i;
		b=j;
		c=n-i-j;
        break;
	  }
	}
  }
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,k,l,m,n,o,a,b,sum;
    scanf("%d",&n);
    scanf("%d",&a);
    scanf("%d",&b);
    sum=0;
    for(o=0;o<=9;o++)
    {
        for(i=0;i<=9;i++)
        {
            for(j=0;j<=9;j++)
            {
                for(k=0;k<=9;k++)
                {
                    for(l=0;l<=9;l++)
                    {
                        for(m=a;m<=b&&10000*o+1000*i+100*j+10*k+l<=n;m++)
                        {
                            if(m==o+i+j+k+l)
                            {
                                sum=sum+10000*o+1000*i+100*j+10*k+l;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int ketasuu(int n) {
	if (n == 0) { return 1; }
	int ret = 0;
	while (n > 0) {
		n = n / 10;
		ret = ret + 1;
	}

	return ret;
}

int keta(int n, int k) {
	/*nの、左から数えてk桁目*/
	if (n == 0) { return 0; }
	int w = ketasuu(n) - k;
	for (int i = 0; i < w; i++) {
		n = n / 10;
	}
	return n % 10;
}

int main() {
	int N, M;
	int s[10];
	int c[10];
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> s[i] >> c[i];
	}
	for (int i = 0; i < 1000; i++) {
		if (ketasuu(i) == N) {
			bool jouken = true;
			for (int j = 0; j < M; j++) {
				if (keta(i, s[j]) != c[j]) {
					jouken = false;
				}
			}
			if (jouken) {
				cout << i;
				return 0;
			}
		}
	}
	cout << "-1";
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;


void solve(long long N, long long A, long long B){
    int ans = 0;

    REP(i, N + 1) {
        if (i == 0) continue ;
        string num = to_string(i);
        int sum = 0;
        REP(j, num.size())
            sum += num[j] - '0';
        if (sum >= A && sum <= B)
            ans += i;
    }

    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			ArrayList<HashMap<Integer, Integer>> adj = new ArrayList<HashMap<Integer, Integer>>();
			for(int i = 0; i < N; i++) { adj.add(new HashMap<Integer, Integer>()); }
			
			for(int i = 0; i < N - 1; i++) {
				final int u = sc.nextInt() - 1;
				final int v = sc.nextInt() - 1;
				final int w = sc.nextInt();
				
				adj.get(u).put(v, w);
				adj.get(v).put(u, w);
			}
			
			LinkedList<Integer> queue = new LinkedList<Integer>();
			queue.add(0); queue.add(-1); queue.add(0);
			
			int[] answers = new int[N];
			while(!queue.isEmpty()) {
				final int node = queue.poll();
				final int parent = queue.poll();
				final int value = queue.poll();
				
				answers[node] = value;
				for(final Entry<Integer, Integer> entry : adj.get(node).entrySet()) {
					final int next_node = entry.getKey();
					final int next_w = entry.getValue();
					
					if(next_node == parent) { continue; }
					if(next_w % 2 == 0) {
						queue.add(next_node); queue.add(node); queue.add(value);
					}else {
						queue.add(next_node); queue.add(node); queue.add(1 - value);
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				System.out.println(answers[i]);
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main(){
    
    string s; cin >> s;
    int ok = 1;
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 1){
            if(s[i] == 'L' or s[i] == 'U' or s[i] == 'D');
            else ok = 0;
        }
        else{
            if(s[i] == 'R' or s[i] == 'U' or s[i] == 'D');
            else ok = 0;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	a[0]-=32;
	b[0]-=32;
	c[0]-=32;
	cout<<a[0]<<b[0]<<c[0]<<endl;
	return 0;
}

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



int main() {
  string S,T;
  cin >> S >> T;
  ll j,cur,count=0,count2=0,k=0,m=0;
  bool torf=false;
  
/*  while(k<S.size()){
    cout << "15" << endl;
    if(S.at(k)!='?'){
      k++;
      cout << k << "18" << endl;
      continue;
    }
    else{
      count2++;
      while(k+1!=S.size() && S.at(k)==S.at(k+1)){
        count2++;
        k++;
        cout << k << "26" << endl;
      }
      
    if(count2>=T.size()){
      torf=true;
      m=max(k+1,m);
      
    }
    count2=0;
    }
    
  k++;
    cout << k <<"37" << endl;
  }
  */
  
//  for(cur=0;cur<T.size();cur++){
  rep(i,(int)S.size()-(int)T.size()+1){
    
    if(S.at(i)!=T.at(0) && S.at(i)!='?')
      continue;
    else{
      
    //  cout << i << "50"<< endl;
      for(j=0;j<T.size();j++){
        if(S.at(i+j)==T.at(j) || S.at(i+j)=='?')
          continue;
        else
          break;
        
      }
      
      if(j==T.size()){
        torf=true;
        count=max(i,count);
       // cout << count << endl;
      }
 
    }
    
    
   // cout << "68" << endl;
  }
    
    
//  }
  
  
  //cout << count << endl;
  
  if(torf==false)
    cout << "UNRESTORABLE" << endl;
  else{
  
 // cout << count << endl;
   // m=m-(int)T.size()+1;
    
    count=max(count,m);
    rep(i,T.size())
      S.at(count+i)=T.at(i);
    
    rep(i,S.size()){
      if(S.at(i)=='?')
        S.at(i)='a';
    }
      
    cout << S << endl;
    
    
  }
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a, n, ans;
char b;
int main()
{
	cin >> a;
	for (int i = 0; i < a; i++)
	{
		cin >> b;
		if (b == 'I')
		{
			n++;
		}
		else
		{
			n--;
		}
		ans = max(ans, n);
	}
	cout << ans << endl;
	return 0;
}

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

tmp = [0 for _ in range(N)]
for i in range(N-1):
    tmp[i] = A[i+1] - A[i]

tmp[-1] = K - A[-1] + A[0]

print(K - max(tmp))

Measured memory_bytes: 25840
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
class UnionFind {
	mutable std::vector<int> parent;
public:
	UnionFind(int size) : parent(size, -1) {};
	int find(int a) const {
		return parent[a] < 0 ? a : parent[a] = find(parent[a]);
	}
	bool same(int a, int b) const {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a); b = find(b);
		if (a == b) return;
		if (parent[a] > parent[b]) std::swap(a, b);
		parent[a] += parent[b];
		parent[b] = a;
	}
	int size_of(int a) const {
		return -parent[find(a)];
	}
};
int main() {
	int n, m, k; std::cin >> n >> m >> k;
	UnionFind uft(n);
	std::vector<int> count(n, -1);
	for (auto i = 0; i < m; ++i) {
		int a, b; std::cin >> a >> b; --a; --b;
		uft.unite(a, b);
		count[a]--; 
		count[b]--;
	}
	for (auto i = 0; i < n; ++i) {
		count[i] += uft.size_of(i);
	}
	for (auto i = 0; i < k; ++i) {
		int c, d; std::cin >> c >> d; --c; --d;
		if (uft.same(c, d)) {
			count[c]--;
			count[d]--;
		}
	}
	for (auto i = 0; i < n; ++i) {
		if (i != 0) std::cout << ' ';
		std::cout << count[i];
	}
	std::cout << '\n';
}

Measured memory_bytes: 1664
def solve(l:list):
    cnt = 0
    for i in range(1, len(l)-1):
        if l[i+1]>l[i]>l[i-1] or l[i+1]<l[i]<l[i-1]:
            cnt += 1
    return cnt

def main():
    input()
    l = list(map(int, input().split(" ")))
    print(solve(l))

if __name__ == "__main__":
    main()

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

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st;

    public static void main(String[] args) throws IOException {
        char[] cs = br.readLine().toCharArray();

        int ds = 0;
        for (char c : cs) {
            ds += c;
        }
        ds -= cs.length * '0';
        System.out.println(ds % 9 == 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 36296
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());降順ソート
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	bool flag = false;
	for (int i = 0; i <=100; ++i) {
		if (a * i % b == c) {
			cout << "YES" << endl;
			flag = true;
			break;
		}
	}
	if (!flag) {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
line = gets.split(' ')



def gcd(a, b)
  a, b = b, a if a > b
  until a == 0
    a, b = b%a, a
  end
  return b
end


def lcm(a, b)
  a * b/gcd(a, b)
end

a = line[0].to_i
b = line[1].to_i

print lcm(a, b)




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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, k; cin >> n >> k;
    int h[n];
    rep(i,n) cin >> h[i];

    int dp[n];
    rep(i,n) dp[i] = INF;
    dp[0] = 0;

    for(int i=1; i<n; i++){
        for(int j=1; j<=k; j++){
            if(i-j < 0) continue;
            else dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4416
import math
import os
import sys

from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N, K = list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


def mod_inv(a, mod):
    """
    a の逆元
    :param int a:
    :param int mod:
    :return:
    """
    return pow(a, mod - 2, mod)


@lru_cache(maxsize=None)
def ncr(n, r, mod=None):
    """
    scipy.misc.comb または scipy.special.comb と同じ
    組み合わせの数 nCr
    :param int n:
    :param int r:
    :param int mod: 3 以上の素数であること
    :rtype: int
    """
    if n < r:
        return 0

    # 何度も呼ぶ場合は最大の n 以下の階乗を事前に計算しておくといい
    if mod:
        return (
                math.factorial(n)
                * mod_inv(math.factorial(r), mod)
                * mod_inv(math.factorial(n - r), mod)
                % mod
        )
    else:
        return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


@lru_cache(maxsize=None)
def nhr(n, r, mod=None):
    """
    重複組み合わせの総数 nHr
    :param int n:
    :param int r:
    :param int mod:
    :return:
    """
    return ncr(n + r - 1, r, mod)


# K を i 個に分割する方法の数
# ncr(K-1,i-1)
# for i in range(1, 10):
#     print(i, ncr(K - 1, i - 1, MOD))

ans = []
for i in range(1, K + 1):
    # K を i 個に分割する方法の数
    ki = ncr(K - 1, i - 1, MOD)
    # i+1 のスペースに残りを入れる
    # 選ばなきゃいけないやつは減らす
    nocori = N - K - (i - 1)
    if nocori >= 0:
        ans.append(ki * nhr(i + 1, nocori, mod=MOD) % MOD)
    else:
        ans.append(0)
print('\n'.join(map(str, ans)))


Measured memory_bytes: 72408
/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.

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

int mod = 1000000007;
long long dp[100005];;

long long gcd(long long a,long long b){

  if(b == 0)
    return a;
  else return gcd(b,a%b);
}


int main(){

 int n,x; cin>>n;
 vector<int>v(n);

 cin>>v[0];
 long long g = v[0];

 for(int i=1;i<n;i++){
    cin>>v[i];
     g = gcd(g,v[i]);
 }

 cout<<g<<endl;

return 0;
}

Measured memory_bytes: 640
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

int[int] HS;

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(int[]);
    foreach (a; as) {
        if (a in HS)
            ++HS[a];
        else
            HS[a] = 1;
    }
    int cnt;
    foreach (i, h; HS) {
        if (!h) continue;
        if (h > i) {
            cnt += h - i;
        } else if (h < i) {
            cnt += h;
        }
    }
    writeln(cnt);
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  double ans=a[0];
  rep(i,n-1){
    ans=(ans+a[i+1]+0.0)/2.0;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3828
s = str(input())

n = len(s)

s2 = s[:int((n-1)/2)]
s3 = s[int((n+3)/2-1):]

def palindrome(string): return True if string==string[::-1] else False

if palindrome(s) and palindrome(s2) and palindrome(s3):
    print("Yes")
else:
    print("No")

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

using namespace std;
using ll = long long;

pair<long long, long long> extgcd(long long a, long long b) {
  long long x0 = 1, y0 = 0;
  long long x1 = 0, y1 = 1;
  while (b != 0) {
    long long q = a / b;
    a -= q * b;
    x0 -= q * x1;
    y0 -= q * y1;
    swap(a, b);
    swap(x0, x1);
    swap(y0, y1);
  }
  return {x0, y0};
}

ll gcd(ll x, ll y) {
  return y == 0 ? x : gcd(y, x % y);
}

pair<ll, ll> common_arith(pair<ll, ll> f, pair<ll, ll> g) {
  if (f.first > g.first) swap(f, g);
  ll c = g.first - f.first;
  ll d = gcd(f.second, g.second);
  if (c % d != 0) {
    return {LLONG_MAX, LLONG_MAX};
  }
  ll p = extgcd(f.second, g.second).first * (c / d);
  ll b = f.second * g.second / d;
  ll a = f.first + p * f.second;
  if (a < f.first) {
    a += (f.first - a + b - 1) / b * b;
  } else {
    a -= (a - f.first) / b * b;
  }
  return {a, b};
}

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  pair<ll, ll> ans(0, 1);
  for (int i = 0; i < N; i++) {
    ans = common_arith(ans, {A[i] / 2, A[i]});
    if (ans.first > M) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (M - ans.first) / ans.second + 1 << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 100001

using namespace std;

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

int main() {
  int N, K, A[MAX_N];
  cin >> N >> K;
  int min_i = -1;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] == 1) {
      min_i = i;
    }
  }

  cout << (N-1+K-2)/(K-1) << endl;

  return 0;
}


Measured memory_bytes: 640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <climits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;
typedef long long ll;
#define ln '\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define drep(i,n) int i = 0;for(;i<(n);++i)
#define FOR(i,s,e) for(int i=s;i<=(e);++i)
#define FORR(i,s,e) for(int i=s;i>=(e);--i)
#define fore(a, x) for(auto& a : x)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define Fill(a,b) memset(a,b,sizeof(a))
template<typename T1, typename T2> bool Max(T1& a, T2 b) { return a<b ? a = b, 1 : 0; }
template<typename T1, typename T2> bool Min(T1& a, T2 b) { return a>b ? a = b, 1 : 0; }

const int N = 500;

void solve() {
  int n, l, r;
  cin >> n;
  int ans = 0;
  rep(i, n) {
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << ln;
}


void init() {
  
}

int main(void) {
  ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
  //freopen("C:\\Users\\LENOVO\\Documents\\Visual Studio 2015\\Projects\\Test\\Input\\in.in", "r", stdin);

  init();
  int TC = 1;
#if 0
  cin >> TC; cin.get();
#endif
  FOR(TI, 1, TC) {
    //cout << "Case #" << TI << ": ";
    solve();
  }
  
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
bool compare(pair< pair<string,int>,int > p1,pair< pair<string,int>,int > p2)
{
    string s1 = p1.fi.fi,s2 = p2.fi.fi;
    if(s1 != s2) return s1 < s2;
    return p1.fi.se > p2.fi.se;
}
int main()
{
    IOS
    int n; cin>>n;
    vector< pair< pair<string,int>,int > > vec;
    string str;
    int pt;
    for(int i=1;i<=n;i++)
    {
        cin>>str; cin>>pt;
        vec.pb(mp(mp(str,pt),i));
    }
    sort(vec.begin(),vec.end(),compare);
    for(int i=0;i<n;i++)
    {
        cout<<vec[i].se<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())


d=4*a*b
if c-a-b>0:
  e=(c-a-b)*(c-a-b)
  print("Yes" if d<e  else "No")
#print(d,e)
#print(1000063246**0.5)
#print(1000000000**0.5+1)


else:
  print("No")

Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

void pok() {
  std::cout << "Yes" << std::endl;
}
void png() {
  std::cout << "No" << std::endl;
}

int main() {
  int n; std::cin >> n;
  std::vector<std::string> words;

  std::string word; std::cin >> word;
  words.push_back(word);

  bool ok = true;
  for (int i = 1; i < n; i++) {
    std::cin >> word;
    if (!ok) continue;

    auto pre_word = words[i-1];

    if (pre_word[pre_word.size()-1] != word[0]) {
      ok = false;
      continue;
    }

    auto it = std::find(words.begin(), words.end(), word);
    if (it != words.end()) {
      ok = false;
      continue;
    }

    words.push_back(word);
  }

  if (ok) pok();
  else png();
  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++)
#define all(vec) vec.begin(),vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    int n;cin>>n;
    cout<<n*n<<endl;
}

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

using namespace std;

int H,W;
bool visited[25][25];
char field[25][25];
map<string,int> mp;
const int dx[] = {-1,-1,-1,0,0,1,1,1};
const int dy[] = {-1,0,1,-1,1,-1,0,1};

void rec(int x,int y,int d,string s){
  if(visited[y][x]){ return; }
  visited[y][x] = true;
  int nx = (x + dx[d] + W) % W;
  int ny = (y + dy[d] + H) % H;
  mp[s+field[y][x]]++;
  rec(nx,ny,d,s+field[y][x]);
}

int main(){
  while(cin >> H >> W, H){
    mp.clear();
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> field[i][j];
      }
    }
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        for(int k = 0 ; k < 8 ; k++){
          memset(visited,false,sizeof(visited));
          rec(j,i,k,"");
        }
      }
    }
    int ans_size = -1;
    string ans;
    map<string,int>::iterator it;
    for(it = mp.begin() ; it != mp.end() ; ++it){
      int size = it->first.size();
      if(it->second < 2 || size < 2){ continue; }
      if(ans_size < size){
        ans_size = size;
        ans = it->first;
      }
    }
    if(ans_size == -1){
      cout << 0 << endl;
    }else{
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 37052
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


H,W = map(int,input().split())
A = [list(input()) for _ in range(H)]

h = 0
w = 0
A[0][0]="."

while not(h==H-1 and w==W-1):
    # print(h,w)
    if h<H-1 and w<W-1 and A[h+1][w]=="#" and A[h][w+1]=="#":
        print("Impossible")
        break

    elif h<H-1 and A[h+1][w]=="#":
        h += 1
        A[h][w] = "."

    elif w<W-1 and A[h][w+1]=="#":
        w += 1
        A[h][w] = "."
    else:
        print("Impossible")
        break

else:
    flg = 0
    for h in range(H):
        for w in range(W):
            if A[h][w]=="#":
                flg = 1
                break
    else:
        if flg:
            print("Impossible")
        else:    
            print("Possible")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(){
    int n, x;
    vector<int> l(n, 0);
    cin >> n >> x;
    for(int i = 0; i < n; i++) cin >> l[i];
    int d = 0;
    int ans = n + 1;
    for(int i = 0; i < n; i++){
        d += l[i];
        if(d > x){
            ans = i + 1;
            break;
        }
    }
    cout << ans << endl;
}


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

int main()
{
  using namespace std;

  string s;

  cin >> s; 

  switch (s[0]) {
    case 'S':
      cout << "Cloudy" << endl;
      break;
    case 'C':
      cout << "Rainy" << endl;
      break;
    default:
      cout << "Sunny" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

int main(){
    int N; cin >> N;
    vector <int> A(N);
    rep(i,N) cin >> A[i];
    
    sort(A.begin(),A.end());
    bool ans=true;
    rep(i,N-1){
        if(A[i]==A[i+1]) ans=false;
    }
    
    if (ans) cout << "YES" << endl;
    else  cout << "NO" << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;

inline char gc()
{
	static const int L = 1000;
	static char sxd[L], *sss = sxd, *ttt = sxd;
	if(sss == ttt)
	{
		ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
		if(sss == ttt)
			return EOF;
	}
	return *sss++;
}

#define dd c = getchar()
inline int read(int& x)
{
	x = 0;
	char dd;
	bool f = false;
	for(; !isdigit(c); dd)
	{
		if(c == EOF)
			return -1;
		if(c == '-')
			f = true;
	}
	for(; isdigit(c); dd)
		x = (x << 1) + (x << 3) + (c ^ 48);
	if(f)
		x = -x;
	return 1;
}
#undef dd

int i,n,x,sum;
bitset<2000007>f;
int main()
{
	read(n);
	f[0]=1;
	for(i=1;i<=n;i++)
	{
		read(x);
		f|=f<<x;
		sum+=x;
	}
	for(i=(sum+1)/2;i<=sum;i++)
	{
		if(f[i])
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N;
  cin >> N;

  vector<int> h(N);
  REP(i, N) cin >> h[i];
  
  vector<int> dp(N, INF);
  dp[0] = 0;

  REP(i, N){
    if(i+1 < N) chmin(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
    if(i+2 < N) chmin(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
  }

  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>

int main()
{
for(int i = 0; i < 3; ++i) {
int l[3], r[3];
for(int j = 0; j < 3; ++j)
scanf("%d", l + j);
for(int j = 0; j < 3; ++j)
scanf("%d", r + j);
int h, m, s;
s = r[2] - l[2];
if(s < 0) {s += 60; r[1] -= 1; }
m = r[1] - l[1];
if(m < 0) {m += 60; r[0] -= 1; }
h = r[0] - l[0];
printf("%d %d %d\n", h, m, s);
}
return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#define FREE -1
#define N 8
#define NOTFREE 1
#define TRUE 1
#define FALSE 0

int row[N], col[N], dpos[2*N-1], dneg[2*N-1], X[N][N];

void init(){
	int i, j;
	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			X[i][j]=FALSE;
		}
		row[i]=FREE;
		col[i]=FREE;		
	}
	for(i=0;i<2*N-1;i++){
		dpos[i]=FREE;
		dneg[i]=FREE;
	}
}
void print(){
	int i, j;
	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			if(X[i][j]==TRUE){
				if(row[i]!=j){
					return ;
				}
			}
		}
	}
	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			printf("%c", (row[i]==j)?'Q':'.');
		}
		printf("\n");
	}
}
void putQueen(int i){
	int j;
	if(i==N){
		print();
		return;
	}
	for(j=0;j<N;j++){
		if(col[j]==NOTFREE||dpos[i+j]==NOTFREE||dneg[i-j+N-1]==NOTFREE){
			continue;
		}
		row[i]=j;
		col[j]=dpos[i+j]=dneg[i-j+N-1]=NOTFREE;
		putQueen(i+1);
		col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
	}
}
int main(){
	int i, j, k, r, c;
	init();
	scanf("%d", &k);
	for(i=0;i<k;i++){
		scanf("%d%d", &r, &c);
		X[r][c]=TRUE;
	}
	putQueen(0);
	return 0;
}


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

int main() {
	string s;
	cin >> s;
	deque<char> dq(s.begin(), s.end());
	int Q;
	cin >> Q;
	bool rev = false;
	for (int q = 0; q < Q; q++) {
		int a;
		cin >> a;
		if (a == 1) {
			rev ^= true;
		} else {
			int f;
			char c;
			cin >> f >> c;
			bool back = rev ^ (f == 2);
			if (back) dq.push_back(c);
			else dq.push_front(c);
		}
	}
	if (rev) {
		for (auto itr = dq.rbegin(); itr != dq.rend(); itr++) {
			cout << *itr;
		}
	} else {
		for (char c : dq) cout << c;
	}
	cout << endl;
	return 0;
}

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

#define ll long long
#define MAX 300005
#define pp pair<ll, pair<ll, ll>>
#define pb push_back
#define mod 1000000007

using namespace std;

/*
 * author: Kruti_20
 */

ll power(ll x, ll y);
ll gcd(ll a, ll b);



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    int curr=1;
    int ans=0;
    while(curr<b){
        curr+=a-1;
        ans++;
    }
    cout<<ans;
    return 0;
}

ll power(ll x, ll y) {
    ll res = 1;
    x = x % mod;
    while (y > 0) {
        if (y & 1) res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main (){
    map< double , int > a[3];
    map< double , int > b;
    for(int i=0;i<3;i++){
        for(int j=0;j<8;j++){
           int x;
           double y;
           cin>>x>>y;
           a[i][y] = x;
        }
        map< double , int >::iterator it = a[i].begin();
        cout<<(*it).second<<" "<<(*it).first<<endl;
        it++;
        cout<<(*it).second<<" "<<(*it).first<<endl;

        int n=6;
        while(n--){
            it++;
            b[(*it).first] = (*it).second;
        }


    }
    map< double , int >::iterator it = b.begin();
        cout<<(*it).second<<" "<<(*it).first<<endl;
        it++;
        cout<<(*it).second<<" "<<(*it).first<<endl;

    for(int i=0;i<3;i++)a[i].clear();
    b.clear();
    return 0;
}

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

int main(){
    int x,y,tmp;
    for(int i = 1;i <= 3000;i++){
        scanf("%d %d",&x,&y);
        if((x==0)&&(y==0))break;
        if(x>y){
            tmp=y;
            y=x;
            x=tmp;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}


Measured memory_bytes: 3128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;

    ll N;
    cin >> N;
    vector<ll> A(N + 2, 0);
    reps(i, 1, N + 1) cin >> A[i];

    vector<ll> diff(N + 2, 0);

    rep(i, N + 1) { diff[i] = abs(A[i + 1] - A[i]); }

    // repv(A) cout << *it << " ";
    // cout << endl;

    // repv(diff) cout << *it << " ";
    // cout << endl;

    ll sum = 0;
    repv(diff) sum += *it;

    // cout << sum << endl;

    reps(i, 1, N + 1) {
        if ((A[i - 1] <= A[i] && A[i] <= A[i + 1]) ||
            (A[i - 1] > A[i] && A[i] > A[i + 1])) {
            cout << sum << endl;
        } else if (A[i - 1] <= A[i] && A[i] > A[i + 1]) {
            cout << sum - 2 * min(diff[i - 1], diff[i]) << endl;
        } else if (A[i - 1] > A[i] && A[i] <= A[i + 1]) {
            cout << sum - 2 * min(diff[i - 1], diff[i]) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4780
n,k = map(int,input().split())
a = list(map(lambda x: (int(x)-1)%k ,input().split()))

sum_a = sum(a)%k

left = [0] * (n+1)
right = [0] * (n+1)
for i,num in enumerate(a,1):
    left[i] = (left[i-1] + num)%k
for i,num in enumerate(a[::-1],1):
    right[-i-1] = (right[-i] + num)%k

from collections import defaultdict
right_d = defaultdict(int)
right_d_over = defaultdict(int)
ans = 0
for i in range(n,-1,-1):
    ans += right_d[(sum_a - left[i])%k] - right_d_over[(sum_a - left[i])%k]
    right_d[right[i]] += 1
    if( (n-i+1) >= k ):
        right_d_over[right[i+k-1]] += 1

print(ans)

Measured memory_bytes: 119160
#include<iostream>
#include<numeric>
#include<vector>
int main(){
    int N,M,X;
    std::cin>>N>>M>>X;
    std::vector<unsigned int> searchSpace(0x0001<<N);
    std::iota(searchSpace.begin(),searchSpace.end(),0);
    std::vector<int>costs(N)
;    std::vector<std::vector<int> >scores(N,std::vector<int>(M));
    for(int i=0;i<N;++i){
        std::cin>>costs[i];
        for(int j=0;j<M;++j){
            std::cin>>scores[i][j];
        }
    }
    for(int i=0;i<M;++i){
        std::vector<unsigned int>buf;
        for(unsigned int j:searchSpace){
            int score=0;
            for(int k=0;k<N;++k){
                if( j & 0x0001<<k){
                    score+=scores[k][i];
                }
            }
            if(score>=X){
                buf.push_back(j);
            }
        }
        searchSpace=buf;
    }
    if(searchSpace.size()>0){
        int min=-1;
        for(unsigned int j:searchSpace){
            int buf=0;
            for(int k=0;k<N;++k){
                if( j & 0x0001<<k){
                    buf+=costs[k];
                }
            }
            if(min==-1 || buf<min){
                min=buf;
            }
        }
        std::cout<<min<<std::endl;
    }
    else{
        std::cout<<-1<<std::endl;
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std ;
float bat,temp,jumlah;
int a[1999],ban;
int main(){
	int n,m;
	cin>>n>>m;
	
	for(int i=1;i<=n;i++){
		cin>>a[i];
		jumlah+=a[i];
	}
	bat=float(1)/float(4*m);
	for(int j=1;j<=n;j++){
		temp=float(a[j])/float(jumlah);
		
		if(temp>=bat){
			ban++;
		}
	}
	if(ban>=m){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(){
  int n; 
  vector<int> p(20);
  cin >> n;
  for(int i = 0; i < n; i++)cin >> p[i];
  int ans = 0;
  for(int i = 1; i < n - 1; i++){
    if(p[i - 1] < p[i] && p[i] < p[i + 1])ans++;
    else if(p[i - 1] > p[i] && p[i] > p[i + 1])ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, n, m;
  in(n);
  vector<ll> c(1000, 1);
  rep(j, n){
    m = n - j;
    rep2(i, 2, m + 1){
      while(m % i == 0){
        c[i]++;
        m = m / i;
      }
    }
  }
  a = 1;
  rep(i, 1000)
    a = a * c[i] % mei;
  out(a);
  memi;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct querys
{
	long long type; long long ord; long long from; long long to; long long name;
	bool operator<(const querys& rhs) const {
		if (ord != rhs.ord) {
			return ord < rhs.ord;
		}
		else {
			return type < rhs.type;
		}
	}
};
ll const MAX = 1e5 + 5;
ll a[MAX];
ll b[MAX] = {};
ll c[MAX] = {};
int main() {
	ll n, m;
	cin >> n >> m;
	REP(i, 1, n) {
		cin >> a[i];
	}
	SORT(a, n);
	a[n+1] = 1e9;
	ll cur = 0;
	REP(i, 1, n) {
		ll x = a[i] % m;
		b[x]++;
		cur++;
		if (a[i] != a[i + 1]) {
			c[x] += cur / 2;
			cur = 0;
		}
	}
	ll ans = 0;
	ans += b[0] / 2;
	if (m % 2 == 0) {
		ans += b[m / 2] / 2;
	}
	for (ll i = 1; i < m - i; i++) {
		ll j = m - i;
		if (b[i] > b[j]) {
			swap(b[i], b[j]);
			swap(c[i], c[j]);
		}
		ans += b[i];
		b[j] -= b[i];
		ans += min(b[j] / 2, c[j]);
	}
	cout << ans << endl;

}

Measured memory_bytes: 2560