akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<string, int> P;

const double PI = 3.14159265358979323846;

const int mod = 1000000007;

int A[3][3];
int used[3][3];

int main(int argc, char *args[]) {
	rep(i, 3) {
		rep(j, 3) {
			cin >> A[i][j];
		}
	}
	int n; cin >> n;
	vector<int> b(n);
	rep(i, n) cin >> b[i];
	rep(k, n) {
		rep(i, 3) {
			rep(j, 3) {
				if (b[k] == A[i][j]) {
					used[i][j] = true;
				}
			}
		}
	}
	bool flag = false;
	rep(i, 3) {
		if (used[i][0] && used[i][1] && used[i][2]) {
			flag = true;
		}
	}
	rep(j, 3) {
		if (used[0][j] && used[1][j] && used[2][j]) {
			flag = true;
		}
	}
	if (used[0][0] && used[1][1] && used[2][2]) {
		flag = true;
	}
	if (used[0][2] && used[1][1] && used[2][0]) {
		flag = true;
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int n,m,p;
    while(1){
        cin>>n>>m>>p;
        if(n==0&&m==0&&p==0)break;
        int x[n];
        double sum=0;
        rep(i,n){
            cin>>x[i];
            sum+=x[i];
        }
        sum=sum*(100-p);
        if(x[m-1]==0){
            cout<<0<<endl;
            continue;
        }
        sum/=x[m-1];
        cout<<floor(sum)<<endl;
    }
    
//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 3240
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b, w):
        self.graph[a].append((b, w))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    def __init__(self, graph, s):
        self.g = graph.graph
        self.dist = defaultdict(lambda: -float('inf'))
        self.dist[s] = 0
        self.prev = defaultdict(lambda: None)
        self.x = 0
        self.y = 0

        self.Q = []
        heappush(self.Q, (self.dist[s], s))

        c = 0
        while self.Q:
            c += 1
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, w in self.g[u]:
                alt = dist_u + w
                if self.dist[v] < alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))
            if c == 2100:
                self.x = self.dist[N]
            if c >= 200000:
                self.y = self.dist[N]
                break
    def s_d(self, goal):
        return self.dist[goal]

    def s_p(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

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

g_a = Graph()
for i in range(M):
    a, b, w = list(map(int, input().split()))
    g_a.add_edge(a, b, w)

s = 1
d_a = Dijkstra(g_a, s)

if d_a.x == d_a.y:
    print(d_a.dist[N])
else:
    print("inf")



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

#define int long long
#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)

const int N = 100005;

int n, a[N], suf[N];

main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    cin >> n;
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
        suf[i] = a[i];
    }
    for (int i = n - 1; i >= 0; i--) suf[i] += suf[i + 1];
    long long res = 0;
    int cur = 1;
    for (int i = 0; i <= n; i++) {
        if (cur < a[i]) return cout << -1, 0;
        cur = cur - a[i];
        res += a[i];
        if (cur >= suf[i + 1]) {
            res += suf[i + 1];
            for (int j = i + 1; j <= n; j++) {
                res += suf[j];
            }
            return cout << res, 0;
        } else {
            res += cur;
            cur = cur * 2;
        }
    }
    return 0;
}

Measured memory_bytes: 5188
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <cassert>

using namespace std;

const int MAX_V = 1001;
const int INF   = INT_MAX;

struct Edge {
  int to;
  int cost;
};

int          V;
vector<Edge> G[MAX_V];
int          d[MAX_V];
int          prev[MAX_V];

void dijkstra(int s) {
  typedef pair<int, int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V, INF);
  fill(prev, prev + V, -1);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P   p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < (int)G[v].size(); i++) {
      Edge e = G[v][i];

      if (d[e.to] > d[v] + e.cost) {
        d[e.to]    = d[v] + e.cost;
        prev[e.to] = v;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

vector<int> get_path(int t) {
  vector<int> path;

  for (; t != -1; t = prev[t]) {
    path.push_back(t);
  }
  reverse(path.begin(), path.end());
  return path;
}


struct Building {
  int x;
  int y;
};

int distance2(Building *b1, Building *b2) {
  int dx = b1->x - b2->x;
  int dy = b1->y - b2->y;
  return dx * dx + dy * dy;
}

int name[MAX_V];
int rname[MAX_V];
Building building[MAX_V];

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    V = n;

    for (int i = 0; i < n; i++) {
      G[i].clear();
    }
    for (int i = 0; i < n; i++) {
      int b;
      cin >> b;
      name[i] = b;
      rname[b] = i;
      cin >> building[i].x >> building[i].y;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        Building *b1 = building + i;
        Building *b2 = building + j;
        int       d2 = distance2(b1, b2);

        if (d2 <= 50 * 50) {
          int d1 = sqrt(d2);
          Edge e1 = {j, d1};
          G[i].push_back(e1);
          Edge e2 = {i, d1};
          G[j].push_back(e2);
        }
      }
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      int s;
      int g;
      cin >> s >> g;
      dijkstra(rname[s]);
      if (d[rname[g]] == INF) {
        cout << "NA" << endl;
      } else {
        vector<int> path = get_path(rname[g]);
        for (int j = 0; j < (int)path.size(); j++) {
          cout << name[path[j]];
          if (j < (int)path.size() - 1)
            cout << " ";
        }
        cout << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vector<int> A, B;
string S, T;


void input() {
  int x, y, z;
  cin>>N;
  ;
}
int lc[90] = {};
int rec(int n){
  if (lc[n] != INF) {
    return lc[n];
  }
  else {
    lc[n] = rec(n-1) + rec(n-2);
    return lc[n];
  }
}


void solve() {
  rep(i,0,89){
    lc[i]=INF;
  }
  lc[0] = 2;lc[1] = 1;
  rec(89);

  cout<<lc[N]<<endl;

  ;

  
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
use std::ascii::AsciiExt;

fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret
}

fn capslock(c: char) -> char {
    if c.is_uppercase() {
        c.to_ascii_lowercase()
    } else {
        c.to_ascii_uppercase()
    }
}

fn convert(string: &str) -> String {
    string.chars().map(capslock).collect()
}

fn main() {
    let s = getline();

    println!("{}", convert(s.trim()));
}



Measured memory_bytes: 5024
#include <stdio.h>
#include <stdlib.h>

int mas[3][3];
int cpy[3][3];

void input() {
  int i, j;
  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++)
      scanf("%d", &mas[i][j]);
}

void output() {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) printf("%3d", mas[i][j]);
    puts("");
  }
}

void copy(int m[3][3], int t[3][3]) {
  int i, j;

  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++) m[i][j] = t[i][j];
}

int calc() {
  int i, sum = 0;
  for(i = 0; i < 9; i++) {
    int v = mas[i/3][i%3];
    if(v) {
      v--;
      sum += abs(i/3-v/3)+abs(i%3-v%3);
    }
  }
  return sum;
}

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

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int is_in(int x, int y) {
  return 0<=x&&x<3&&0<=y&&y<3;
}

int dfs(int x, int y, int p, int dep, const int lim) {
  int i, h = calc();
  //output();
  if(h == 0) return dep;
  //printf("%d %d %d\n", h, lim, p);
  if(dep+h > lim) return -1;

  for(i = 0; i < 4; i++) {
    int nx = x+dx[i], ny = y+dy[i], res;
    if(~p && i == (p+2)%4) continue;
    if(!is_in(nx, ny)) continue;
    swap(&mas[y][x], &mas[ny][nx]);
    res = dfs(nx, ny, i, dep+1, lim);
    if(~res) return res;
    swap(&mas[y][x], &mas[ny][nx]);
  }

  return -1;
}

void get_empty(int *x, int *y) {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) {
      if(!mas[i][j]) {
	*x = j;
	*y = i;
	return;
      }
    }
  }
}

int solve() {
  int x, y, lim, ans;
  get_empty(&x, &y);
  for(lim = 0; lim < 50; lim++) {
    copy(cpy, mas);
    if((ans = dfs(x, y, -1, 0, lim)) != -1) return ans;
    copy(mas, cpy);
  }
  return -1;
}

int main() {
  input();
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin >> S;
    int sum=700;
    for (int i=0; i<3 ; i++){
        if(S[i] == 'o'){
            sum=sum+100;
                     }
                            }
    cout << sum << endl;
    
   
    return 0;
    // Your code here!
    
}


Measured memory_bytes: 256
<?php
$n = trim(fgets(STDIN));
$t_score = 0;
$h_score = 0;

for($i = 0; $i < $n; $i++){
    $card = explode(" ", trim(fgets(STDIN)));
    $t_card = $card[0];
    $h_card = $card[1];
    if($t_card > $h_card){
        $t_score += 3;
    }elseif ($t_card < $h_card) {
        $h_score += 3;
    }else{
        $t_score += 1;
        $h_score += 1;
    }
}
printf("%d %d%s",$t_score,$h_score,PHP_EOL);

Measured memory_bytes: 15132
import re
s = input()
t = s.replace("x", "")
if t != t[::-1]:
  print(-1)
else:
  k = re.split('[abcdefghijklmnopqrstuvwyz]', s)
  l = len(k)
  ans = 0
  for i in range(l//2):
    ans += abs(len(k[i]) - len(k[l-1-i]))
  print(ans)

Measured memory_bytes: 4528
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	nums := make([]int, 0)
	ps := make([]bool, 56000)
	for i := 2; i < len(ps); i++ {
		ps[i] = true
	}
	for i := 2; i < len(ps); i++ {
		if ps[i] {
			if i%5 == 1 {
				nums = append(nums, i)
				if len(nums) == n {
					break
				}
			}
			for j := i + i; j < len(ps); j += i {
				ps[j] = false
			}
		}
	}

	for i := 0; i < n; i++ {
		if i < n-1 {
			fmt.Printf("%d ", nums[i])
		} else {
			fmt.Println(nums[i])
		}
	}
}


Measured memory_bytes: 640
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
using namespace std;
// #define endl '\n'
#define br cout<<endl
#define mem(a) memset(a,0,sizeof(a))
const double pi=3.141592653589793238;
#define d(x) cout<<x<<endl;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define rev(a) reverse(a.begin(),a.end())
const int inf = 100000000000000000;
#define maxn 1000005
#define mod 1000000007
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) x.begin(),x.end()
#define f(i,n) for(int i=1;i<=n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i+=1)
#define fn(i,k,n) for(int i=k;i>=n;i-=1)
void pv(vector<int> v){  for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<endl;}
void pa(int a[],int n,int p){for (int i = p; i < n+p; ++i){cout<<a[i]<<" ";}cout<<endl;}
int modexp(int x,int y) {
   int res = 1;
   x = x % mod;
   while (y > 0){
       if (y & 1LL)
           res = (res*x) % mod;
       y = y>>1;
       x = (x*x) % mod;  
   }
   return res;
}
int invmod(int a) {
    return modexp(a,mod-2);
}
vector<int> edge[maxn];
void ipgraph(int n,int m) {
    fp(i,1,n) edge[i].clear();
    if(m==0) return;
   fp(i,1,m) {
       int a,b;
       cin>>a>>b;
       edge[a].pb(b);
       edge[b].pb(a);
   } 
}
/*
void dfs(int node,int p)
{
    for(int u : edge[node]) 
    {
        if(u!=p)
        {
            dfs(u,node);
        }
    }
}
*/
///////////////////////////////////////////////////////////////////////////////////
int dp[2001];
void solve()
{
    int n;
    cin>>n;
    dp[0] = 1;
    fp(i,1,n)
    {
        fp(j,3,n)
        {
            if(i-j>=0) {dp[i]+=dp[i-j];dp[i]%=mod;}
        }
    }
    d(dp[n])
}
int32_t main()
{
   IOS;
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
    #endif
   int t=1;
    //cin>>t;
   fp(i,1,t)
   {
       //cout<<"Case "<<i<<": ";
       solve();
   }
}


Measured memory_bytes: 27072
#include <iostream>
#include <vector>
#include<math.h>
using namespace std;
int main()
{
	int n;
	int m;
	vector<int> stork;
	cin >> n;
	cin >>m;
	stork.resize(n + 1);
	stork[0] = 0;
	for (int e = 1; e < n+1; e++)
		cin >> stork[e];
    int answer=0;
    int e=3;
    int run[n+1];
    run[2] = abs(stork[2]-stork[1]);
    run[1] =0;
    while(e<=n){
        int a=0;
        a = run[e-1]+abs(stork[e]-stork[e-1]);
        for(int g=1;g<=m;g++)
        {
            if(e-g<=0)
            {
                break;
            }

            a = min(run[e-g]+abs(stork[e]-stork[e-g]),a);
        }
            run[e] = a;
            e++;
        }
    cout<< run[n]<<endl;
}

Measured memory_bytes: 4020
N = int(input())
A = list(map(int,input().split()))
total = 0
S = [0] * (N + 1)
for i in range(N):
    total += A[i]
    S[i + 1] = total
S.sort()
ans = 0
pre = float("inf")
for i in range(N + 1):
    if S[i] == pre:
        cnt += 1
        ans += cnt
    else:
        cnt = 0
    pre = S[i]
print(ans)

Measured memory_bytes: 25976
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define R register
#define LL long long
#define U unsigned
#define FOR(i,a,b) for(R int i = a;i <= b;++i)
#define RFOR(i,a,b) for(R int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

namespace fastIO{
    #define BUF_SIZE 100000
    #define OUT_SIZE 100000
    #define ll long long
    bool IOerror=0;
    inline char nc(){
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if (p1==pend){
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if (pend==p1){IOerror=1;return -1;}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline void read(int &x){
        bool sign=0; char ch=nc(); x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
    }
    inline void read(ll &x){
        bool sign=0; char ch=nc(); x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
    }
    #undef ll
    #undef OUT_SIZE
    #undef BUF_SIZE
};
using namespace fastIO;

const int MAXN = 200000 + 5;
int N,M;
int a[MAXN];
int x[MAXN],y[MAXN];
int p[MAXN],num[MAXN];
int line[MAXN],ans;

inline void add(int x){
    if(x <= 0) return;
    if(++line[x]==1)ans++;
}

inline void del(int x){
    if(x <= 0) return;
    if(!--line[x]) ans--;
}

int main(){
    read(N);read(M);
    FOR(i,1,N){
        read(a[i]);
        num[a[i]]++;
        add(a[i]-num[a[i]]+1);
    }
    while(M--){
        int x,y;
        read(x);read(y);
        del(a[x]-num[a[x]]+1);
        num[a[x]]--;
        num[y]++;
        add(y-num[y]+1);
        a[x] = y;
        printf("%d\n",N-ans);
    }
    return 0;
}


Measured memory_bytes: 5760
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;

int main(){
	int n,m;
	char str[10000];
	while(1){
		fgets(str,1000,stdin);
		if(strcmp(str,"END OF INPUT\n")==0) break;
		m=0;
		for(n=0;;n++){
			if(str[n]==' '){
				printf("%d",m);
				m=-1;
			}
			if(str[n]=='\n'){ 
				printf("%d",m);
				break;
			}
			m++;
		}
		printf("\n");
	}
	
	
	return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m, p[11], s[11];
vector<int> a[11];
int res = 0;
void check() {
	for (int i = 1; i <= m; i++) {
		int cnt = 0;
		for (auto x : a[i]) {
			cnt += s[x];
		}
		if (cnt % 2 != p[i]) {
			return;
		}
	}
	res += 1;
}

void find(int p = 1) {
	if (p > n) {
		check();
		return;
	}
	s[p] = 1;
	find(p + 1);
	s[p] = 0;
	find(p + 1);
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int k;
		cin >> k;
		for (int j = 1; j <= k; j++) {
			int f;
			cin >> f;
			a[i].push_back(f);
		}
	}
	for (int i = 1; i <= m; i++) {
		cin >> p[i];
	}
	find();
	cout << res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) {
		solve();
	}
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int X, A, B;
  cin >> X >> A >> B;
  cout << (X-A)%B << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
s = input()
leng = len(s)
cnt = 0
mod = 2019

SUM = [0] * (leng + 1)
for i in range(leng):
    temp = int(s[-(i + 1)]) * pow(10, i, mod)
    SUM[i + 1] = (SUM[i] + temp) % mod

#print(SUM)
ans = Counter(SUM)
for i in ans.values():
    if i >= 2:
        cnt += i * (i - 1) // 2
print(cnt)

Measured memory_bytes: 75928
def main():
    S = input()[::-1]

    count = 0

    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        count += mods[current % 2019]
        mods[current % 2019] += 1
        x = x * 10 % 2019

    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68288
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  
   vector<int> hw(M);
  
   for (int i = 0; i < M; i++) {
    cin >> hw.at(i);
   }
  // 入力終わり
  
  int sum = 0;
  
    for (int i = 0; i < M; i++) {
    sum += hw.at(i);
  }
  
  if(N-sum >= 0) {
    cout << N-sum << endl;
  }
  
  else {
    cout << "-1" << endl;
  }
  
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a < 10 && b < 10){
        cout << a * b;
    }else{
        cout << -1;
    }
    return 0;
}

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

int coutnt (int N ) {
  int ans = 0 ;
  while(1) {
    if(N%2==0){
      N /= 2 ;
      ans ++ ;
    } else {
      break ;
    }
  }
  return ans ;
}

int main () {
  int N ;
  cin >> N ;
  int ans1 =  -1 , ans = 0 ;
  for(int i = 1 ; i <= N ; i++ ){
    int pre = 0 ;
    pre = coutnt(i) ;
    ans1 = max(ans1,pre) ;
    if (ans1==pre) ans = i ;
  }
  cout << ans << endl ;
}

Measured memory_bytes: 636
import sys
input = sys.stdin.readline

def main():
    number_of_types,number_of_purchase = map(int,input().split())
    price_list = list(map(int,input().split()))
    price_list.sort()
    sum_price = sum([item for suffix,item in enumerate(price_list) if suffix < number_of_purchase])
    print(sum_price)
if __name__ == "__main__":
    main()

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

using ll = long long;
ll p10[19];

void precomp() {
	p10[0] = 1; for (int i = 1; i <= 18; i++) { p10[i] = p10[i-1]*10; }
}

// these may have leading digit 0
ll dfs(int l, ll d) {
	assert(l >= 0);
	d = abs(d);
	if (l == 1) {
		return d == 0 ? 10 : 0;
	}
	if (l == 0) {
		return d == 0 ? 1 : 0;
	}
	assert(l >= 2);

	ll ans = 0;
	for (int delta = -9; delta <= 9; delta++) {
		ll nd = d - delta + p10[l-1] * delta;
		if (nd % 10) continue;
		ans += dfs(l-2, nd / 10) * (10 - abs(delta));
	}
	return ans;
}

ll dfsNonZero(int l, ll d) {
	assert(l > 0);
	if (l == 1) {
		return d == 0 ? 9 : 0;
	}
	assert(l >= 2);
	ll ans = dfs(l, d);
	for (int dig = 0; dig <= 9; dig++) {
		ll nd = d + dig - p10[l-1] * dig;
		if (nd % 10) continue;
		ans -= dfs(l-2, nd / 10);
	}
	return ans;
}

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

	int D; cin >> D;
	ll ans = 0;
	for (int L = 1; L <= 19; L++) {
		ans += dfsNonZero(L, D);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

void main() {
    immutable ip = readln.split.to!(ulong[]);
    immutable n = ip[0], m = ip[1];

    auto ls = new ulong[m];
    auto rs = new ulong[m];

    for(ulong i = 0; i < m; i++) {
        immutable ip1 = readln.split.to!(ulong[]);
        immutable l = ip1[0], r = ip1[1];
        ls[i] = l;
        rs[i] = r;
    }

    ulong max_l = ls[0], min_r = rs[0];
    ulong invalid = false;
    for (ulong i = 1; i < m; i++) {
        if (ls[i] > max_l) max_l = ls[i];
        if (rs[i] < min_r) min_r = rs[i];
        if (max_l > min_r) {invalid = true; break;}
    }
    writeln(invalid ? 0 : min_r-max_l+1);
}


Measured memory_bytes: 4732
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

using namespace std;

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

long long GCD(int x,int y){
    if(x==0)return y;
    else{
        GCD(y%x,x);
    }
}

int main(){
    long long A,B,C,D;
    cin>>A>>B>>C>>D;
    long long change;
    if(C>D){
        change=C;
        C=D;
        D=change;
    }
    long long CD=(C*D/GCD(C,D));
    long long a=(B/C-(A-1)/C);
    long long b=(B/D-(A-1)/D);
    long long ab=(B/CD-(A-1)/CD);
    cout<<B-A+1-a-b+ab;
    return 0;
}

Measured memory_bytes: 256
s = input()

n = list(s)

check = False
isok = True

if n[0] == 'A':
    check = True

count = 0

for i in range(2, len(n) - 1):
    if n[i] == 'C':
        count += 1

for i in range(len(n)):
    p = int(ord(n[i]))
    if p == 65 or p == 67 or p > 96:
        continue
    else:
        isok = False

if check and count == 1 and isok:
    print('AC')
else:
    print('WA')




Measured memory_bytes: 9088
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
int main() {
    int N,M,X;
    vector<int> C;
    vector<vector<int>> A;
    cin >> N >> M >> X;
    C.resize(N);
    A.resize(N,vector<int>());
    REP(i,N) {
        A[i].resize(M);
        cin >>C[i];
        REP(j,M)
            cin>>A[i][j];
    }
    int ans=13* 100000;
    REP(i,1<<N) {
        int sa=0;
        vector<int> r;
        r.resize(M,0);
        REP(j,N) {
            if ((i>>j)&1) {
                sa+=C[j];
                REP(k, M) {
                    r[k]+=A[j][k];
                }
            }
        }
        bool no=false;
        REP(k, M)
            if (r[k]<X)no=true;
        if(!no)
            ans=min(ans,sa);
    }
    if (ans==13*100000) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long 
#define mod 1000000007
int main()
{
	ll n,k;
	cin>>n>>k;
	if(k>=(2*n))
	{
		cout<<n+((k-2*n)/4)<<endl;
		//cout<<(k-n)/4<<endl;
	}
	else //if(k>n && k<(2*n))
	{
		ll q=min(n,k/2);
		cout<<q<<endl;
	}
}

Measured memory_bytes: 256
import heapq

N,M=map(int,input().split())
A=[0 for _ in range(N)]
B=[0 for _ in range(N)]
for i in range(N):
  A[i],B[i]=map(int,input().split())
#print(A)
#print(B)

tasks=[[] for _ in range(10**5+1)]
for i in range(N):
  tasks[A[i]-1].append(B[i])
#print(tasks)

pq=[]
ans=0
for i in range(M):
  for b in tasks[i]:
    heapq.heappush(pq,-b)
  if len(pq)!=0:
    temp=heapq.heappop(pq)
    ans-=temp
print(ans)
    

Measured memory_bytes: 23136
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt,ans;ll ret;
int a[200010];
ll hz[200010],qz[200010],qzh[200010];
void calc(){
	for(rt i=n-1;i>=1;i--)hz[i]=hz[i+1]+2ll*(n-i)*a[i];
	qz[1]=qzh[1]=a[1];
	for(rt i=2;i<=n;i++)qz[i]=qz[i-1]+(2ll*i-1)*a[i],qzh[i]=qzh[i-1]+a[i];
	ll ans=0;
	for(rt i=1;i<=n;i++){
		ans+=a[i];int md=i+n>>1; 
		ret=max(ret,ans-hz[md+1]-(qz[md]-qz[i]-(qzh[md]-qzh[i])*2ll*i)+qzh[n]*(n-i-1));
	}
}
int main(){
	int L=r;n=r;a[++n]=L;
	for(rt i=1;i<n;i++){
		a[i]=r;
	}
	for(rt i=n;i>=2;i--)a[i]-=a[i-1];
	calc();reverse(a+1,a+n+1);calc();
	cout<<ret;
	return 0;
}


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

#define ll long long 
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

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

	int x, y;
	cin >> x >> y;

	ll ml = 2 * x, ma = 4 * x;
	if(y >= ml && y <= ma && y % 2 == 0) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;

    cout << n / 100 + n % 10 + n / 10 % 10 << endl;

    return 0;
}

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

int main(){

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    sort(A.rbegin(), A.rend());

    int width = 0, height = 0;
    for(int i = 0; i < A.size(); i++){
        if(A[i] == A[i + 1]){
            if(width == 0) width = A[i];
            else if(height == 0) height = A[i];
            i++;
        }
    }

    cout << (long long)width * height << endl;

    return 0;
}

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

int main() {
    int p, q, r;
    cin >> p >> q >> r;

    int ans = 300;
    ans = min(ans, p+q);
    ans = min(ans, p+r);
    ans = min(ans, q+p);
    ans = min(ans, q+r);
    ans = min(ans, r+q);
    ans = min(ans, r+p);

    cout << ans;
}

Measured memory_bytes: 256
n, w = map(int, input().split())

w_list = [0] * n
v_list = [0] * n
for i in range(n):
    w_list[i], v_list[i] = map(int, input().split())

dp = [0] * (w + 1)
for i in range(n):
    for j in range(w, -1, - 1):
        v = dp[j] + v_list[i]
        if j + w_list[i] <= w and dp[j + w_list[i]] < v:
            dp[j + w_list[i]] = v
print(dp[-1])


Measured memory_bytes: 70624
def check(state,switch, check)
  switch.map { |i| state[i - 1] }.count('1') % 2 == check
end

n,m = gets.split(' ').map(&:to_i)
switch_list = []
m.times do
  switch_list << gets.split(' ').map(&:to_i)[1..-1]
end
check_list = gets.split(' ').map(&:to_i)

count = 0
(0...2 ** n).each do |num|
  flag = true
  (0...m).each do |j|
    unless check("%#{n}b" % num, switch_list[j], check_list[j])
      flag = false
      break
    end
  end
  count += 1 if flag
end

puts count

Measured memory_bytes: 1788
import scala.io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  case class Id(i: Int, p: Int, x: Int)

  val city = Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" "))
    .zipWithIndex
    .map(a => new Id(a._2.toInt, a._1(0).toInt, a._1(1).toInt))
    .toArray

  val sortedCity = city
    .sorted {
      new Ordering[Id] {
        def compare(x: Id, y: Id): Int = (
          x.p.compareTo(y.p) match {
            case 0 => x.x.compareTo(y.x)
            case c => c
          })
      }
    }
    .scanLeft((0, 0, 0)) { (acc, city) =>
        if(acc._2 == city.p) (city.i, acc._2, acc._3 + 1)
        else (city.i, city.p, 1)
      }
    .tail
    .sortBy(_._1)

  sortedCity.foreach { id =>
        val p = Array.fill(6 - rec(0, id._2))('0').mkString
        val x = Array.fill(6 - rec(0, id._3))('0').mkString
        out.println(p + id._2 + x + id._3)
      }
  out.flush

  def rec(cnt:Int, v: Int):Int = {
    if(v == 0) cnt
    else rec(cnt+1, v / 10)
  }
}

Measured memory_bytes: 121620
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

class route {
public:
  i64 c, t;
  friend std::istream& operator>>(std::istream& is, route& self) {
    return is >> self.c >> self.t;
  }
};

int main() {
  i64 N, T;
  std::cin >> N >> T;
  std::vector<route> routes;
  tools::read(routes, N);

  std::vector<route> possible_routes;
  std::copy_if(routes.begin(), routes.end(), std::back_inserter(possible_routes), [&T](const route& route) { return route.t <= T; });
  auto it = std::min_element(possible_routes.begin(), possible_routes.end(), [](const route& x, const route& y) { return x.c < y.c; });
  if (it != possible_routes.end()) {
    std::cout << it->c << std::endl;
  } else {
    std::cout << "TLE" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
s = int(input())
dp = [0] * (2000+1)
dp[0] = 1
dp[3] = 1
m = 10**9+7
for i in range(4, s+1):
    ans = 0
    for j in range(3, i+1):
        ans = (ans + dp[i-j]) % m
    dp[i] = ans
print(dp[s])

Measured memory_bytes: 8876
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            long N = long.Parse(Console.ReadLine());
            long[] Arr = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long m = 1000;

            long day = 0;
            long k = 0;
            while (true)
            {
                if (k!=0)
                {
                    m += Arr[day] * k;
                    k = 0;
                }
                if (day == N - 1)
                {
                    m += Arr[day] * k;
                    k = 0;
                    break;
                }
                if (Arr[day] < Arr[day + 1]) 
                {
                    k = m / Arr[day];
                    m -= Arr[day] * k;
                }

                day++;
           }

            Console.WriteLine(m);


        }
    }
}


Measured memory_bytes: 28232
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String T = sc.nextLine();
    //SとTの長さsl tl
    int sl = S.length();
    int tl = T.length();
    //一致していない文字数を数えmに格納。missよりmが小さければmissを更新する
    int miss = 1000;
    int m = 0;
    
    if(S.contains(T)){
      miss = 0;
    }else{
        for(int i = 0; i <= sl - tl; i++){
            for(int j = 0; j < tl; j++){
                if((S.substring(i + j, i + j + 1)).equals(T.substring(j, j + 1)) == false){
                    m += 1;
                }
            }
            if(miss > m){
                miss = m;
            }
            m = 0;
        }
    }
    System.out.println(miss);
  }
}

Measured memory_bytes: 52360
package main

import (
	"fmt"
)

type ll int64


func main() {

	var A,B,C,D ll
	fmt.Scan(&A,&B,&C,&D)

	//A-1まで
	var ans_f ll = (A-1) - (A-1)/C - (A-1)/D + (A-1)/lcm(C,D)
	//Bまで
	var ans_b ll = B - B/C -B/D + B/lcm(C,D)

	fmt.Println(ans_b - ans_f)


}

//lcm,使用にはgcdが必要
func lcm(x,y ll) ll {
	gcd := gcd(x,y)
	return x*y/gcd
}

//int型のgcd
func gcd(x, y ll) ll {
	if x < y {
		x, y = y, x
	}
	for y > 0 {
		r := x % y
		x = y
		y = r
	}
	return x
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int a, b, c;

int solve() {
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    return (int)s.size();
}

void input() {
    cin >> a >> b >> c;
}

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

    input();
    cout << solve() << endl;
}

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

int main(){
  int N,K;
  cin >> N >> K;

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  /* まず各操作後に初期配置と同じになるかどうか調べる */
  vector<bool> is_SortedSeg(N-K+1);
  int cnt_pat= 0;
  int right= 1;
  for(int left=0; left<N;){
    while(right < N && data.at(right-1) < data.at(right)){
      right++;
    }

    for(int i=left; i+K <= right; i++){
      is_SortedSeg.at(i)= true;
      cnt_pat= 1;
    }

    left= right;
    right++;
  }

  /* 初期配置と異なる操作をカウント */
  set<int> seg;
  for(int k=0; k<K; k++){
    seg.insert(data.at(k));
  }

  int cnt_unpat= is_SortedSeg.at(0) ? 0
                                    : 1;
  for(int l=1; l+K <= N; l++){
    int r= l+ K; // [l,r)
    if(data.at(l-1)==*begin(seg) && data.at(r-1) > *rbegin(seg)){
      // do nothing
    }
    else if(!is_SortedSeg.at(l)){
      cnt_unpat++;
    }

    seg.erase(data.at(l-1));
    seg.insert(data.at(r-1));
  }

  /* 結果を出力 */
  int ans= cnt_pat+ cnt_unpat;

  cout << ans << endl;
}

Measured memory_bytes: 13556
// 2014/07/18 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int a1, b1;
	cin >> a1 >> b1;

	cout << a1-b1 << '\n';

	int a2, b2;
	cin >> a2 >> b2;

	cout << a2-b2 << '\n';

	int a3, b3;
	cin >> a3 >> b3;

	cout << a3-b3 << '\n';

	int a4, b4;
	cin >> a4 >> b4;

	cout << a4-b4 << '\n';

	int a5, b5;
	cin >> a5 >> b5;

	cout << a5-b5 << '\n';

	int a6, b6;
	cin >> a6 >> b6;

	cout << a6-b6 << '\n';

	int a7, b7;
	cin >> a7 >> b7;

	cout << a7-b7 << '\n';

	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++){
        double hoge = (double)i * 1.08;
        if((int)hoge == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}


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

int main() {
  
  long n;
  cin >> n;
  unordered_set<long> factors({n});
  for (long k = 2; k * k <= n; ++k) {
    if (n % k == 0) {
      long x(n);
      while (x % k == 0) x /= k;
      if (x % k == 1) factors.insert(k);
    }
  }
  for (long k = 1; k * k <= n - 1; ++k) {
    if ((n - 1) % k == 0) {
      factors.insert(k);
      factors.insert((n - 1) / k);
    }
  }
  cout << factors.size() - 1 << '\n';
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int n;
  string s;
  vector<int> ac(N + 1, 0);
  vector<pair<int, bool>> wa(N + 1, make_pair(0, false));
  for(int i = 0; i < M; ++i){
    cin >> n >> s;
    if(s == "AC"){
      if(ac[n] != 0) continue;
      ac[n] = 1;
      wa[n].second = true;
    }
    else {
      if(wa[n].second) continue;
      wa[n].first++;
    }
  }
  int aca = 0;
  int waa = 0;
  for(int i = 0; i < N + 1; ++i){
    if(ac[i] > 0) aca++;
    if(wa[i].second) waa += wa[i].first;
  }
  cout << aca << " " << waa << endl;

}

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

int main() {
	int amount = 10;
	vector<int> mountains(10);
	for(int i = 0; i < amount; ++i) {
		cin >> mountains[i];
	}
	
	sort( mountains.begin(), mountains.end() );
	
	for(int i = 9; i > 6; --i) {
		cout << mountains[i] << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	int[] sosuu = new int[1000000];
	public void run() {
		calcSosuu();
		while(sc.hasNext()){
			int a = sc.nextInt();
			int d = sc.nextInt();
			int n = sc.nextInt();
			if(a == 0 && d == 0 && n == 0) break;
			else calc(a,d,n);
		}
	}
	
	public void calc(int a, int d, int n){
		int s = a;
		while(n > 0){
			if(sosuu[s] == 1){
				n--;
				if(n == 0) break;
			}
			s = s + d;
		}
		System.out.println(s);
	}
	
	public void calcSosuu(){
		sosuu[0] = -1;
		sosuu[1] = -1;
		for(int i = 2; i < 1000000; i++){
			if(sosuu[i] == 0){
				sosuu[i] = 1;
				for(int j = i * 2; j < 1000000; j = j + i){
					sosuu[j] = -1;
				}
			}
		}
	}

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

Measured memory_bytes: 23524
n, m = STDIN.gets.split.map(&:to_i)
students = []
n.times do
  students << STDIN.gets.split.map(&:to_i)
end
points = []
m.times do
  points << STDIN.gets.split.map(&:to_i)
end

default_min = Float::INFINITY
min_points = []
students.each do |a, b|
  min = default_min
  num = -1
  points.each.with_index do |(c, d), i|
    d = (a - c).abs + (b - d).abs
    if min > d
      min = d
      num = i
    end
  end
  min_points << num
end

min_points.each do |num|
  puts num + 1
end


Measured memory_bytes: 1788
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    s = input()
    cnt = 0
    m = 0
    for i in range(n):
        if s[i] == '(':
            cnt += 1
        else:
            cnt -= 1
        m = min(m, cnt)
    ans = '('*(-m)+s+')'*(cnt-m)
    print(ans)


if __name__ == '__main__':
    main()

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

ll n,d; cin>>n>>d;
  ll di=d*d;
  ll x[n];
  ll y[n];
  rep(i,n){cin>>x[i]>>y[i];}
  
  int c=0;
  rep(i,n){if(x[i]*x[i]+y[i]*y[i]<=di){c++;}}
  cout<<c<<endl;

  
}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

ll divisor=1000000007;

int main(){
	ll n,m;
	cin>>n>>m;
	ll w[n],v[n];
	rep(i,n)cin>>w[i]>>v[i];
	ll dp[m+1][n+1]={};
	rep(i,m+1){
		if(i==0)continue;
		rep(j,n+1){
			if(j==0)continue;
			if(i<w[j-1]){
				dp[i][j]=dp[i][j-1];
				continue;
			}
			dp[i][j]=max(dp[i][j-1],dp[i-w[j-1]][j-1]+v[j-1]);
		}
	}
	puts(dp[m][n]);
}


Measured memory_bytes: 82368
n, k = map(int, input().split())

if n >= k:
    kati = (n -(k-1))/n
else:
    kati = 0

for i in range(1, min(n+1, k)):
    total = i
    kakuritsu = 1/n
    while total < k:
        kakuritsu *= 0.5
        total *= 2
    kati += kakuritsu

print(kati)

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

using namespace std;



/******************************************************************************
	Main
******************************************************************************/
int main()
{
    int a, b;
    cin >> a >> b;
    assert(a >= 1 && a <= 100);
    assert(b >= 1 && b <= 100);

	// (8 / 100) * x = a => x = 100 * a / 8, x \pm x * 100/8  くらい動かしたらええのでは 
	// (10 / 100) * x = b => 100 * b / 10, x \pm x * 100/10  くらい動かしたらええのでは 
	double x_coef = 100.0 / 8.0;
	double y_coef = 100.0 / 10.0;
	double x = a * x_coef;
	double y = b * y_coef;
	// cout << "x:" <<  x << " y: " << y << endl;
	int x_min = int(x - x_coef);
	int x_max = int(x + x_coef);
	int y_min = int(y - y_coef);
	int y_max = int(y + y_coef);

	// cout << x_min << "-" <<  x_max << endl;
	// cout << y_min << "-" <<  y_max << endl;
	for (int i = x_min; i < x_max; i++) {
		if (int(i / x_coef) != a) continue;
		if (i < y_min || i > y_max) continue;
		if (int(i / y_coef) != b) continue;

		cout << i << endl;
		return 0;
	}

	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256