akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
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,k,q;
  int data[100000];
  int d2[100000];
  REP(i, 100000) d2[i] = 0;
  
  cin >> n >> k >> q;
  REP(i, q){
    int tmp;
    cin >> tmp;
    d2[tmp-1]++;
  }
  REP(i, n){
    if(k - (q - d2[i]) <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }



}	


Measured memory_bytes: 1024
import numpy as np
N,K=map(int,input().split())
p=list(map(int,input().split()))
E=[]
for i in range(N):
  E.append((1+p[i])/2)
S=np.cumsum(E)
max=0
if N!=K:
  for i in range(N-K+1):
    if S[i+K-1]-S[i-1]>max:
       max=S[i+K-1]-S[i-1]
  print(max)
else:
  print(sum(E))

Measured memory_bytes: 33984
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <bitset>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

bool check( vector<int> &cnt ){
    for(int i = 0; i < cnt.size(); i++){
        if(cnt[i] > 1) return false;
    }
    return true;
}

void add( vector<int> &cnt, bitset<20> &bs ){
    for(int i = 0; i < 20; i++){
        cnt[i] += bs[i];
    } 
}

void sub( vector<int> &cnt, bitset<20> &bs ){
    for(int i = 0; i < 20; i++){
        cnt[i] -= bs[i];
    } 
}


int main(){

    int n;
    cin >> n;

    vector < bitset<20> > v(n);
    for(int i = 0; i < n; i++){
        unsigned long s;
        cin >> s;
        bitset<20> bs(s);
        v[i] = bs;
    }

    vector<int> cnt(20);

    int left = 0;
    int right = -1;
    ll ans = 0;

    while(true){

        if( check(cnt) && right < n ){
            right ++;
            ans += (right - left);
            if(right != n) add( cnt, v[right] );
        }
        else{
            ans += (right - left);
            sub( cnt, v[left] );
            left ++;
        }

        if(right == n && left == n) break;

    }
    
    cout << ans / 2 << endl;


}

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

int main() {
    int N; cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++)
        cin >> d.at(i);
    int sum = 0;
    for(int i = 0; i < N-1; i++)
        for(int j = i+1;j < N; j++) {
            sum+= d.at(i) * d.at(j);
        }

    cout << sum << endl;
}

Measured memory_bytes: 256
//verified against interviewbit knight problem and AOJ GRL_1_A
//following is a implementation on directed graph

#include <bits/stdc++.h>

using namespace std;

const int pinf = (1U << 31) - 1;

struct Edge {
  int dst;
  int wgt;
  Edge(int idst, int iwgt) : dst(idst), wgt(iwgt) {};
};

class Graph {
  private:
    int V;
    int E;
    vector <vector <Edge>> adj;
  public:
    Graph(int n, int m);
    void addEdge(int src, int dst, int wgt);
    void dijkstra(int src);
};

Graph::Graph(int n, int m) {
  this->V = n;
  this->E = m;
  adj.resize(n);
}

void Graph::addEdge(int src, int dst, int wgt) {
  adj[src].push_back(Edge(dst, wgt));
}

void Graph::dijkstra(int src) {
  set <pair <int, int>> st;
  vector <int> dist(V, pinf);
  dist[src] = 0;
  st.emplace(dist[src], src);

  while (!st.empty()) {
    pair <int, int> pr = *(st.begin());
    st.erase(st.begin());
    int u = pr.second;

    for (Edge &edge : adj[u]) {
      int v = edge.dst;
      int w = edge.wgt;

      if (dist[u] + w < dist[v]) {
        if (dist[v] != pinf) {
          st.erase(st.find(make_pair(dist[v], v)));
        }
        dist[v] = w + dist[u];
        st.emplace(dist[v], v);
      }
    }
  }

  
  //..printing distances from source
  for (int i = 0; i < V; i++) {
    if (dist[i] == pinf) {
      cout << "INF" << endl;
    } else {
      cout << dist[i] << endl;
    }
  }
}

int main() {
  int n, m, src;
  cin >> n >> m >> src;
  Graph g(n, m);
  int s, t, w;
  for (int i = 0; i < m; i++) {
    cin >> s >> t >> w;
    g.addEdge(s, t, w);
  }
  g.dijkstra(src);
  return 0;
}


Measured memory_bytes: 14088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    public class AGC_026_A
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var str = Console.ReadLine().Split(' ');
            var A = Array.ConvertAll(str, int.Parse);

            long ans = 0;
            long cnt = 1;

            for (long i = 0; i <= N; i++)
            {
                if (i != 0 && i != N)
                {
                    if (A[i] == A[i - 1])
                    {
                        cnt++;
                    }
                    else
                    {
                        ans += cnt / 2;
                        cnt = 1;
                    }
                }
                else if (i == N)
                {
                    ans += cnt / 2;
                }
            }
            Console.WriteLine(ans);
            //Console.WriteLine(result);
            Console.Read();
        }
    }
}

Measured memory_bytes: 11092
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;

using namespace std ;
bigint dp[100001] ;
bigint frogJump( string str , int N , int D ){
    for( int i = 0 ; i < N ; i++ ){
        dp[i] = INT_MAX ;
        if( str[i] == '0' )
            continue ;
            for( int j = i - D ; j < i ; j++ ){
                dp[i] = min( dp[i] , dp[j] + 1 ) ;
            }
    }
    return dp[N-1] ;
}
int main(){
    FAST();
    int N , K ; cin >> N >> K ;
    int arr[N] ;
    for( int i = 0 ; i < N ; i++ )
        cin >> arr[i] ;
    bigint dp[100001] ;
    dp[0] = 0 ;
    dp[1] = abs( arr[1] - arr[0] ) ;
    for( int i = 2 ; i < N ; i++ ){
        dp[i] = INT_MAX ;
        for( int j = i - K ; j < i ; j++ ){
            if( j < 0 )
                continue ;
            dp[i] = min( dp[i] , dp[j] + abs( arr[i] - arr[j]) ) ;
        }
    }
    cout << dp[N-1] << endl ;
    return 0 ;
}


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

using namespace std;

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k, x, ans = 0;
    cin >> n >> k;
    vector < int > a;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < k; ++i) ans += a[i];
    cout << ans;
    return 0;
}



Measured memory_bytes: 3668
#y,m,d=map(int,input().split())
#a,b=map(int,input().split())
n=int(input())
#a=int(input())
#b=int(input())
#s=list(input())
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
#b=list(map(int,input().split()))
#b=list(map(int,input().split()))
a=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
dic={}
for i in range(n):
    dic[a[i]]=i+1
dic=sorted(dic.items(),key=lambda x:x[0])
ans=[]
for i in range(n):
    ans.append(dic[i][1])
print(*ans)

Measured memory_bytes: 24796
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

void dfs(vector<vector<ll> > &g, vector<ll> &w, int from, int now){
    for (auto e : g[now]){
        if (e == from) continue;
        w[e] += w[now];
        dfs(g,w,now,e);
    }
}


int main(){
    int N,Q; cin >> N >> Q;
    vector<vector<ll> > g(N);
    vector<ll> w(N,0);
    for (int i = 0; i < N-1; i++){
        int a,b; cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i = 0; i < Q; i++){
        int p,x; cin >> p >> x; p--;
        w[p] += x;
    }
    for (auto e : g[0]){
        w[e] += w[0];
        dfs(g,w,0,e);
    }
    for (auto e : w){
        cout << e << " ";
    }
    cout << endl;
}

Measured memory_bytes: 30464
#include <bits/stdc++.h>
#include <atcoder/maxflow>

using namespace std;
using namespace atcoder;

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  REP(i, SZ(v)) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  REP(i, n) {
    cin >> s[i];
  }

  mf_graph<int> flow(2 * n * m + 2);

  vi dx = {-1, 1, 0, 0};
  vi dy = {0, 0, -1, 1};
  REP(i, n) {
    REP(j, m) {
      if (s[i][j] == '#') continue;
      REP(k, 4) {
        int ni = i + dx[k], nj = j + dy[k];
        if (!(0 <= ni && ni < n && 0 <= nj && nj < m)) continue;
        if (s[ni][nj] == '#') continue;

        if ((i + j) % 2 == 0) flow.add_edge(1 + i * m + j, n * m + 1 + ni * m + nj, 1);
        else flow.add_edge(1 + ni * m + nj, n * m + 1 + i * m + j, 1);
      }
    }
  }

  REP(i, n) {
    REP(j, m) {
      if (s[i][j] == '#') continue;
      flow.add_edge(0, 1 + i * m + j, 1);
      flow.add_edge(n * m + 1 + i * m + j, 2 * n * m + 1, 1);
    }
  }

  int val = flow.flow(0, 2 * n * m + 1);
  cout << val << endl;

  auto g = flow.edges();
  for(auto &e: g) {
    if(e.from == 0) continue;
    if(e.flow == 0) continue;
    int div = (e.from - 1) / (n * m);
    if(div != 0) continue;

    int i1 = (e.from-1) / m, j1 = (e.from - 1) % m;
    int i2 = (e.to - 1 - n*m) / m, j2 = (e.to - 1 - n*m) % m;

    //cout << i1 << " " << j1 << endl;
    //cout << i2 << " " << j2 << endl;
    //cout << endl;

    REP(k, 4) {
      int ni = i1+dx[k], nj = j1+dy[k];
      if(i2 == ni && j2 == nj) {
        if(k == 0) {
          s[i1][j1] = '^';
          s[i2][j2] = 'v';
        } else if(k == 1) {
          s[i1][j1] = 'v';
          s[i2][j2] = '^';
        } else if(k == 2) {
          s[i1][j1] = '<';
          s[i2][j2] = '>';
        } else {
          s[i1][j1] = '>';
          s[i2][j2] = '<';
        }
        break;
      }
    }
  }

  REP(i, n) {
    cout << s[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 7912
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x1:f64 = read();
    let y1:f64 = read();
    let x2:f64 = read();
    let y2:f64 = read();
    let ans = ((x1-x2).powf(2.0) + (y1-y2).powf(2.0)).sqrt();
    println!("{}", ans);
}


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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const ll llinf = LLONG_MAX;
const ull ullinf = ULLONG_MAX;

int n, k;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;
#endif
  string s; cin >> s;
  int plus = 0;
  int minus = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == '+') plus++;
    else minus++;
  }
  cout << plus - minus << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<string> strs(n);
    for(int i = 0; i < n; i ++){
        cin >> strs[i];
        if(i > 0 && strs[i].front() != strs[i-1].back()){
            cout << "No\n";
            return 0;
        }
    }

    sort(strs.begin(), strs.end());
    for(int i = 1; i < n; i ++){
        if(strs[i] == strs[i-1]){
            cout << "No\n";
            return 0;
        }
    }
    
    cout << "Yes\n";

}


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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, less<int>, null_type, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 1e5 + 667;
int a[3][3];
bool used[3][3];

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

    for(int i = 0;i<3;i++){
        for(int j = 0;j<3;j++){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    while(n--){
        int b;
        cin >> b;
        for(int i = 0;i<3;i++){
            for(int j = 0;j<3;j++){
                if(a[i][j] == b) used[i][j] = true;
            }
        }
    }
    if(used[0][0] == true && used[1][1] == true && used[2][2] == true){
        cout << "Yes" << "\n";
        return 0;
    }
    if(used[0][2] == true && used[1][1] == true && used[2][0] == true){
        cout << "Yes" << "\n";
        return 0;
    }
    for(int i = 0;i<3;i++){
        int j;
        for(j = 0;j<3;j++){
            if(used[i][j] == false) break;
        }
        if(j == 3){
            cout << "Yes";
            return 0;
        }
    }
    for(int i = 0;i<3;i++){
        int j;
        for(j = 0;j<3;j++){
            if(used[j][i] == false) break;
        }
        if(j == 3){
            cout << "Yes" << "\n";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


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

int main(){
    int n,t=0,h=0,len;
    string taro,hana;
    
    cin >> n;
    
    for(int i = 0;i<n;i++){
        cin >> taro >> hana;
        if(taro.size()>hana.size()){
            len = taro.size();
        }else{
            len = hana.size();
        }
        for(int j = 0;j<len;j++){
            if(taro==hana){
                t += 1;
                h += 1;
                break;
            }else if(taro[j]>hana[j]){
                t+=3;
                break;
            }else if(taro[j]<hana[j]){
                h+=3;
                break;
            }
        }
    }
    cout << t <<" "<< h << endl;
    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  vector<int> stair(n+1);
  for(int i=0;i<m;i++){
    int a;cin>>a;
    stair[a]=-1;
  }
  stair[n]=1;
  for(int i=n-1;i>=0;i--){
    if(stair[i]==-1){
      stair[i]++;
      continue;
    }
    if(i==n-1){
      stair[i]=stair[n];
      continue;
    }
    else stair[i]=(long long)(stair[i+1]+stair[i+2])%1000000007;
  }
  cout<<stair[0]<<endl;
}

Measured memory_bytes: 640
from collections import deque
n, m = map(int, input().split())
g = [[] for _ in range(n)]
colors = {}
done = set()

for i in range(m):
    s, t = map(int, input().split())
    g[s].append(t)
    g[t].append(s)

# print(g)
color = 0

for i in range(n):
    if i in colors:
        continue
    done.clear()
    color += 1
    q = deque()
    q.append(i)

    while q:
        node = q.popleft()
        colors[node] = color
        for next in g[node]:
            if next not in done:
                done.add(next)
                q.append(next)

# print(colors)

Q = int(input())
qs = []
for i in range(Q):
    s, t = map(int, input().split())
    qs.append([s, t])

for i in range(len(qs)):
    if colors[qs[i][0]] == colors[qs[i][1]]:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 34436
#include<iostream>
using namespace std;
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
    int l,r,largest;
    l = 2*i;
    r = 2*i+1;
    
    if(l<=H && A[l]>A[i]) largest = l;
    else largest = i;
    if(r<=H && A[r]>A[largest]) largest = r;
    
    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

int main(){
    cin >> H;
    
    for(int i = 1;i<=H;i++) cin >> A[i];
    
    for(int i = H/2;i>=1;i--) maxHeapify(i);
    
    for(int i = 1;i<=H;i++){
        cout << " " << A[i];
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 5048
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
 
#define REP(i,n) for(int i=0;(i)<(n);(i)++)
 
int main() {
	string s;
	cin >> s;
 
	int len = s.length();
 
	for (int i = 0;i < len;i++) {
		if (s[i] != s[len - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
 
 
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<iii> viii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> si;
typedef set<ll> sll;
#define pb push_back
#define I insert
#define INF 1000000000
#define LINF (ll)INF*INF
#define all(x) x.begin(),x.end()
#define F first
#define S second
ll check(ll m, vi &a)
{
	ll res=0;
	for(int i=0;i<a.size();i++)
	{
		res+=abs(a[i]-m);
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;cin>>n;
	vi a(n);
	ll mean=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]-=(i+1);
		
	}
	sort(all(a));
	ll res1=(check(a[n/2],a));
	if(n%2==0)
	{
		res1= min(check(a[n/2+1],a),res1);
	}
	cout<<res1<<endl;
	return 0;
}
/*
	Two roads diverged in a wood, and I—
	I took the one less traveled by,
	And that has made all the difference.
*/

Measured memory_bytes: 1024
s = input()
if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
else:
    print(1)


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
// const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int h, n, sum = 0;
  cin >> h >> n;
  rep(i, 0, n) {
    int a;
    cin >> a;
    sum += a;
  }

  if(sum >= h) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 256
N, M = gets.split(' ').map(&:to_i)
A = gets.split(' ').map(&:to_i)

mods = Hash.new(0)
mods[0] = 1
sum = 0
N.times do |i|
  sum += A[i]
  mods[sum % M] += 1
end

puts mods.values.collect{|n| n * (n - 1) / 2}.inject(:+)

Measured memory_bytes: 13060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main(){
  ll a;
  ld b;
  cin>>a>>b;

  if(a==0||b==0){
    cout << 0 << endl;
    return 0;
  }

  ll c=b*1000;

  ll d=c/1000;
  ll e=(c%1000)/10;

  ll ans=a*d+(a*e)/100;

  cout << ans << endl;
}


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

using namespace std;
using ll = long long;

#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)

int main()
{
    ll H,W;
    cin >> H >> W;
    
    char s[H+2][W+2];
    rep(i, H) rep(j, W) cin >> s[i + 1][j + 1];

    ll d[2][8] = {
        {-1, -1, 0, +1, +1, +1, 0, -1},
        {0, +1, +1, +1, 0, -1, -1, -1}
    };

    REP(i, 1, H+1) REP(j, 1, W+1) {
        if(s[i][j] == '.'){
            int n=0;
            rep(k, 8) n += s[i + d[0][k]][j + d[1][k]] == '#' ? 1 : 0;
            s[i][j] = n+'0';
        }
    }

    REP(i, 1, H+1) {
        REP(j, 1, W+1) {
            cout << s[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<pi>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}


double memo[301][301][301];
double f(int i, int j, int k, int n) {
    if(i + j + k == 0) return 0;
    if(memo[i][j][k] != 0) return memo[i][j][k];
    int s = i + j + k;
    double ret = n - s;
    if(i) ret += (f(i - 1, j, k, n) + 1) * i;
    if(j) ret += (f(i + 1, j - 1, k, n) + 1) * j;
    if(k) ret += (f(i, j + 1, k - 1, n) + 1) * k;
    ret /= s;
    memo[i][j][k] = ret;
    return ret;
}



int main(){
    int n, r, a = 0, b = 0, c = 0;
    setp(12);
    cin >> n;
    rep(i, n) {
        cin >> r;
        if (r == 1) a ++;
        else if (r == 2) b ++;
        else c ++;
    }
    co(f(a, b, c, n));
}



Measured memory_bytes: 111244
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        A = list(map(int, input().split()))

        ans = 1
        state = 0
        for i in range(1, N):
            if state == 1:
                if A[i - 1] <= A[i]:
                    continue
                else:
                    ans += 1
                    state = 0
            elif state == -1:
                if A[i - 1] >= A[i]:
                    continue
                else:
                    ans += 1
                    state = 0
            elif state == 0:
                if A[i - 1] == A[i]:
                    continue
                elif A[i - 1] > A[i]:
                    state = -1
                elif A[i - 1] < A[i]:
                    state = 1
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<ll> water(n);
    rep(i, n) cin >> water[i];

    ll s = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) s += water[i];
        else s -= water[i];
    }

    vector<ll> mountains(n);
    mountains[0] = s;
    for (int i = 1; i < n; i++) {
        ll a = mountains[i - 1];
        ll w = water[i - 1];
        mountains[i] = 2 * w - a;
    }

    for (ll a : mountains) cout << a << endl;

}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		int m = in.nextInt();
		int[] b = new int[m];
		for(int i = 0; i < m; i++){
			b[i] = in.nextInt();
		}
		int count = 0;
		for(int bb : b){
			for(int aa : a){
				if(bb == aa){
					count++;
					break;
				}
			}
		}
		System.out.println(count);
		in.close();
	}

}

Measured memory_bytes: 40104
N,K = map(int,input().split())
S = input()
fortune = 0
nums = 0
count = 0
for i in range(N):
    if i != N-1 and S[i] == S[i+1]:
        count += 1
    else:
        fortune += count
        count = 0
for i in range(N):
    if i != N-1 and S[i] != S[i+1]:
        nums +=1
if nums%2 ==0 and nums//2 <= K:
    print(fortune + nums)
elif nums%2 == 0 and K <= nums//2:
    print(fortune + K*2)
elif nums%2 ==1 and (nums-1)//2+1 <= K:
    print(fortune + nums)
elif nums%2 ==1 and K <= (nums-1)//2+1:
    print(fortune + K*2)

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

int main(void){
  int N, X;
  cin >> N >> X;
  
  vector<int> donut(N);
  
  for (int i = 0; i < N; i++) {
    cin >> donut.at(i);
  }
  
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    sum += donut.at(i);
  }
  
  int residue = X - sum;
  
  sort(donut.begin(), donut.end());
  
  int mi = donut.at(0);
  
  int count = N;
  
  while (residue >= mi) {
    residue -= mi;
    count++;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    cout << (0 <= x-r && x+r <= w && 0 <= y-r && y+r <= h ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 101;
const int K = 1e5+1;
using ll = long long;
int n, k, arr[N];
bool dp[K][2];
int main()
{
    scanf("%d %d", &n, &k);
    int lim = inf;
    for(int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        lim = min(lim, arr[i]);
    }
    for(int stones = 0; stones <= k; stones++) {
        for(int move = 1; move >= 0; move--) {
            for(int i = 0; i < n; i++) {
                if(move) {
                    if(stones < lim) dp[stones][1]=0;
                    else {
                        if(stones-arr[i] >= 0)dp[stones][1] |= dp[stones-arr[i]][0];
                    }
                }
                else {
                    if(dp[stones][1]) dp[stones][0]=0;
                    else dp[stones][0]=1;
                }
            }
        }
    }
    if(dp[k][1]) printf("First\n");
    else printf("Second\n");
    return 0;
}

Measured memory_bytes: 3956
my $s = <>;
chomp $s;
my @PDB;
my @MDB;
my $state  =0;
my $mstate =0;
my $pmmax  =0;
my $pmmin  =0;
my $sum=0;
for(my $i=0;$i<$s;$i++){
    my $line = <>;chomp $line;
    my @dat = split(//,$line);
    #print "@dat\n";
    my $min=0;
    my $max=0;
    my $total=0;
    for(my $j=0;$j<=$#dat;$j++){
        #print "$dat[$j]\n";
      if($dat[$j] eq '(' ){
         #print "plus \n";
        $total++;
      }else{
        $total--;
      }
      if($min >$total ){ $min =$total;}
      if($max <$total ){ $max =$total;}
    }
    $max = $max - $total;
    #print "$total $min\n";
    $sum = $sum + $total;
    if($total ==0){
      if($pmmin > $min){$pmmin = $min;}
    }elsif($total >0){
      if( $min >=0 ){#-にならないならここで足してしまう
        $state = $state + $total;
        next;
      }
      my @row = ($total,$min);
      push (@PDB,\@row);
    }else{
      $min = $min - $total;#左からみた最小
      if( $min >=0){
        $mstate = $mstate + $total;
        #print"$min $mstate\n";
        next;
      }
      my @row = ($total,$min);
      push (@MDB,\@row);
    }
    #print "$sum $total \n";
}
#print "$state $mstate \n";

@PDB = sort{ $b->[1] <=> $a->[1]} @PDB;
#my @amari;
for(my $i=0;$i<=$#PDB;$i++){
  if(($state+$PDB[$i][1]) >= 0){#採用
    $state = $state + $PDB[$i][0];
    #print "@{$PDB[$i]} state $state \n ";
  }else{
    print "No";exit;
  }
}
#print "$state $pmmin \n";
if( ($state+$pmmin) < 0){ print "No";exit;}
#print "MDB $#MDB\n";

@MDB = sort{ $b->[1] <=> $a->[1]} @MDB;
for(my $i=0;$i<=$#MDB;$i++){
  if((-$mstate+$MDB[$i][1]) >= 0){#採用
    $mstate = $mstate + $MDB[$i][0];
    #print "@{$MDB[$i]} mstate $mstate \n ";
  }else{
    print "No";exit;
  }
}
$state = $state + $mstate;

if( $state == 0){
    print "Yes";
}else{
    print "No";
}


Measured memory_bytes: 12988
N = int(input())
MOD = 10 ** 9 + 7
dp = [0] * 2010
dp[0] = 1
for i in range(3, N + 1):
    for j in range(i - 3 + 1):
        dp[i] = (dp[i] + dp[j]) % MOD
print(dp[N])


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

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int c = 0;
	for (int i = 0; i <= n - 3; ++i) {
		if (s.substr(i, 3) == "ABC") ++c;
	}
	cout << c;
}

Measured memory_bytes: 256
s = input()
t = input()
mini = -1 
for i in range(len(s) - len(t)+1):
    temp = 0
    for j in range(len(t)):
        if(s[j + i] != t[j]):
            temp+=1
    if(mini == -1 or temp < mini):
        mini = temp
print(mini)

Measured memory_bytes: 72852
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<vector<int>> vec(N,vector<int> (2));
  for(int i=0;i<N;i++){
    cin>>vec[i][0]>>vec[i][1];
  }
  
  
  int sum=N;
  
  for(int i=0;i<N;i++){
    sum+=(vec[i][1]-vec[i][0]);
  }
  
  cout<<sum<<endl;
}

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

using namespace std;

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


void f(vector<int>& v){

v.push_back(v.front());
v.erase(v.begin());

}

void g(vector<int>& v){

v.insert(v.begin(),v.back());
v.pop_back();

}

int main(){

	while(true){

	vector<int>NS(4); NS[0]=1; NS[1]=5; NS[2]=6; NS[3]=2;
	vector<int>EW(4); EW[0]=1; EW[1]=3; EW[2]=6; EW[3]=4;
	vector<int>D(4);  D[0]=5;  D[1]=3;  D[2]=2;  D[3]=4;

	int n; string a;

	cin >> n;
	if(n==0) break;

    int c=1;
	rep(i,n){

	cin >> a;

	if(a=="North"){

		g(NS);
		c+=NS[0];
		EW[0]=NS[0]; EW[2]=NS[2];
		D[0]=NS[1];  D[2]=NS[3];
	}

	if(a=="East"){

		g(EW);
		c+=EW[0];
		NS[0]=EW[0]; NS[2]=EW[2];
		D[1]=EW[1];  D[3]=EW[3];
	}

	if(a=="South"){

		f(NS);
		c+=NS[0];
		EW[0]=NS[0]; EW[2]=NS[2];
		D[0]=NS[1];  D[2]=NS[3];
	}

	if(a=="West"){

		f(EW);
		c+=EW[0];
		NS[0]=EW[0]; NS[2]=EW[2];
		D[1]=EW[1];  D[3]=EW[3];
	}

	if(a=="Right"){

		g(D);
		c+=NS[0];
		NS[1]=D[0]; NS[3]=D[2];
		EW[1]=D[1]; EW[3]=D[3];
	}

	if(a=="Left"){

		f(D);
		c+=NS[0];
		NS[1]=D[0]; NS[3]=D[2];
		EW[1]=D[1]; EW[3]=D[3];
	}
	}

	cout << c << endl;

	}

	return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>

int main(){

  int n;
  scanf("%d",&n);
  char s[n];
  scanf("%s",&s);
  int count=0;

  for(int i=0;i<n;i++){
    if(s[i]=='A' && i+2<n){
      if(s[i+1]=='B' && s[i+2]=='C'){
        count++;
      }
    }
  }

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

Measured memory_bytes: 1732
# フェルマーの小定理
X, Y = map(int, input().split())

m = 1000000007


def make_factorial_table(n):
    result = [0] * (n + 1)
    result[0] = 1
    for i in range(1, n + 1):
        result[i] = result[i - 1] * i % m
    return result


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m


if (X + Y) % 3 != 0:
    print(0)
    exit()

a = (2 * Y - X) // 3
b = (2 * X - Y) // 3

if a < 0 or b < 0:
    print(0)
    exit()

n = a + b
fac = make_factorial_table(n)
print(mcomb(n, a))


Measured memory_bytes: 35188
def solve():
    N = int(input())
    if N == 0: return -1
    score = []
    for i in range(N):
        s = input().split()
        win, draw = 0, 0
        for j in range(1, len(s)):
            if s[j] == '1': continue
            elif s[j] == '0': win += 1 
            else : draw += 1
        score.append((s[0], win, draw))
    res = sorted(score, reverse=True, key=lambda x:(x[1], x[2]))
    for s in res: print(s[0])

while True:
    if solve() != None: break


Measured memory_bytes: 5600
#include <iostream>
#include <vector>

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N, M;
        cin >> N >> M;
        if(!N && !M) break;
        vector<int> players(N);
        for(int i = 0; i < N; ++i) players[i] = i+1;
        int pos = N-1;
        for(int phase = 0; phase < N-1; ++phase) {
            const int SIZE = players.size();
            pos = (pos+M) % SIZE;
            players.erase(players.begin()+pos);
            --pos;
        }
        cout << players.front() << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
import java.util.Scanner;

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

        boolean zero = true;
        int cntMiss = 0;
        for (int i = 0; i < len; i++) {
            char c = s.charAt(i);

            if (zero) {
                if (c == '0') {

                } else {
                    cntMiss++;
                }
            } else {
                if (c == '1') {

                } else {
                    cntMiss++;
                }
            }
            zero = !zero;
        }
        int cntMiss2 = 0;
        zero = false;
        for (int i = 0; i < len; i++) {
            char c = s.charAt(i);
            if (zero) {
                if (c == '0') {

                } else {
                    cntMiss2++;
                }
            } else {
                if (c == '1') {

                } else {
                    cntMiss2++;
                }
            }
            zero = !zero;
        }
        if (cntMiss < cntMiss2) {
            System.out.println(cntMiss);
        } else {
            System.out.println(cntMiss2);
        }
        sc.close();

    }
}

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

int main(){
  int N;
  cin >> N;
  int T[N+1],X[N+1],Y[N+1];
  for(int i=0;i<N;i++){
    cin>> T[i] >> X[i] >> Y[i];
  }
  T[-1]=X[-1]=Y[-1]=0;
  bool flg=true;
  for(int i=0; i<N ;i++){
    int t=T[i]-T[i-1];
    int px=abs(X[i]-X[i-1]);
    int py=abs(Y[i]-Y[i-1]);
    if(t<px+py||(t-px-py)%2!=0)flg=false;
  }
  if(flg) cout << "Yes" <<"\n";
  else cout << "No" << "\n";
}

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

int main(){
  
  string s;
  cin>>s;
  
  int i=0, rainy=0;
  while(i<3){
  if(s[i]=='R'){
  	if(i>0 && s[i-1]=='R'){
    	rainy++;
    }
    else
      rainy=1;
  }
    i++;
  }

cout<<rainy;
  return 0;
}

Measured memory_bytes: 3536
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n, k, a[SIZE];

  scanf("%d%d", &n, &k);

  int pos1 = 0;
  
  for(int i=0;i<n;i++){
    scanf("%d", a+i);
    if(a[i] == 1) pos1 = i;
  }

  int ans = INF;

  int L = pos1;
  int R = n - pos1 - 1;
  
  for(int i=0;i<k;i++){
    ans = min(ans, max(0, L - i + k-2)/(k-1) + max(0, R-(k-i-1) + k-2)/(k-1));
  }
  
  cout << ans + 1 << endl;
  
  
  return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
  int n,d,X[21][21],ans=0;
  cin>>n>>d;
  rep(i,n)rep(j,d) cin>>X[i][j];
  rep(i,n)for(int j=i+1;j<n;j++){
    ll a=0;
    rep(k,d) a+=pow((X[i][k]-X[j][k]),2);
    if(pow(ll(sqrt(a)),2)==a) ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 256
// AOJ 1067 Cutting a Chocolate
// 2018.3.17 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//#define getchar_unlocked()  getchar()
int in()        // get a non-negative integer from stdin
{
	int n = 0, c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

double dbl()    // get a non-negative real number from stdin  
{
	double x, y;
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	x = n;
	if (c == '.') {
		y = 1, c = getchar_unlocked();
		do y *= 0.1, x += y * (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	}
	return x;
}

#define EQ(a,b)   (fabs(a-b)<1e-7)

typedef struct { double x, y; } P;
P p[30002];

int hl[30002], hr[30002], s[30002], a[30002], d[30002];

int binary_search(int *tbl, int hi, int key)
{
	int lo = 0, mi, r;

    while (lo < hi) {
        mi = (lo + hi) >> 1;
		r = tbl[mi] - key;
		if (!r) return mi;
        if (r < 0) lo = mi + 1; else hi = mi;
    }
	return lo-1;
}

int cmp(P *a, P *b)
{
	double d;
	d = a->y - b->y; if (d < 0) return -1; if (d > 0) return 1;
	d = a->x - b->x; if (d < 0) return -1; if (d > 0) return 1;
	return 0;
}

int main()
{
	int n, m, w, h, wh2, S, i, j, ans;
	double x, y, y1, y2;

	while (n = in()) {
		m = in()+1, w = in(), h = in(), wh2 = (w*h)<<1, S = wh2-(in()<<1);
		for (i = 1; i < m; i++) {
			hl[i] = in(), hr[i] = in(), a[i] = 0;
			s[i] = (hl[i] + hr[i])*w, d[i] = hr[i]-hl[i];
		}
		for (i = 0; i < n; i++) p[i].x = dbl(), p[i].y = dbl();
		qsort(p, n, sizeof(P), cmp);

		j = 1; for (i = 0; i < n; i++) {
			x = p[i].x, y = p[i].y;
			while (1) {
				y1 = d[j-1] * x / w + hl[j-1];
				y2 = d[j  ] * x / w + hl[j  ];
				if (y1 < y) {
					if (y < y2) break;
					j++;
				} else j--;
			}
			a[j]++;
		}
		for (i = 1; i < m; i++) a[i] += a[i-1];

		if      (S == 0  ) { printf("%d\n", n); continue; }
		else if (S == wh2) { puts("0");         continue; }

		j = binary_search(s, m, S); ans = a[j++];
		for (i = 1; j < m; j++) {
			while (s[j]-s[i] > S) i++;
			if (a[j]-a[i] > ans) ans = a[j]-a[i];
		}
		printf("%d\n", n - ans);
	}
	return 0;
}



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

int main()
{
    int n, x;
    cin >> n >> x;
    int count = 0;
    int min_m = 100000;
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        x -= m;
        count++;
        min_m = min(min_m, m);
    }
    count += x / min_m;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 100010
#define int long long

typedef pair<int, int> P;

int par[MAX * 2];
int rk[MAX * 2];

struct edge{ int u, v, cost; };

edge es[MAX * 2];
int n;

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rk[i] = 0;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rk[x] < rk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rk[x] == rk[y]) rk[x]++;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}

bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}

int kruskal() {
  int m = 2 * n - 2;
  sort(es, es + m, comp);
  init(m);
  int res = 0;
  for (int i = 0; i < m; i++) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

signed main() {
  cin >> n;
  int x[n], y[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  P xres[n], yres[n];
  for (int i = 0; i < n; i++) {
    xres[i] = P(x[i], i);
    yres[i] = P(y[i], i);
  }
  sort(xres, xres + n);
  sort(yres, yres + n);
  for (int i = 0; i < n - 1; i++) {
    edge tmp;
    tmp.u = xres[i].second;
    tmp.v = xres[i + 1].second;
    tmp.cost = abs(xres[i + 1].first - xres[i].first);
    es[i] = tmp;
  }
  for (int i = n - 1; i < 2 * n - 2; i++) {
    edge tmp;
    tmp.u = yres[i - n + 1].second;
    tmp.v = yres[i - n + 2].second;
    tmp.cost = abs(yres[i - n + 1].first - yres[i - n + 2].first);
    es[i] = tmp;
  }
  /*
  for (int i = 0; i < 2 * n - 2; i++) {
    cout << es[i].u << " " << es[i].v << " " << es[i].cost << endl;
  }
  */
  cout << kruskal() << endl;
  return 0;
}


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

int selectionSort(int A[], int n) {
    int counter = 0;
    
    for(int i = 0; i < n; i++) {
        int minj = i;
        
        for(int j = i; j < n; j++) {
            if(A[j] < A[minj]) {
                minj = j;
            }
        }
        
        int temp = A[i];
        A[i] = A[minj];
        A[minj] = temp;
        if(i != minj) counter++;
    }
    return counter;
}

int main(void){
    // Here your code !
    int A[100], n;
    
    cin >> n;
    
    for(int i = 0; i < n; i++) {
        cin >> A[i];
    }
    
    int counter = selectionSort(A,n);
    
    for(int i = 0; i < n; i++) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << counter << endl;
}

Measured memory_bytes: 1160