akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

    int xn = sc.nextInt();
    int yn = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int x[] = new int [xn];
    int y[] = new int [yn];
    for (int i = 0; i < xn; i++) {
      x[i] = sc.nextInt();
    }
    for (int i = 0; i < yn; i++) {
      y[i] = sc.nextInt();
    }
    Arrays.sort(x);
    Arrays.sort(y);
    if (x[xn-1] < y[0] && X < y[0] && x[xn-1] < Y) {
      System.out.println("No War");
    }
    else
      System.out.println("War");
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    Rep(i,n) cin >> a[i];
    vector<ll> c(3,0);
    Rep(i,n){
        ll flag = 0;
        while(a[i]%2==0){
            a[i] /=2ll;
            flag++;
            if(flag==2) break;
        }
        c[flag]++;
    }
    if(c[1]==0){
        if(c[0]-1<=c[2]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        if(c[0]<=c[2]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}

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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputstream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputstream);
        AtcoderA solution = new AtcoderA();
        solution.solve(1, in, out);
        out.flush();
        out.close();
    }
    static class AtcoderA {
        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            String s = sc.next(), t = sc.next();
            if (t.startsWith(s))
                out.println("Yes");
            else
                out.println("No");
        }
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            return st.nextToken();
        }

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


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  double num1 = ((float)A / D);
  double num2 = ((float)C / B);
  
  //if((num1 - (int)num1) > 0.0)num1+=1.0;
  if((num1 -(int)num1) > 0.0)num1 = (int)num1 + 1.0;
  if((num2 -(int)num2) > 0.0)num2 = (int)num2 + 1.0;
  //cout << num1 << endl;
  //cout << num2 << endl;
  if(num1 >= num2)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------
ll dp[55][55][3000];
int main(){
  int N,A;
  cin >> N >> A;
  vector<int> x(N);
  for(int i=0; i<N; i++){
    cin >> x[i];
  }
  for(int i=0; i<55; i++){
    for(int j=0; j<55; j++){
      for(int k=0; k<3000; k++){
        dp[i][j][k] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  for(int i=0; i<N; i++){
    for(int j=0; j<=i; j++){
      for(int k=0; k<3000; k++){
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
        dp[i+1][j][k] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  for(int j=1; j<=N; j++){
    ans += dp[N][j][j*A];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 71168
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

#define T 800

int main(int argc, char const *argv[])
{
	int N,M;
	int r;
	int t,n,m,s;
	int q;
	int ts,te;
	int ans;

	while(1){
		cin>>N>>M;
		if(N+M==0) break;

		map<int,vector<int> > lio;

		for(int i1=0;i1<M;i1++){
			vector<int> v(T);
			fill(v.begin(), v.end(),0);
			lio[i1]=v;
		}

		cin>>r;
		for(int i1=0;i1<r;i1++){
			cin>>t>>n>>m>>s;
			vector<int> v=lio[m-1];
			if(s==1) v[t-540]+=1;
			else if(s==0) v[t-540]+=-1;
			lio[m-1]=v;
			
		}

		for(int i1=0;i1<M;i1++){
			vector<int> v=lio[i1];
			for(int i2=1;i2<T;i2++){
				v[i2]=v[i2-1]+v[i2];
			}
			lio[i1]=v;
		}

		cin>>q;
		for(int i1=0;i1<q;i1++){
			cin>>ts>>te>>m;

			vector<int> v=lio[m-1];
			ans=0;
			for(int i2=ts-540;i2<te-540;i2++){
				if(v[i2]>0) ans++;
			}
			cout<<ans<<endl;
		}



	}
	return 0;
}

Measured memory_bytes: 32156
#include <stdio.h>
#include <string.h>

int main(void){
	char str[201] = { 0 };
	char str1[201] = { 0 };
	char str2[201] = { 0 };
	int n;
	int m;
	int h;
	int i;

	while (1){
		scanf("%s", str);

		if (strcmp(str, "-") == 0){
			break;
		}

		n = strlen(str);

		scanf("%d", &m);

		for (i = 0; i < m; i++){
			scanf("%d", &h);
			strncpy(str2, str, h);
			strncpy(str1, str+h, n - h);
			strcpy(str, strcat(str1, str2));
			memset(str1, '\0', n);
			memset(str2, '\0', h);
		}
	
		printf("%s\n", str);
		memset(str, '\0', n);
	}

	return 0;
}

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

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

    set<int> a = {1, 3, 5, 7, 8, 10, 12};
    set<int> b = {4, 6, 9, 11};
    set<int> c = {2};
    if ((a.count(x) && a.count(y)) || (b.count(x) && b.count(y))) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;

const int MAX_N = 1e5, INF = 1e9 + 1;
int n, m;
struct ver {
    map<int, int> to;
    int dist = INF;
};
ver v[MAX_N];

bool dfs(int x, int y) {
    if (v[x].dist != INF) {
        if (v[x].dist != y) return false;
        else return true;
    }
    v[x].dist = y;
    for (auto &i : v[x].to) {
        if (!dfs(i.first, y + i.second)) return false;
    }
    return true;
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int l, r, d;
        scanf("%d %d %d", &l, &r, &d);
        v[l - 1].to.emplace(r - 1, d);
        v[r - 1].to.emplace(l - 1, -d);
    }
    
    for (int i = 0; i < n; i++) {
        if (v[i].dist == INF) {
            if (!dfs(i, 0)) {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 26368
//=======================================
// abc145a
//
//  2019/11/16
//=======================================

#include <bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[])
{
	cin.tie(0);
  ios::sync_with_stdio(false);

  double r; cin >> r;

  cout << r*r << endl;


  return 0;
}

Measured memory_bytes: 256
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
li = [chr(ord('a') + i) for i in range(26)]
for c in s:
    if c in li:
        li.remove(c)
if li:
    print(li[0])
else:
    print('None')




Measured memory_bytes: 3700
#include<stdio.h>
int main() {
	int n, i;
	scanf("%d", &n);
	for (i = 1;i <= n;i++) {
		if (i % 3 == 0) {
			printf(" %d", i);
		}
		else {
				if (i % 10 == 3) {
					printf(" %d", i);
				}				
				else if ((i / 10) % 10 == 3) {
					printf(" %d", i);
				}
				else if ((i / 10 / 10) % 10 == 3) {
					printf(" %d", i);
				}
				else if ((i / 10 / 10 / 10) % 10 == 3) {
					printf(" %d", i);
				}
		}
		}
	printf("\n");
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<int> p(n), q(n), per(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    rep(i, n) per[i] = i + 1;
    int np, nq;
    int idx = 0;
    do
    {
        if (p == per)
        {
            np = idx;
        }
        if (q == per)
        {
            nq = idx;
        }
        idx++;
    } while (next_permutation(all(per)));

    cout << abs(nq - np) << '\n';

    return 0;
}


Measured memory_bytes: 3568
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            vars()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)


import numpy as np

def solve(N, D, A, XH):
    q = []
    idx_q = 0
    I = XH[:, 0].argsort()
    XH = XH[I]
    XH[:, 1] = -(-XH[:, 1]//A)
    d = 0
    ans = 0
    for i in range(N):
        x, h = XH[i]
        while idx_q < len(q) and q[idx_q][0] <= x:
            d -= q[idx_q][1]
            idx_q += 1
        if d < h:
            q.append((x + D*2+1, h-d))
            ans += h-d
            d = h
    return ans

numba_compile([
    [solve, "i8(i8,i8,i8,i8[:,:])"],
])

import sys
def main():
    N, D, A = map(int, input().split())
    XH = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N, 2)
    ans = solve(N, D, A, XH)
    print(ans)

main()


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

using namespace std;

string s;
unsigned long long ans=0;
bool arr[9]={0};

void subset(int y){
    if (y==s.size()-1){
        unsigned long long a=0;
        int q=0;
        for (int i=0;i<s.size()-1;i++){
            if (arr[i]==1){
                a+=stoi(s.substr(q,i+1-q));
                q=i+1;
            }
        }
        ans+=a+stoull(s.substr(q,s.size()-q));
    }else{
        subset(y+1);
        arr[y]=1;
        subset(y+1);
        arr[y]=0;
        return;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>s;
    if (s.size()==1){
        cout<<s<<endl;
        return 0;
    }subset(0);
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

vector<ll>lay;
ll n, k;

ll fun(ll n, ll x){
	if (n == 0)return (x <= 0 ? 0 : 1);
	ll p = (1LL << n) - 1;
	if (x <= 2*p)return fun(n - 1, x - 1);
	return p + 1 + fun(n - 1, x - (1 + 2*p));
}

int main(){
	cin >> n >> k;
	lay.push_back(1);
	for (int i = 1; i <= n; i++){
		ll l = lay[i - 1] * 2 + 3;
		lay.push_back(l);
	}
	cout << fun(n, k) << endl;
}

Measured memory_bytes: 256
#Prime Numbers

import math

def is_prime(n):
    if n <= 3:
        return True
    
    if n % 2 == 0:
        return False 

    limit = int(math.sqrt(n)) + 1
    limit = limit if limit < n//2 else n//2 + 1

    for i in range(3,limit,2):
        if n % i == 0:
            return False
        #print(f"i:{i}")  # dbg
    
    return True

n = int(input())

ans = 0
for i in range(n):
    if is_prime(int(input())):
        ans += 1

print(ans) 


Measured memory_bytes: 5672
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, ABC, Q, K, XY):
    kd = [0] * (N+1)
    kd[K] = 0
    g = defaultdict(dict)
    for a, b, c in ABC:
        g[a][b] = c
        g[b][a] = c

    q = [K]
    while q:
        n = q.pop()
        for m, c in g[n].items():
            if m != K and kd[m] == 0:
                kd[m] = kd[n] + c
                q.append(m)

    for x, y in XY:
        print(kd[x] + kd[y])


def main():
    N = read_int()
    ABC = [read_int_n() for _ in range(N-1)]
    Q, K = read_int_n()
    XY = [read_int_n() for _ in range(Q)]

    slv(N, ABC, Q, K, XY)


if __name__ == '__main__':
    main()


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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

void first_win(){
    p("Hom");
    exit(0);
}

void second_win(){
    p("Tem");
    exit(0);
}

bool can_win(ll a, ll b, ll c){
    vector<ll> A;
    A.push_back(a);
    A.push_back(b);
    A.push_back(c);
    
    ll odd_count = 0;
    for(ll a : A){
        if(a%2==1) odd_count++;
    }

    if(odd_count>=2){
        return true;
    }else{
        return false;
    }
}

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

    // input
    ll a, b, c;
    cin >> a >> b >> c;

    if(can_win(a, b, c)){
        first_win();
    }else{
        second_win();
    }
    return 0;
}


Measured memory_bytes: 3208
NMC = list(map(int, input().split()))
B = list(map(int, input().split()))
A = []
for i in range(NMC[0]):
    A.append(list(map(int, input().split())))
ans = 0
tmp = 0
for a in A:
    tmp = 0
    for i in range(NMC[1]):
        tmp += (a[i]*B[i])
    tmp += NMC[2]
    if tmp > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
# coding: utf-8
import sys


def main():

    NumCount = 0

    lines = sys.stdin.readlines()
    for i,line in enumerate(lines):
        if i==0:
            continue
        else:
            value = line.split()
            if len(value)==1:
                NumCount += 1
            else:
                NumCount += int(value[1])-int(value[0]) + 1
    print(NumCount)
    return


if __name__=='__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int []a = new int [n];
		int []b = new int [n+1];
		
		b[0] = 10000000; b[n] = 100000000;
		
		for(int i = 1; i < n ; i++) {
		   b[i] = sc.nextInt();
		}
		int sum = 0;
		for(int i = 0 ; i < n ; i++) {
			a[i] = Math.min(b[i], b[i+1]);
			sum += a[i];
		}
		System.out.println(sum);

	}

}


Measured memory_bytes: 23252
#include<stdio.h>

 int main(){
     int n,i=0;
     long num,MAX,MIN,SUM=0;
     
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%ld",&num);
        if(i == 1)
            MIN = MAX = num;
        if(MAX<num){
            MAX=num;
        }else if(MIN>num){
            MIN=num;
        }
        SUM+=num;
    }
    printf("%ld %ld %ld\n",MIN,MAX,SUM);
 }


Measured memory_bytes: 2112
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
	    String s = "No";
        int count = 0;
        for(int i=0;i<a;i++){int b = sc.nextInt();
                             int c = sc.nextInt();
                             if(b==c){count++;}
                             else{count=0;}
                             if(count>=3){s="Yes";break;}
                            }		       
		System.out.println(s);
	}
}

Measured memory_bytes: 36144
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,m;
	cin>>n>>m;
	long long s;
	long long e;
	s=n%2019;
	e=m%2019;
	if(m-n>=2019)e+=2019;
	long long minv=999999999;
	for(long long i=s;i<=e;i++){
		for(long long j=i+1;j<=e;j++){
			if(i%2019==0||j%2019==0){
				cout<<"0";
				return 0;
			}
		    minv=min(minv,i*j%2019);	
		}
	}
	cout<<minv<<endl;
	return 0;
}

Measured memory_bytes: 256
def solve(H, W, s):
    scores = [[float('inf') for _ in range(W)] for _ in range(H)]
    scores[0][0] = 0 if s[0][0] == '.' else 1

    for i in range(H):
        for j in range(W):
            for x, y in [(i - 1, j), (i, j - 1)]:
                if x < 0 or y < 0:
                    continue
                if s[i][j] == '.' or s[x][y] == '#':
                    scores[i][j] = min(scores[i][j], scores[x][y])
                else:
                    scores[i][j] = min(scores[i][j], scores[x][y] + 1)

    return scores[H - 1][W - 1]

if __name__ == '__main__':
    H, W = map(int, input().split())
    s = []
    for _ in range(H):
        s.append(list(input()))

    print(solve(H, W, s))


Measured memory_bytes: 41456
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((c-b)==(b-a)) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3620
def main() -> None:
    S = input()
    left, right = 0, len(S) - 1
    ans = 0
    while left < right:
        if S[left] == S[right]:
            left, right = left + 1, right - 1
        elif S[left] == 'x':
            ans += 1
            left += 1
        elif S[right] == 'x':
            ans += 1
            right -= 1
        else:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
	int k,a,b;
	cin >> k >> a >> b;
	b = b/k*k;
	if(a <= b) cout << "OK" << endl;
	else cout << "NG" << endl;
}

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

int main()
{
  string q;
  while(cin >> q){
    int n;
    int res = 0;
    cin >> n;
    for(int i = 0; i < n; ++i){
      string ring;
      cin >> ring;
      ring += ring;
      if( ring.find(q) != string::npos ){
	++res;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



string s;
int n, x, dp[10010][101][2];

signed main() {
	cin >> s >> x;
	n = (int)s.size();
	dp[0][0][0] = 1;
	rep(i,n) rep(j,x) rep(k,2) if (dp[i][j][k]) rep(d,(k ? 9 : (s[i]-'0'))+1)
		(dp[i+1][(j+d)%x][k|(d<(s[i]-'0'))] += dp[i][j][k]) %= mod;
	cout << (dp[n][0][0] + dp[n][0][1] + mod-1) %mod << endl;
}

Measured memory_bytes: 16000
#define fRead(x)  freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)

#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e7
#define PI acos(-1.0)

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))

#define scanI(a) scanf("%d",&a)
#define scanI2(a,b) scanI(a) , scanI(b)
#define scanI3(a,b,c) scanI(a), scanI(b), scanI(c)
#define scanI4(a,b,c,d) scanI(a), scanI(b), scanI(c), scanI(d)

#define scanL(a) scanf("%I64d",&a)
#define scanL2(a,b) scanL(a) , scanL(b)
#define scanL3(a,b,c) scanL(a), scanL(b), scanL(c)
#define scanL4(a,b,c,d) scanL(a), scanL(b), scanL(c), scanL(d)

#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())

#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);

#include<bits/stdc++.h>

using namespace std;
LL make(LL a,LL b, LL c)
{
    LL area = b*c;
    LL x = a/2;
    LL y = a - x;
    LL z = abs(x-y)*area;
    return z;
}
vector<LL>v;
int main()
{
    LL a,b,c;
    cin >> a >> b >> c;
    v.push_back(make(a,b,c));
    v.push_back(make(b,a,c));
    v.push_back(make(c,b,a));
    SORT(v);
    cout << v[0] << "\n";
}


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

int main()
{
	int n;
	long long m[10000] ;

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

		long long wait[10000] = { 0 }, waitsum = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> m[i];
		}
		
		sort(m, m+n);		//??????????????????

		for (int i = 0; i < n; i++)
		{
			wait[i + 1] = m[i]+wait[i];
		}
		for (int i = 0; i < n; i++)
		{
			waitsum += wait[i];
		}

		cout << waitsum << endl;

	}

	return 0;
}

Measured memory_bytes: 1340
from collections import defaultdict

res = defaultdict(lambda: 0)
#素因数分解O(√n)
def primeFactor(n):
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            res[i] += 1
            n = n // i
    if n != 1:
        res[n] += 1

N = int(input())

for i in range(1, N+1):
    primeFactor(i)

ans = 1
for v in res.values():
    ans *= (v+1)
    ans %= 10**9+7

print(ans)




Measured memory_bytes: 3444
A,B,C,X,Y=gets.split.map(&:to_i)


p1=C*(X>Y ? X : Y)*2
p2=A*X+B*Y
p3=(X>Y ? Y : X)*C*2 + (X-Y).abs*(X>Y ? A : B)

puts [p1,p2,p3].min

Measured memory_bytes: 1788
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    if(a>=1 && a<=100 && b>=1 && b<=100)
    {
      String temp=""+a+""+b;
      int c=Integer.parseInt(temp);
      Double d=Math.sqrt(c);
      int e = d.intValue();
      if(d==e)
      {
        System.out.println("Yes");
      }else
      System.out.println("No");
    }
  }
}

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

int main() {
	int N;
	cin >> N; /*実行回数*/

	int D, Dn;

	int count = 0;
	int countt = 0;

	while (true) {
		if (countt == N) {
			break;
		}

		cin >> D >> Dn;

		if (D == Dn) {
			count++;
		}
		else if (D != Dn) {
			if (3 <= count) {
				count = 3;
			}
			else {
				count = 0;
			}
		}

		countt++;
	}
	if (3 <= count) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O3")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<a[i]<<c;
	cout<<"\n";
}

lli tmod(lli x,lli m){return (x%m+m)%m;}//USE AT YOUR OWN RISK
lli power(lli x, lli y) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;  
    }
    if(res<0)
       res+=mod; 
    return res; 
}
lli fact[2000009];
lli ncr(lli n,lli r){
    lli ans=fact[n];
    if(r>n)return 0;
    ans=(ans*power(fact[n-r],mod-2))%mod;
    ans=(ans*power(fact[r],mod-2))%mod;
    return ans;
}
int main() 
{ 
    fastio;
    fact[0]=1;
    f(i,1,2000009)fact[i]=(fact[i-1]*i)%mod;
    lli ans=0;
    lli r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    f(i,r1,r2+1){
        ans=(ans+ncr(i+c2+1,i+1)-ncr(i+c1,i+1))%mod;
    }
    cout<<tmod(ans,mod);
    return 0; 	
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/
template<class T> class Dijkstra {
public:
    int N;
    T inf;
    vector<T> cost;
    vector<vector<pair<T, int>>> edge;
 
    Dijkstra(const int N, T inf) : N(N), inf(inf),cost(N), edge(N) {
    }
 
    void make_edge(int from, int to, T w) {
        edge[from].push_back({ w,to });
    }
 
    void solve(int start) {
        for(int i = 0; i < N; ++i) cost[i] = inf;
 
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
        cost[start] = 0;
        pq.push({ 0,start });
 
        while (!pq.empty()) {
            T v = pq.top().first;
            int from = pq.top().second;
            pq.pop();
            for (auto u : edge[from]) {
                T w = v + u.first;
                int to = u.second;
                if (w < cost[to]) {
                    cost[to] = w;
                    pq.push({ w,to });
                }
            }
        }
        return;
    }
};

/*
使い方
1. まずインスタンス生成
重みの型、頂点の数、距離の無限大のINFLL
Dijkstra<ll> d(N, INFLL);

2. 辺を貼る
iからjに重みwの辺を貼る場合
d.make_edge(i,j,w);

3. 頂点sから解く
d.solve(s);

4. sからgの距離
d.cost[g]

GigaCode2019 E - 車の乗り継ぎ
https://atcoder.jp/contests/gigacode-2019/submissions/8651446

*/
/*------------------------------------*/

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

    ll N,M,s,t;
    cin>>N>>M>>s>>t;
    Dijkstra<ll> d1(N, INFLL);
    Dijkstra<ll> d2(N, INFLL);
    s--;t--;
    rep(i,M){
        ll u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;v--;
        d1.make_edge(u,v,a);
        d1.make_edge(v,u,a);

        d2.make_edge(u,v,b);
        d2.make_edge(v,u,b);
    }
    d1.solve(s);
    d2.solve(t);

    ll money = 1e15;
    ll maxx = 0;
    vector<ll> ans(N);
    for(int i = N-1; i >= 0; i--){
        ll cost = d1.cost[i] + d2.cost[i];
        ll tmp = money - cost;
        chmax(maxx, tmp);
        ans[i] = maxx;
    }
    rep(i,N){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 19016
S = input()
s_num = len(S)

i=0
max_count = 0
count = 0

while i < s_num:
    if S[i] != "R":
        if max_count < count:
            max_count = count
            count = 0
    elif S[i] == "R":
        count += 1

    i+=1

if max_count < count:
    max_count = count

print(max_count)

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

ll height[100000];
int higher[100000];
int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) cin >> height[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b; a--; b--;
    if (height[a] >= height[b]) higher[b]++;
    if (height[a] <= height[b]) higher[a]++;
  }
  int ans = 0;
  rep(i, n) if (higher[i] == 0) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4776
n,m=map(int, input().split())
k=[list(map(int, input().split())) for _ in range(m)]
p=list(map(int, input().split()))

ans=0

for i in range(2**n):
    t=0
    for j in range(m):
        o=sum(1 for h in k[j][1:] if i >>(h-1)&1)
        if o%2==p[j]:
            t+=1
    if t==m:
        ans+=1
print(ans)

Measured memory_bytes: 9200
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
	if (a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int lcm(int a, int b) {
	long long int L;
	L = (a * b) / gcd(a, b);
	return L;
}

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	for (int i = 2; i * i <= n; i++) {
		;
		if (is_prime.at(i)) {
			for (int j = i * i; j <= n; j += i) {
				is_prime.at(j) = false;
			}
		}
		Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int keta(long long int N) {
	int k = 0;
	while (N > 0) {
		N /= 10;
		k++;
	}
	return k;
}



int Combination(int n, int m) {
	long long int s = 1, t = 1;
	int tmp = n;
	while (n - m != tmp) {
		s *= tmp;
		tmp--;
	}
	tmp = m;
	while (tmp != 1) {
		t *= tmp;
		tmp--;
	}
	return s / t;
}

int main() {
	string s;
	cin >> s;
	int c = 0;
	for (int i = 0; i < s.size() / 2; i++) {
		if (s[i] != s[s.size() - i - 1])
			c++;
	}
	cout << c << endl;
}

Measured memory_bytes: 256
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846

ll n, m;
char g[111][111];
const ll inf = 1e13;
ll memo[111][111][2];
ll dp(ll x, ll y, ll inverted) {
	if (x >= n || y >= m)
		return inf;
	if (x == n - 1 && y == m - 1) {
		//cout << inverted << "_" <<
		//((g[x][y] == '#' && inverted) || g[x][y] == '.'? 0 : 1) << endl;
		return (g[x][y] == '#' && inverted) || g[x][y] == '.'? 0 : 1;
	}
	if (memo[x][y][inverted] != -1)
		return memo[x][y][inverted];
	ll ans = inf;
	if (inverted) {
		if (g[x][y] == '.')
			ans = min(dp(x + 1, y, 0), dp(x, y + 1, 0));
		else
			ans = min(dp(x + 1, y, 1), dp(x, y + 1, 1));
	}else {
		if (g[x][y] == '#')
			ans = 1 + min(dp(x + 1, y, 1), dp(x, y + 1, 1));
		else
			ans = min(dp(x + 1, y, 0), dp(x, y + 1, 0));
	//cout << x << " " << y << " " << " " << inverted << " " << ans << endl;
	}
	return memo[x][y][inverted] = ans;
}

int main(){
	FASTIO;
	cin >> n >> m;
	for ( int k = 0; k < n; k++ )
		cin >> g[k];
	for ( int k = 0; k < 101; k++ )
		for ( int j = 0; j < 101; j++ )
			memo[k][j][0] = memo[k][j][1] = -1;
	cout << dp(0, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
#define N 1e9+10;
ll n,m,i,j,k,t,l,r;
ll a,b,c,d;
char A,C,X,Y,Z;
ll ans,MAX,MIN,sum;
ll ax[2000500];
char cx[500];
ll dx[12];
ll bx[500];


int main()
{
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
        cin >> n;
        int flag=0;
        if(n%10==7) flag=1;
        n=n/10;
        if(n%10==7) flag=1;
        n=n/10;
        if(n%10==7) flag=1;
        if(flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 3636
// finish date: 2018/02/02
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;


int main() {
    int N, A, B;
    cin >> N >> A >> B;
    ll total = 0;
    vi X(N);
    rep(i, N) cin >> X[i];
    //sort(X.begin(),X.end());
    FOR(i, 1, N) {
        total += min((ll)A * (X[i] - X[i - 1]), (ll)B);
    }
    cout << total << endl;

    return 0;
}



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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S;
    cin >> S;
    ll cnt = 0;
    for (int i = 0; i < S.size()/2; i++) {
        if(S[i] != S[S.size()-1-i]){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main(){
    string a, b, c;
    cin>>a>>b;
    ll sa, sb;
    cin>>sa>>sb;
    cin>>c;
    if(a == c) sa--;
    else if(b == c) sb--;
    cout<<sa<<" "<<sb;
}

Measured memory_bytes: 256
while True:
    t= int(input())
    if t== 0: break
    n= int(input())
    c= [list(map(int, input().split())) for _ in range(n)]
    sf= sum(c[i][1]-c[i][0] for i in range(n))
    print("OK" if t<= sf else t-sf)

Measured memory_bytes: 7704
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new java.util.Scanner(System.in);
    String[] st = sc.nextLine().split(" ");
    String S = st[0];
    String T = st[1];
    String[] times = sc.nextLine().split(" ");
    int A = Integer.parseInt(times[0]);
    int B = Integer.parseInt(times[1]);
    String U = sc.nextLine();
    if (S.equals(U)) {
      A -= 1;
    } else if (T.equals(U)) {
      B -= 1;
    }
    System.out.println(A + " " + B);
  }
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll x;
    cin >> x;
    ll temp = 1999 - x;
    cout << temp / 200 + 1 << endl;
    return 0;
}



Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>

int main(void){
	char a[10005];
	char b[5];
	int ioi=0;
	int joi=0;
	
	while (scanf("%s",a)!=EOF){
		ioi=0;
		joi=0;
		int length;
		length= (int)strlen(a);
		
		int i;
		for (i=0;i<(length-2);i++){
			strncpy(b,&a[i],3);
			if (strcmp(b,"JOI")==0){
				joi++;
			}else if (strcmp(b,"IOI")==0){
				ioi++;
			}
		}
		printf("%d\n",joi);
		printf("%d\n",ioi);
	}					
	return 0;
}

Measured memory_bytes: 568
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int inf=1e9;
const ll INF=1e18;
const double pi=3.1415926535897932384626433832;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,ans;
  cin >> a >> b;
  if(abs(a-b)>=2) {
    cout << 0 << endl;
  }
  else if(a==b) {
    ans=1;
    for(int i=a; i>=1; i--) {
      ans*=i;
      ans%=MOD;
      ans*=i;
      ans%=MOD;
    }
    ans*=2;
    ans%=MOD;
    cout << ans << endl;
  }
  else {
    ans=1;
    for(int i=a; i>=1; i--) {
      ans*=i;
      ans%=MOD;
    }
    for(int i=b; i>=1; i--) {
      ans*=i;
      ans%=MOD;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

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

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

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 3636
def main():
    n = int(input())

    s, cnt = 0, 0
    while s < n:
        cnt += 1
        s += cnt

    for i in range(cnt, -1, -1):
        if n - i >= 0:
            print(i)
            n -= i

        if n == 0:
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
i = input()
count = 0
first_half, second_half = i[:len(i)//2], i[(len(i)+1)//2:]
if first_half == reversed(second_half):
    print(count)
else:
    for x in range(len(first_half)):
        if first_half[x] != second_half[len(second_half)-x-1]:
            count += 1
    print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<vector>
#include<utility>
#include<cstring>
#include<limits.h>
#define pb(a)             push_back(a)
#define mp(a,b)           make_pair(a,b)
#define pf printf
#define ff first
#define ss second
#define sef second.first
#define ses second.second
#define ms(a,b)            memset(a, b, sizeof(a))
#define lp(i,a,b) for (int i = a; i <= b; i++)
#define pii                pair <int,int>
#define sl(a)              scanf("%I64d",&a)
#define sll(a,b)           scanf("%I64d %I64d",&a,&b)
#define si(a)              scanf("%d",&a)
#define sii(a,b)           scanf("%d %d",&a,&b)
#define EulerGamma 0.57721566490153286060651209;/// when n>1e6  nth harmonic num = log(x+.5)+EulerGamma;
///UINT_MAX 2^32
///ULLONG_MAX 2^64
/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction
/*-----------------------Bitmask------------------*/
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define S2(x,y) scanf("%d%d",&(x),&(y))
#define SL(x) scanf("%lld",&(x))
#define SL2(x) scanf("%lld%lld",&(x),&(y))
#define P(x) printf("%d\n",(x))
using namespace std ;
typedef long long ll ;
map < ll , ll > saved ;
void calco(ll n)
{
    while(!(n&1))
    {
        saved[2]++;
        n = n >> 1 ;
    }
    for(ll i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        {
            while(n%i==0)
            {
                saved[i]++;
                n = n/i ;
            }
        }
    }
    if(n>1){saved[n]++;}
}
int main()
{
   ll n,temp=0;
   cin >> n ;
   calco(n);
   for(auto it : saved)
   {
       ll val = it.ff , co = it.ss ;
       ll p = 1 ;
       while(p<=co)
       {
           temp++;
           co-=p;
           p=p+1;
       }
   }
   cout << temp << endl;
   return 0 ;
}


Measured memory_bytes: 3644