akhauriyash/Code-Regression huggingface dataset:
from collections import deque


class Dinic:
    def __init__(self, N, inf):
        self.N = N
        self.inf = inf
        self.G = [[] for _ in range(N)]
        self.level = [0]*N

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s):
        self.level = [-1]*self.N
        deq = deque([s])
        self.level[s] = 0
        while deq:
            v = deq.pop()
            lv = self.level[v] + 1
            for w, cap, _ in self.G[v]:
                if cap > 0 and self.level[w] == -1:
                    self.level[w] = lv
                    deq.appendleft(w)

    def dfs(self, v, t, f):
        if v == t:
            return f
        for e in self.iter[v]:
            w, cap, rev = e
            if cap > 0 and self.level[v] < self.level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d > 0:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t] == -1:
                return flow
            *self.iter, = map(iter, self.G)
            f = self.inf
            while f > 0:
                f = self.dfs(s, t, self.inf)
                flow += f


import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


H,W = MI()
S = [LS2() for _ in range(H)]

Di = Dinic(2*H*W+2,10000)
s,t = 2*H*W,2*H*W+1

for i in range(H):
    for j in range(W):
        if S[i][j] == 'X':
            Di.add_edge(s,W*i+j,10000)

for j in range(W):
    Di.add_edge(H*W+j,t,10000)
    Di.add_edge(H*W+W*(H-1)+j,t,10000)
for i in range(1,H-1):
    Di.add_edge(H*W+W*i,t,10000)
    Di.add_edge(H*W+W*i+(W-1),t,10000)

for i in range(H):
    for j in range(W-1):
        Di.add_edge(H*W+W*i+j,W*i+(j+1),10000)
        Di.add_edge(H*W+W*i+(j+1),W*i+j,10000)
for i in range(H-1):
    for j in range(W):
        Di.add_edge(H*W+W*i+j,W*(i+1)+j,10000)
        Di.add_edge(H*W+W*(i+1)+j,W*i+j,10000)

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            Di.add_edge(W*i+j,H*W+W*i+j,1)
        else:
            Di.add_edge(W*i+j,H*W+W*i+j,10000)

flow = Di.flow(s,t)
print(flow if flow < 10000 else -1)


Measured memory_bytes: 133156
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int n;
	cin>>n;
	while(n--){
		int a,b;
		cin>>a>>b;
		int ans=a%b;
		if(ans==0)ans=b;
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main
{
    public static void main(String arg[])
    {
        Scanner sc = new Scanner(System.in);
        String aa = sc.next();
        String bb = sc.next();
        int a = Integer.parseInt(aa);
        int b = Integer.parseInt(bb);

        if (a > b)
        {
            System.out.println("a > b");
        }
        else if (a < b)
        {
            System.out.println("a < b");
        }
        else
        {
            System.out.println("a == b");
        }
    }

}



Measured memory_bytes: 26216
#include <stdio.h>

int main() {
        long a, b, d, r;
        double f;

        scanf("%ld %ld", &a, &b);

        d = a / b;
        r = a % b;
        f = (double)a / b;

        printf("%ld %ld %.5lf\n", d, r, f);

}


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

int main(){
    string s,t;

    cin >> s >> t;
    int count=0;

    for(int i=0;i<s.size();i++){
        if(s.at(i)!=t.at(i)){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3812
#include<stdio.h>
int main(void) {
	int M, N, L, s=0,i,num[12];
	while (1) {
		scanf("%d",&L);
		s = 0;
		if (L == 0)break;
		for (i = 0; i < 12; i++) {
			scanf("%d %d", &M, &N);
			s += M - N;
			num[i] = s;
		}
		for (i = 0; i < 12; i++) {
			if (num[i] >= L) {
				printf("%d\n", i + 1);
				break;
			}
		}
		if (s < L)printf("NA\n");
	}
	return 0;
}

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

int main()
{
   // cout << "Hello World!" << endl;
    
    int x,y;
    cin>>x>>y;
    
    int s=0;
    
    int arr[3]={300000,200000,100000};
    
    if(x<=3)
    s+=arr[x-1];
    
    if(y<=3)
    s+=arr[y-1];
    
    if(x==1 && y==1)
    s+=400000;
    
    cout<<s;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

char s[5];

int main(){
  
  scanf("%s", s);
  
  int ans = 0;
  
  for(int i = 0; i <4; i++){
    if(s[i]=='+') ans++;
    else ans--;
  }
  
   printf("%d", ans);
    
   return 0;
    
  }

Measured memory_bytes: 128
// ConsoleApplication.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdio.h"
#include <cstdlib>
#include <iostream>


using namespace std;

struct Point {
	int x, y;
	Point& operator+(const Point& rhs) {
		x += rhs.x;
		y += rhs.y;
		return *this;
	}
	Point& operator-(const Point& rhs) {
		x -= rhs.x;
		y -= rhs.y;
		return *this;
	}
	Point& operator*(const int& rhs) {
		x *= rhs;
		y *= rhs;
		return *this;
	}
};

bool isZero(const int val)
{
	return abs(val) < 1e-10;
}

int innerProduct(const Point& p0, const Point& p1)
{
	return p0.x * p1.x + p0.y * p1.y;
}

int outerProduct(const Point& p0, const Point& p1)
{
	return p0.x * p1.y - p0.y * p1.x;
}

void readPointsFromLine(Point& p0, Point& p1)
{
	cin >> p0.x;
	cin >> p0.y;
	cin >> p1.x;
	cin >> p1.y;
}

int main()
{
	int N; cin >> N;
	for (int i = 0; i != N; ++i) {
		int flag = 0;
		while (true) {
			Point p0, p1, p2, p3;
			readPointsFromLine(p0, p1);
			readPointsFromLine(p2, p3);
			const Point v0 = p1 - p0;
			const Point v1 = p3 - p2;
			const bool isParallel = isZero(outerProduct(v0, v1));
			if (isParallel) {
				flag = 2;
				break;
			}
			const bool isOrthogonal = isZero(innerProduct(v0, v1));
			if (isOrthogonal) {
				flag = 1;
				break;
			}
			break;
		}
		cout << flag << endl;
	}


	return 0;
}


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

int main(void) {
  ll L, R; cin >> L >> R;
  if (R-L < 2019) {
    int l = L%MOD, r = R%MOD;
    int min = 2019;
    for (int i = l; i <= r-1; i++) {
      for (int j = i+1; j <= r; j++) {
        if ((i*j)%MOD < min) min = (i*j)%MOD;
      }
    }
    cout << min << endl;
  } else cout << 0 << endl;

  return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int N,M,ans;
deque<int> v[300];
map<int,int> m,b;

signed main() {
    cin >> N >> M;
    rep(i,N) rep(j,M) {
        int a;
        cin >> a;
        v[i].pb(a);
    }
    rep(i,N) m[v[i][0]]++;
    for(auto i : m) ans = max(ans, i.se);
    rep(k,M-1) {
        int MAX=0,num;
        for(auto i : m) if (i.se > MAX) {
            MAX = i.se;
            num = i.fi;
        }
        b[num] = 1;
        m.clear();
        rep(i,N) {
            while (b[v[i][0]]) v[i].pop_front();
            m[v[i][0]]++;
        }
        int tmp=0;
        for(auto i : m) tmp = max(tmp, i.se);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int p;
	cin>>p;
	int sum = 0, a = p;
	p %= 10000;
	sum += a-p;
	a = p;
	p %= 5000;
	sum += a-p;
	a = p;
	p %= 1000;
	sum += a-p;
	a = p;
	p %= 500;
	sum += a-p;
	cout << sum << endl;
}



Measured memory_bytes: 3120
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int total=0;
  int arr[n];
  for (int i=0; i<n; i++){
    cin >> arr[i];
    total+=arr[i];
  }
  sort(arr, arr+n);
  if (total%10!=0){
    cout << total << endl;
    return 0;
  }
  else{
    int max = total;
    for (int i=0; i<n; i++){
        max -= arr[i];
    	if (max%10!=0){
        	cout << max << endl;
            return 0;
        }
        max = total;
    }
    cout << 0 << endl;
  }
}
    

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int a, b; cin >> a >> b;

	set <int> s1, s2;

	for(int i = 1; i < 1e5; i++){
		if((i * 8) / 100 == a){
			s1.insert(i);
		}
		if(i / 10 == b){
			s2.insert(i);
		}
	}

	for(int it : s1){
		if(s2.find(it) != s2.end()){
			cout << it << endl; return 0;
		}
	}

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

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

int main() {
  string s, t;
  cin >> s >> t;

  int k = -1;
  int S = s.length();
  int T = t.length();
  rep(i, S - T + 1) {
    bool ok = true;
    rep(j, T) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        ok = false;
      }
    }
    if (ok) k = i;
  }
  if (k == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    rep(i, T) s[i + k] = t[i];
    rep(i, S) s[i] = (s[i] == '?') ? 'a' : s[i];
    cout << s << endl;
  }
}


Measured memory_bytes: 3628
#include <stdio.h>

int MAX_INPUT = 10;

int main ( int argc, char **argv )
{
    char buffer[100];
    while ( fgets(buffer, 100, stdin) != NULL )
    {
        int total = 0;
        int x,y = 0;
        sscanf(buffer, "%d %d", &x, &y);
        total = x + y;
        int places = 0;
        while ( total > 0 ) 
        {
            total = total / 10;
            places++;
        }

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

    return 0;
}

Measured memory_bytes: 608
nums = list(map(int, input().split())) # "1 2 3"と入力
n = nums[0]
t = nums[1]
minC = 1001
for i in range(n):
    numss = list(map(int, input().split()))
    c = numss[0]
    ti = numss[1]
    if ti <= t and minC > c:
        minC = c
if minC == 1001:
    print('TLE')
else:
    print(minC)
 


Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

typedef struct range {
  i32 l, r;
} range;

typedef range radix_type;
typedef uint32_t u32;

#define RADIX_WIDTH 9
const u32 radix_type_max = 17;
const u32 radix_type_begin = 0;
const u32 radix_width = RADIX_WIDTH;
const u32 radix_mask = (1 << RADIX_WIDTH) - 1;
#undef RADIX_WIDTH

static inline u32 radix_get_bit (radix_type v, u32 shift) {
  return (u32)(v.r - v.l) >> shift & radix_mask;
}

void radix_sort (radix_type *a, u32 n) {
  radix_type * const array = (radix_type *) calloc (4 * n, sizeof (radix_type));
  radix_type **bucket = (radix_type **) calloc (1 << radix_width, sizeof (radix_type *));
  u32 *len = (u32 *) calloc (2 << radix_width, sizeof (u32));
  u32 *max_len = len + (1 << radix_width);
  for (u32 shift = radix_type_begin; shift < radix_type_max; shift += radix_width) {
    radix_type *p = array;
    memset (len, 0, sizeof (u32) << (radix_width + 1));
    for (u32 i = 0; i < n; ++i) {
      u32 bit = radix_get_bit (a[i], shift);
      if (len[bit] == max_len[bit]) {
	for (u32 j = 0; j < len[bit]; ++j) {
	  p[j] = bucket[bit][j];
	}
	max_len[bit] = 2 * max_len[bit] + 1;
	bucket[bit] = p;
	p += max_len[bit];
      }
      bucket[bit][len[bit]++] = a[i];
    }
    for (u32 bit = 0, i = 0; bit < (1 << radix_width); ++bit) {
      for (u32 j = 0; j < len[bit]; ++j, ++i) {
	a[i] = bucket[bit][j];
      }
    }
  }
  free (array);
  free (bucket);
  free (len);
}

void add (i32 *bit, i32 x, i32 v) {
  i32 n = bit[0];
  for (i32 i = x; i <= n; i += i & -i) {
    bit[i] += v;
  }
}

i32 find (i32 *bit, i32 x) {
  i32 sum = 0;
  for (i32 i = x; i > 0; i -= i & -i) {
    sum += bit[i];
  }
  return sum;
}

void run (void) {
  i32 n = read_int();
  i32 m = read_int();
  range *p = (range *) calloc (n, sizeof (range));
  for (i32 i = 0; i < n; ++i) {
    p[i].l = read_int();
    p[i].r = read_int() + 1;
  }
  radix_sort (p, n);
  i32 *bit = (i32 *) calloc (m + 2, sizeof (i32));
  bit[0] = m + 1;
  for (i32 d = 1, i = 0; d <= m; ++d) {
    for (; i < n && p[i].r - p[i].l < d; ++i) {
      add (bit, p[i].l, 1);
      add (bit, p[i].r, -1);
    }
    i32 ans = n - i;
    for (i32 j = d; j <= m; j += d) {
      ans += find (bit, j);
    }
    print_int (ans);
    putchar ('\n');
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 11776
a, b, c, d = map(int, input().split(" "))

if a <= c:
  if b <= c:
    ans = 0
  elif d <= b:
    ans = d - c
  else:
    ans = b - c
else:
  if d <= a:
    ans = 0
  elif b <= d:
    ans = b - a
  else:
    ans = d - a
print(ans)

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

void chmax (int64_t &x, int64_t a) {
    x = max(x, a);
}

signed main () {
    int64_t n, m, ans = 0;
    cin >> n >> m;
    for (int64_t i = 1; i * i <= m; ++i) {
        if (m % i == 0) {
            if (i >= n) 
                chmax(ans, m / i);
            else if (m / i >= n)
                chmax(ans, i);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

    lint res = 0;

    vec r(n), g(n), b(n);
    for (int i = n-2; i >= 0; i--) {
        r[i] = r[i+1];
        g[i] = g[i+1];
        b[i] = b[i+1];

        if (s[i+1] == 'R') r[i]++;
        if (s[i+1] == 'G') g[i]++;
        if (s[i+1] == 'B') b[i]++;
        
    }

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (s[i] == s[j]) continue;

            // i == R
            if (s[i] == 'R') {
                if (s[j] == 'G') {
                    res += b[j];
                    if (j*2-i < n && s[j*2-i] == 'B') res--;
                }
                else if (s[j] == 'B') {
                    res += g[j];
                    if (j*2-i < n && s[j*2-i] == 'G') res--;
                }
            }
            else if (s[i] == 'G') {
                if (s[j] == 'R') {
                    res += b[j];
                    if (j*2-i < n && s[j*2-i] == 'B') res--;
                }
                else if (s[j] == 'B') {
                    res += r[j];
                    if (j*2-i < n && s[j*2-i] == 'R') res--;
                }
            }
            else {
                if (s[j] == 'R') {
                    res += g[j];
                    if (j*2-i < n && s[j*2-i] == 'G') res--;
                }
                else if (s[j] == 'G') {
                    res += r[j];
                    if (j*2-i < n && s[j*2-i] == 'R') res--;
                }
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3716
import java.util.Scanner;

class Main {

  private static long INF = Long.MAX_VALUE / 4;

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    int X = scanner.nextInt();
    int Y = scanner.nextInt();
    long[] res = new long[3];
    res[0] = Math.min(X, Y) * 2 * C;
    if (X < Y) {
      res[0] += B * (Y - X);
    } else {
      res[0] += A * (X - Y);
    }
    res[1] = A * X + B * Y;
    res[2] = Math.max(X, Y) * 2 * C;
    long ans = INF;
    for (int i = 0; i < res.length; i++) {
      ans = Math.min(res[i], ans);
    }

    System.out.println(ans);
  }

}


Measured memory_bytes: 23252
#include<stdio.h>
int main(void){
	char a[100];
	char b[100];
	scanf("%s %s",a,b);
	int i=0;
	while(1){
		if(a[i]=='\0'){
			puts("Yes");
			return 0;
		}
		if((int)a[i]!=(int)b[i]){
			puts("No");
			return 0;
		}
		i++;
	}
	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll x, y;
    cin >> x >> y;

    int flip = 0;
    bool samesign = (x>=0 && y>0) || (x<0 && y<=0);
    if     (samesign && x <= y) flip = 0;
    else if(samesign && x >  y) flip = 2;
    else flip = 1;
    cout<<(abs(abs(x)-abs(y)) + flip)<<endl;

    return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var a = new int[n]; var b = new int[m];
            var da = new Dictionary<int, int>();
            var db = new Dictionary<int, int>();
            for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < m; i++) b[i] = int.Parse(Console.ReadLine().Trim());
            setDic(da, a); setDic(db, b);
            var count = 0;
            foreach (var x in da)
                if (db.ContainsKey(x.Key)) count += x.Value * db[x.Key];
            Console.WriteLine(count);
        }
    }
    public static void setDic(Dictionary<int, int> d, int[] a)
    {
        var aL = a.Length + 1;
        var a2 = new int[aL];
        for (int i = 1; i < aL; i++)
            a2[i] = a2[i - 1] + a[i - 1];
        for (int i = 1; i < aL; i++)
            if (d.ContainsKey(a2[i])) d[a2[i]]++;
            else d[a2[i]] = 1;
        for (int i = 1; i <= aL - 2; i++)
            for (int j = i + 1; j <= aL - 1; j++)
            {
                var w = a2[j] - a2[j - i];
                if (d.ContainsKey(w)) d[w]++;
                else d[w] = 1;
            }
    }
}

Measured memory_bytes: 36328
s=input()
if s[0]==s[1] and s[2]==s[3] and s[1]==s[2]:
 print("No")
elif s[0]==s[1] and s[2]==s[3]:
 print("Yes")
elif s[0]==s[2] and s[1]==s[3]:
 print("Yes")
elif s[0]==s[3] and s[1]==s[2]:
 print("Yes")
else:
 print("No")

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{

    int a,b,x,c,d,e;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&x);
    c=a-b;
    d=c%x;
    e=c-d;
    printf("%d",d);
    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(NULL);


int main()
{
	FASTIO;
	int n,k;
  cin>>n>>k;
  int ans=0;
  while(n)
  {
    ++ans;
    n/=k;
  }
  cout<<ans<<"\n";	
	
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    int w;
    getline(cin,s);
    cin>>w;
    for(int i=0;i<(int)s.length();i+=w)cout<<s[i];
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, a, b;
int board[500][500];
int h, w;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h>>w;
    int count=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>board[i][j];
        }
    }
    int ans=0;
    vector<p> z;
    int xs=0, ys=0, xe=h-1, ye=w-1;
    for(int i=0;i<w-1;i++){
        for(int j=0;j<h;j++){
            if(board[j][i]%2==1){
                ans++;
                board[j][i+1]++;
                z.push_back(make_pair(j,i));
                z.push_back(make_pair(j,i+1));
            }
        }
    }
    for(int i=0;i<h-1;i++){
        if(board[i][w-1]%2==1){
                ans++;
                board[i+1][w-1]++;
                z.push_back(make_pair(i,w-1));
                z.push_back(make_pair(i+1,w-1));
            }
    }
        cout << ans << "\n";
        for(int i=0;i<z.size();i+=2){
            cout<<z[i].first+1<<" "<<z[i].second+1<<" "<<z[i+1].first+1<<" "<<z[i+1].second+1<<"\n";
        }
    
    /*else{
        cout << ans << "\n";
        for(int i=0;i<z.size();i+=2){
            cout<<z[i].first+1<<" "<<z[i].second+1<<" "<<z[i+1].first+1<<" "<<z[i+1].second+1<<"\n";
        }
    }*/
}

Measured memory_bytes: 5232
def solve():
  l = input()
  mod = 10**9+7
  n = len(l)
  dp = [[0]*2 for _ in range(n+1)]
  dp[0][0] = 0
  dp[0][1] = 1
  for i in range(n):
    dp[i+1][0] += dp[i][0]*3
    if l[i] == "0":
      dp[i+1][1]  += dp[i][1]
    else:
      dp[i+1][0] += dp[i][1]
      dp[i+1][1] += dp[i][1]*2
    dp[i+1][0] %= mod
    dp[i+1][1] %= mod
  print((dp[n][0]+dp[n][1])%mod)
solve()

Measured memory_bytes: 19700
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define PB push_back
#define PF push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define vec vector
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void solve(){
	int n, hp, ipt;
	ll atk = 0;
	
	cin >> hp >> n;
	rep(i, n){
		cin >> ipt;
		atk += ipt;
	}
	
	if(atk < hp) cout << "No" << '\n';
	else		 cout << "Yes" << '\n';
}

int main(){
	int t = 1;
	
	while(t--){
		solve();
	}
}




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

int main(){
  int i, x, y;
  for (i = 1;i > 0 ; ++i) {
 cin >> x >> y;
 if(x == y){
   if(x == 0)break;
 }
 if(x >= y){
   cout << y << " " << x << endl;
 } else {
   cout << x << " " << y << endl;
 }
  }
return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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 = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    string s;
    cin >> s;
    rep(i, 3) {
        if (s[i] == '7') {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

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


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005,mod=1e9+7,inv2=(mod+1)/2;
int a[Maxn],s[Maxn],pre[Maxn],f[Maxn],invf[Maxn];
struct node{
	int l,r,v,cnt;
}Tree[4*Maxn];
int ksm(int x,int k){
	int ret=1,tmp=x;
	while(k){
		if(k&1)ret=1ll*ret*tmp%mod;
		tmp=1ll*tmp*tmp%mod;k>>=1;
	}
	return ret;
}
int inv(int x){return ksm(x,mod-2);}
void PushUp(int v){
	Tree[v].v=(Tree[2*v].v+Tree[2*v+1].v)%mod;
	Tree[v].cnt=Tree[2*v].cnt+Tree[2*v+1].cnt;
}
void Build(int v,int l,int r){
	Tree[v]=(node){l,r,0,0};
	if(l==r)return;
	Build(2*v,l,(l+r)/2);
	Build(2*v+1,(l+r)/2+1,r);
}
void Modify(int v,int pos,int val){
	if(Tree[v].l==Tree[v].r){
		Tree[v].v=(Tree[v].v+val)%mod;
		Tree[v].cnt++;
		return;
	}
	if(pos<=Tree[2*v].r)Modify(2*v,pos,val);
	else Modify(2*v+1,pos,val);
	PushUp(v);
}
int Askv(int v,int l,int r){
	if(r<Tree[v].l||Tree[v].r<l)return 0;
	if(l<=Tree[v].l&&Tree[v].r<=r)return Tree[v].v;
	return (Askv(2*v,l,r)+Askv(2*v+1,l,r))%mod;
}
int Askc(int v,int l,int r){
	if(r<Tree[v].l||Tree[v].r<l)return 0;
	if(l<=Tree[v].l&&Tree[v].r<=r)return Tree[v].cnt;
	return Askc(2*v,l,r)+Askc(2*v+1,l,r);
}
int main(){
	int n,g=1,ans=0;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)s[a[i]]++;
	for(int i=n;i>=1;i--)s[i]+=s[i+1];
	for(int i=1;i<=n;i++)s[i]-=n-i;
	for(int i=1;i<=n;i++){
		int cur=1ll*(s[i]-1)*inv(s[i])%mod;
		if(!cur)pre[i]=i;
		else pre[i]=pre[i-1];
		f[i]=1ll*(i==1?1:f[i-1])*max(cur,1)%mod;
		invf[i]=inv(f[i]);
	}
	for(int i=n;i>=1;i--)g=1ll*g*s[i]%mod;
	Build(1,1,n);
	for(int i=1;i<=n;i++){
		ans=(ans+1ll*g*inv2%mod*Askv(1,pre[a[i]]+1,a[i])%mod*f[a[i]])%mod;
		Modify(1,a[i],invf[a[i]]);
	}
	Build(1,1,n);
	for(int i=n;i>=1;i--){
		ans=(ans+1ll*g*Askc(1,1,a[i]-1)-1ll*g*inv2%mod*Askv(1,pre[a[i]]+1,a[i]-1)%mod*f[a[i]])%mod;
		Modify(1,a[i],invf[a[i]]);
	}
	cout<<(ans+mod)%mod<<"\n";
	return 0;
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
int N;
string S;
int get(int f, int s) {
    int ret = 0;
    int d[10] = {0};
    if(!s) {
        for(int i = f; i < N-s; i++) {
            int c = S[i] - '0';
            if(!d[c]) ret++;
            d[c]++;
        }
        return ret;
    }
    for(int i =  f; i < N-s; i++) {
        int c = S[i] - '0';
        if(d[c]) continue;
        d[c]++;
        ret += get(i+1, s-1);
    }
    return ret;
}
int main() {
    cin >> N >> S;
    cout << get(0, 2);
}

Measured memory_bytes: 256
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

class Solution {
public:

private:

};

int solve() {
    Solution solution;
    // handle IO here
    int A, B;
    cin >> A >> B;
    int64_t sum = int64_t(A) + B;
    if (sum % 2 == 0) {
        cout << sum / 2 << '\n';
    } else {
        cout << "IMPOSSIBLE\n";
    }

    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for (int i = s; i < (e); ++i)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define FILEIO                          \
    freopen("./input.txt", "r", stdin); \
    freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                               \
    for (                                                                       \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second;                                                       \
        debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T &x) { return x > 0 ? x : -x; }
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }

int main()
{
    FASTIO
#ifdef LOCAL
    FILEIO
#endif
    int i, j;
    cin >> i >> j;
    cout << i * j << endl;
    return 0;
}

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


int main()
{
	string n; cin >> n;
	int ans = 0;
	for (int i = 0; i < n.size(); ++i)
		ans += n[i] - 48;
	if (ans == 1) ans = 10;
	cout << ans << endl;
}



Measured memory_bytes: 3620
#include<stdio.h>
 #define MAX 2000000
 #define K 10010
 int A[MAX], B[MAX];
 void CountingSort(int A[], int N, int B[])
 {
 int C[K] ={0};
 for (int i = 0;
 i < N;
 i++)
 {
 C[A[i]]++;
 }
 for (int i = 1;
 i < K;
 i++)
 {
 C[i] += C[i - 1];
 }
 for (int i = N - 1;
 i >= 0;
 i--) { C[A[i]]--;
 B[C[A[i]]] = A[i];
 }
 }
 int main()
 {
 int N;
 scanf("%d", &N);
 for (int i = 0; i < N; i++)
 {
 scanf("%d", &A[i]);
 }
 CountingSort(A, N, B);
 for (int i = 0; i < N;
 i++)
 {
 if (i)printf(" ");
 printf("%d",B[i]);
 }
 printf("\n");
 return 0;
 }


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

int main(){
	int W;
	cin >> W;
	vector<int> a(W+2),dp1(W+2,-1e9),dp2(W+2,-1e9);
	for(int i = 1 ; i <= W ; i++) cin >> a[i];
	
	for(int i = 1 ; i <= W ; i++){
		if( a[i] == 0 ) dp1[i] = 1e9;
		else if( a[i] < 0 ) dp1[i] = min(dp1[i-1]-1,-a[i]);
		else dp1[i] = dp1[i-1]-1;
	}
	for(int i = W ; i >= 1 ; i--){
		if( a[i] == 0 ) dp2[i] = 1e9;
		else if( a[i] < 0 ) dp2[i] = min(dp2[i+1]-1,-a[i]);
		else dp2[i] = dp2[i+1]-1;
	}

	int ans = 0;
	for(int i = 1 ; i <= W ; i++)
		ans += max(0,min(max(dp1[i],dp2[i]),a[i]));
	cout << ans << endl;

	
	
	
}

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

int main(){
	ios::sync_with_stdio(false);

	int N; cin>>N;
	vector<int> L(N);
	// 棒が２本以下の時は三角形が作れない。
	// if(N<3){
	// 	cout << 0 << endl;
	// 	return 0;
	// }
	
	//入力を受け取ってソート
	rep(i,N) cin>>L[i];
	sort(L.begin(),L.end());

	int ans=0;
	for(int i=0; i<int(L.size())-2; i++){
		for(int j=i+1; j<int(L.size())-1; j++){
			// 同じ数の時は飛ばす
			if(L[i]==L[j]) continue;
			for(int k=j+1; k<int(L.size()); k++){
				// 同じ数の時は飛ばす
				if(L[j]==L[k]) continue;
				if(L[k] < L[i]+L[j]) ans++;	
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3656
function Main(input) {
	input = input.replace(' ', '');
	var a = parseInt(input, 10);
	var anser = '';
	if(Math.sqrt(a)-Math.floor(Math.sqrt(a)) == 0){
		anser = 'Yes'
    }else{
       	anser = 'No';
    }
	console.log(anser);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
def main():
    S=input()
    if S=="RRS":
        print(2)
    elif S=="SRR":
        print(2)
    elif S=="SSS":
        print(0)
    elif S=="RRR":
        print(3)
    else:
        print(1)

if __name__=="__main__":
    main()


Measured memory_bytes: 61748
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<set>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,K,D[10],d,f=0;
  set<int> sets;
  
  cin >> N >> K;
  REP(i,K){
    cin >> d;
    sets.insert(d);
  }
  for(int i=N;i<=100000;i++){
    d = i;
    f = 1;
    while(d > 0){
      if(sets.count(d%10)){
        f = 0;
        break;
      }
      d /= 10;
    }
    if(f){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[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(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    ll sum=0;
    rep(i,n){
        cin >> a[i];
        sum = sum ^ a[i];
    }
    rep(i,n){
        int ans=0;
        ans = sum ^ a[i];
        cout << ans << endl;
    }
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long S, long long W){
    if(W >= S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long S;
    scanf("%lld",&S);
    long long W;
    scanf("%lld",&W);
    solve(S, W);
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

int print1(string &s, long long a, long long b)
{
    cout << s.substr(a, b - a + 1) << endl;
}
int reverse1(string &s, long long a, long long b)
{
    string h;
    h = s.substr(a, b - a + 1);
    reverse(h.begin(), h.end());
    s.replace(a, b - a + 1, h);
}
int replace1(string &s, long long a, long long b, string p)
{
    s.replace(a, b - a + 1, p);
}

int main()
{
    string s;
    cin >> s;
    long long q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        string o;
        cin >> o;
        if (o == "print")
        {
            long long a, b;
            cin >> a >> b;
            print1(s, a, b);
        }
        else if (o == "reverse")
        {
            long long a, b;
            cin >> a >> b;
            reverse1(s, a, b);
        }
        else if (o == "replace")
        {
            long long a, b;
            cin >> a >> b;
            string p;
            cin >> p;
            replace1(s, a, b, p);
        }
    }
    return 0;
}


Measured memory_bytes: 3204
N = int(input())

H = list(map(int, input().split()))

counts = []
count = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        count += 1
    else:
        counts.append(count)
        count = 0
else:
    counts.append(count)

print(max(counts))

Measured memory_bytes: 20620
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

V<ll> ans;

bool solve() {
    ll N;
    cin >> N;
    V<ll> A(N + 1);
    for(ll i = 1; i <= N; i++) cin >> A[i];
    V<bool> ball(N + 1, false);
    for(ll i = N; 0 < i; i--) {
        ll sum = 0;
        for(ll j = 1; i * j <= N; j++) sum += ball[i * j];
        if(sum % 2 != A[i]) {
            ball[i] = true;
            ans.push_back(i);
        }
    }
    sort(ALL(ans));
    return true;
}

int main() {
    solve();
    cout << ans.size() << endl;
    for(ll i = 0; i < ans.size(); i++) cout << ans[i] << " \n"[i + 1 == ans.size()];
    return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
const ll MOD = 1000000007;

int main() {
    int x,ans = 0;
    cin >> x;
    ans += (x / 500)*1000;
    x = x % 500;
    ans += (x / 5)*5;
    cout << ans;
}

Measured memory_bytes: 768
#pragma region template 1.2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a) \
    REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;

    map<char, ll> c;
    REP(i, N)
    {
        ++c[S[i]];
    }
    ll ans = c['R'] * c['G'] * c['B'];
    REP(i, N)
    {
        for (ll j = i + 1; j < N; ++j)
        {
            ll k = 2 * j - i;
            if (k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k])
            {
                --ans;
            }
        }
    }
    OUT(ans);
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<string> s(N); REP(i, N) cin >> s[i];
  REP(i, N) sort(all(s[i]));
  map<string, ll> m;
  REP(i, N) m[s[i]]++;
  ll ans = 0;
  for(auto x : m) {
    ll tmp = x.second * (x.second - 1) / 2;
    ans += tmp;
  }
  cout << ans << endl;
}

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

int main() {
	long n,m,i,j,k,ans,cur,res,a,b,c;
	cin >> a >> b >> c >> k;
	ans=min(a,k); k-=min(a,k);
	k-=min(b,k);
	ans-=min(c,k);
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	ll n,m,i,sum=0;
	cin >> n >> m;
	for(i=0;i<m;i++){
		ll x;
		cin >> x;
		sum+=x;
	}
	if(sum>n)
		cout << "-1\n";
	else
		cout << n-sum << "\n";
	return 0;
}

Measured memory_bytes: 3624
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};



int main(){
    IOS;
    make(string,s);
    ll n=s.length();
    string t="keyence";
    if(t==s) {cout<<"YES \n"; return 0;}
    fr(i,n){
        for(ll j=i;j<n;j++){
            string st="";
            fr(k,n){
                if(k>=i&&k<=j) continue;
                else st.push_back(s[k]);
            }
            if(st==t){
                cout<<"YES \n"; return 0;
            }
        }
    }
    cout<<"NO \n";


    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
typedef long long int ll;
ll wgt[101],val[101];
ll cnt;
ll dp[100009][101];
ll solve(ll w,ll i,ll n)
{
	if(dp[w][i]!=-1)
	return dp[w][i];
	else
	{
	ll ans;
	if(w==0||i==n)
	return 0;
	if(w<wgt[i])
	ans= solve(w,i+1,n);
	else
	ans= max(val[i]+solve(w-wgt[i],i+1,n),solve(w,i+1,n));
	dp[w][i]=ans;
	return ans;
    }
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	FOR(i,0,100009)
	{
		for(int j=0;j<101;j++)	
	dp[i][j]=-1;
   }
	ll n,w;
	cin>>n>>w;
	for(int i=0;i<n;i++)
	{
		cin>>wgt[i]>>val[i];
	}
	ll ans;
	ans=solve(w,0,n);
	cout<<ans<<endl;
}

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

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

typedef long long ll;
int main(){
    int N; cin >> N;
    double T,A; cin >> T >> A;
    vector<pair<double,int>> P(N);
    for(int i = 0;i < N;i++){
        double h; cin >> h;
        P[i] = make_pair(abs(A-(T - h*0.006)),i);
    }
    sort(P.begin(),P.end());
    cout << P[0].second + 1 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
    int n,k; cin>>n>>k;
    int ht[n], dp[n];
    memset(dp, 0, sizeof dp);
    for(int i=0; i<n; i++) cin>>ht[i];
    dp[1] = abs(ht[1] - ht[0]);

    for(int i=2; i<n; i++) {
        int tmp = INT_MAX;
        for(int j=i-1; j>=max(0ll, i-k); j--) {
            tmp = min(tmp, dp[j] + abs(ht[i] - ht[j]));
        }
        dp[i] = tmp;
    }

    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 5188
#include <stdio.h>
#define N 100

void sort(int *,int);
int main() {
  int i,n;
  int array[N];

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

  sort(array,n);

  return 0;
}

void sort(int *A,int n){
  int i,j,k,cnt=0,temp,flag=1;
  i = 0;
  while (flag) {
    flag = 0;
    for (j = n-1; j >= i+1; j--) {
      if (A[j] < A[j-1]) {
        temp = A[j];
        A[j] = A[j-1];
        A[j-1] = temp;
        cnt++;
        flag = 1;
      }
    }
    i++;
  }
  for (i = 0; i < n; i++) {
      if (i > 0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
}



Measured memory_bytes: 2108