akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>

using namespace std;
#define mod 10000
#define MAX_N (100+1)
int n, k;
int sche[MAX_N];

int dp[MAX_N][4][4];
int cnt(int day, int one, int two) {
    if (day == n) return 1;
    if (dp[day][one][two] >= 0) return dp[day][one][two];
    if (sche[day] > 0) {
        if (one == two && two == sche[day]) return dp[day][one][two] = 0;
        return dp[day][one][two] = cnt(day+1, sche[day], one);
    }
    int ret = 0;
    for (int i = 1; i <= 3; i++) {
        if (one == two && two == i) continue;
        ret += cnt(day+1, i, one);
        ret %= mod;
    }
    return dp[day][one][two] = ret % mod;
}

int main() {
    cin >> n >> k;
    memset(sche, -1, sizeof(sche));
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < k; i++) {
        int d, p; cin >> d >> p;
        d--;
        sche[d] = p;
    }
//    for (int i = 0; i < n; i++) cout << sche[i] << ' ';cout << endl;
    cout << cnt(0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 1172
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
cnt = Counter(A)
tot = sum(A)
q = int(input())
ans = []
for _ in range(q):
    b,c = map(int,input().split())
    if b not in cnt.keys():
        ans.append(tot)
    else:
        d = cnt[b] * (c-b)
        tot += d
        ans.append(tot)
        cnt[c] += cnt[b]
        cnt[b] = 0
for a in ans:
    print(a)

Measured memory_bytes: 94704
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;
ll N, Q;

ll findParent(ll a, ll b)
{
	ll max = std::max(a, b);
	ll min = std::min(a, b);
	if (N != 1)
	{
		while (max != min)
		{
			max = (max + (N - 2)) / N;
			if (min > max)
			{
				swap(min, max);
			}
		}
	}
	return min;
}

int main()
{
	cin >> N >> Q;
	vector<ll> ans(Q);
	REP(i, Q)
	{
		ll v, w;
		cin >> v >> w;
		ans[i] = findParent(v, w);
	}
	REP(i, Q)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#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 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;
#include <numeric>

using namespace std;
typedef long long ll;

int memo[200][200] = {{0}};

signed main() {
  int k, ans = 0;
  cin >> k;
  for(int i = 1; i <= k; i++) {
    for(int j = 1; j <= k; j++) {
      for(int l = 1; l <= k; l++) {
        int g;
        if(memo[i][j] != 0) {
          g = memo[i][j];
        } else {
          g = __gcd(i, j);
          memo[i][j] = g;
        }
        ans += __gcd(g, l);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,W;
  cin >> N >> W;
  vp wv(N);
  rep(i,N) {
    int we,va;
    cin >> we >> va;
    wv[i] = P(we,va);
  }
  v(ll) dp(W+1,-LINF);
  dp[0] = 0;
  rep(i,N) {
    v(ll) dp2(W+1,-LINF);
    dp2[0] = 0;
    ll we = wv[i].first;
    ll va = wv[i].second;
    rep(w,W+1) {
      if(w-we < 0) {
        dp2[w] = dp[w];
        continue;
      }
      dp2[w] = max(dp[w],dp[w-we]+va);
    }
    dp = dp2;
  }
  ll ans = -INF;
  rep(i,W+1) {
    ans = max(ans,dp[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1804
def getDepth(u):
    d = 0
    while node_list[u].parent != -1:
        u = node_list[u].parent
        d += 1
    return d
def getChildren(u):
    c = node_list[u].left
    child_list = []
    while c != -1:
        child_list.append(c)
        c = node_list[c].right
    return child_list

def getType(u):
    if node_list[u].parent == -1:
        return "root"
    if node_list[u].left == -1:
        return "leaf"
    return "internal node"
max_value = 10 ** 10
nil = -1

class Node():
    " node of the tree structure"
    def __init__(self, name = -1, parent = -1, left = -1, right = -1):
        self.name = name
        self.parent = parent
        self.left = left
        self.right = right
node_list = []
n = int(input())
for i in range(n):
    node = Node()
    node_list.append(node)

for i in range(n):
    a,b,*args = map(int, input().split())
    for j in range(b):
        if j == 0:
            node_list[a].left = args[j]
        else:
            node_list[l].right = args[j]
        l = args[j]
        node_list[args[j]].parent = a


#for i in range(n):

for i in range(n):
    print("node", str(i) + ":" , "parent =", str(node_list[i].parent) + ",", "depth =", str(getDepth(i)) + ",", getType(i) + ",", getChildren(i))



Measured memory_bytes: 33648
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a[5];
  for(int i=0;i<5;i++) cin >> a[i];
  int b[5];
  for(int i=0;i<5;i++){
    b[i] = 10 - a[i] % 10;
    if(b[i] == 10) b[i] = 0;
  }

  int mx = *max_element(b,b+5);

  int ans = 0;
  for(int i=0;i<5;i++){
    ans += a[i] + b[i];
  }

  ans -= mx;

  cout << ans << endl;
  return 0;


}


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

namespace AtCoder
{
    class Program
    {
        static void Main (string[] args)
        {
            var N = Int32.Parse(Console.ReadLine());
            var result = new Dictionary<string, int> ();
            long total = 0;

            for(var i = 0;N > i;i++)
            {
                var line = new string(Console.ReadLine().OrderBy(v => v).ToArray());

                if (result.ContainsKey (line))
                {
                    result[line]++;
                    total += result[line];
                }
                else
                {
                    result[line] = 0;
                }
            }

            Console.WriteLine (total);
        }
    }
}

Measured memory_bytes: 31384
class Node:
    def __init__(self, idn):
        self.id = idn
        self.left = -1
        self.right = -1
        self.parent = -1

n = int(input())
T = [Node(i) for i in range(n)]
for ni in range(n):
    idn, left, right = [int(i) for i in input().split()]
    T[idn].left = left
    T[idn].right = right
    if left != -1:
        T[left].parent = idn
    if right != -1:
        T[right].parent = idn

i = 0
while T[i].parent != -1:
    i = T[i].parent
root = i

orderList = []
def setPreorderList(p):
    orderList.append(T[p].id)
    if T[p].left != -1:
        setPreorderList(T[p].left)
    if T[p].right != -1:
        setPreorderList(T[p].right)

setPreorderList(root)
print("Preorder")
print("",*orderList)

orderList = []
def setInorderList(p):
    if T[p].left != -1:
        setInorderList(T[p].left)
    orderList.append(T[p].id)
    if T[p].right != -1:
        setInorderList(T[p].right)

setInorderList(root)
print("Inorder")
print("",*orderList)

orderList = []
def setPostorderList(p):
    if T[p].left != -1:
        setPostorderList(T[p].left)
    if T[p].right != -1:
        setPostorderList(T[p].right)
    orderList.append(T[p].id)

setPostorderList(root)
print("Postorder")
print("",*orderList)
    


Measured memory_bytes: 5616
#include<cstdio>
int main(){
    char s[101];
    scanf("%s",s);
    int c=-1,f=-1;
    for(int i=0;s[i]!='\0';i++){
        if(c==-1 && s[i]=='C')c=i;
        if(s[i]=='F')f=i;
    }
    if(c==-1 || f==-1 || c>=f)printf("No");
    else printf("Yes");
    return 0;
}

Measured memory_bytes: 128
using System;

class Program
{
    static void Main()
    {
        while (true)
        {
            var line = Console.ReadLine().Split(' ');
            int n = int.Parse(line[0]);
            int x = int.Parse(line[1]);
            int counter = 0;

            if (n == 0 && x == 0) break;
            for(var i=1; i<=n; i++)
            {
                for(var j=i+1; j<=n; j++)
                {
                    for(var k=j+1; k<=n; k++)
                        if (i + j + k == x) counter++;
                }
            }
            Console.WriteLine(counter);
        }
    }

}



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

int main(void) {
    char str[1000];
    int i;
    
    fgets(str, sizeof(str), stdin);
    
    for(i = 0; str[i] != '\n'; i++) {
        if(!(strncmp(&str[i], "peach", 5))) {
            str[i] = 'a';
            str[i + 1] = 'p';
            str[i + 2] = 'p';
            str[i + 3] = 'l';
            str[i + 4] = 'e';
        } else if(!(strncmp(&str[i], "apple", 5))) {
            str[i] = 'p';
            str[i + 1] = 'e';
            str[i + 2] = 'a';
            str[i + 3] = 'c';
            str[i + 4] = 'h';
        }
    }
    
    printf("%s", str);
    
    return(0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
#define f first
#define s second
#define pb push_back

ll a, b, c;

int main() {
	cin >> a >> b >> c;
	if (c <= a+b) cout << "No";
	else if (a*a + b*b + c*c > 2*a*b + 2*a*c + 2*b*c) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAXDATA 10001
int main(){
  int i,datanum,temp;
  int *a,*b;
  int c[MAXDATA];//a ni dainyu
  scanf("%d",&datanum);
  a = (int *)malloc(sizeof(int) * (datanum + 1));
  b = (int *)malloc(sizeof(int) * (datanum + 1)); //sizeがおおきすぎて、mallocじゃないとエラー吐く
  
  for(i=0;i<MAXDATA;i++){
    c[i] = 0;
  }
  for(i=0;i<datanum;i++){
    scanf("%d",&a[i + 1]);
    c[a[i + 1]]++; 
  }
  for(i=1;i<=MAXDATA;i++){
    c[i] = c[i] + c[i-1];
  }
  
  for(i=datanum;i>=1;i--){
    b[c[a[i]]] = a[i];
    c[a[i]]--;
  }
  for(i=1;i<=datanum;i++){
    if(i != 1)printf(" ");
    printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}




Measured memory_bytes: 17412
N=int(input())
*A,=map(int,input().split())

now=1000
amari=0
stock=0
i=0
while i<N-1:
    if A[i]<A[i+1]:
        if stock==0:
            stock=now//A[i]
            amari=now%A[i]
            now=0
    elif A[i]>A[i+1]:
        if stock>0:
            now=stock*A[i]+amari
            stock=0
            amari=0
    i+=1

now=max(now,stock*A[i]+amari)
print(now)

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

using namespace std;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


bool dp[100001] = {false};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    for(int i = 1; i <= k; ++i){
        for(int j = 0; j < n; ++j){
            if (i-a[j]<0) break;
            dp[i] |= !dp[i-a[j]];
        }
    }

    ppp(dp[k]?"First":"Second");



    return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static void insertionSortStep(int[] A, int idx)
    {
        int v = A[idx];
        int i;
        for (i = idx - 1; i >= 0 && A[i] > v; i--) A[i + 1] = A[i];
        A[i + 1] = v;
    }
    public static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        for (int i = 0; i < N; i++)
        {
            insertionSortStep(A, i);
            for (int j = 0; j < N - 1; j++) Console.Write("{0} ", A[j]);
            Console.WriteLine(A[N - 1]);
        }
    }
}


Measured memory_bytes: 18360
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

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

        static void Q()
        {
            var NM = ReadSplitInt();
            var X = ReadSplitInt().OrderBy(x => x).ToArray();

            if (NM[0] >= NM[1])
            {
                Println(0);
                return;
            }

            var list = new List<int>();
            for (int i = 1; i < NM[1]; i++)
            {
                list.Add(X[i] - X[i - 1]);
            }

            list = list.OrderByDescending(x => x).ToList();
            var sum = 0;
            for (int i = 0; i < NM[0]-1; i++)
            {
                sum += list[i];
            }

            Println(X[NM[1] - 1] - X[0] - sum);

        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 25312
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    void run(){
	while(sc.hasNext()){
	    char[] c = sc.next().toCharArray();
	    for(int k=0; k<3; k++)
		for(int i=0; i<c.length; i++)
		if(c[i]>'A')
		    c[i]--;
		else c[i] = 'Z';
		
	    for(int i=0; i<c.length; i++)
		System.out.print(c[i]);
	    System.out.println();
	}
    }
}

Measured memory_bytes: 17232
#include "bits/stdc++.h"
using namespace std;typedef long long lint;typedef vector<lint> liv;
//#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define linf 1152921504606846976
#define MAXN 100010
#define md 1000000007//998244353

#define _vcppunko4(tuple) _getname4 tuple
#define _getname4(_1,_2,_3,_4,name,...) name
#define _getname3(_1,_2,_3,name,...) name
#define _trep2(tuple) _rep2 tuple
#define _trep3(tuple) _rep3 tuple
#define _trep4(tuple) _rep4 tuple
#define _rep1(n) for(lint i=0;i<n;++i)
#define _rep2(i,n) for(lint i=0;i<n;++i)
#define _rep3(i,a,b) for(lint i=a;i<b;++i)
#define _rep4(i,a,b,c) for(lint i=a;i<b;i+=c)
#define _trrep2(tuple) _rrep2 tuple
#define _trrep3(tuple) _rrep3 tuple
#define _trrep4(tuple) _rrep4 tuple
#define _rrep1(n) for(lint i=n-1;i>=0;i--)
#define _rrep2(i,n) for(lint i=n-1;i>=0;i--)
#define _rrep3(i,a,b) for(lint i=b-1;i>=a;i--)
#define _rrep4(i,a,b,c) for(lint i=a+(b-a-1)/c*c;i>=a;i-=c)
template<class T>
istream& operator>>(istream& is,vector<T>& vec);
template<class T,size_t size>
istream& operator>>(istream& is,array<T,size>& vec);
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p);
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec);
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p);
template<class T>
istream& operator>>(istream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
//template<class T>
//ostream& operator<<(ostream& os,vector<T>& vec){ os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; }
//template<class T>
//ostream& operator<<(ostream& os,deque<T>& deq){ os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; }
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p){ os<<p.first<<" "<<p.second;return os; }

inline void in(){}
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); }
template <class T>
inline bool out(T t){ cout<<t<<'\n';return 0; }
inline bool out(){ cout<<'\n';return 0; }
template <class Head,class... Tail>
inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; }

#define rep(...) _vcppunko4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__))
#define rrep(...) _vcppunko4((__VA_ARGS__,_trrep4,_trrep3,_trrep2,_trrep1))((__VA_ARGS__))
#define lin(...) lint __VA_ARGS__;in(__VA_ARGS__)
#define stin(...) string __VA_ARGS__;in(__VA_ARGS__)
#define vin(type,name,size) vector<type> name(size);in(name)

int main(){
	char a;in(a);
	if(a=='A')cout<<"T\n";
	if(a=='T')cout<<"A\n";
	if(a=='C')cout<<"G\n";
	if(a=='G')cout<<"C\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(void)
{
	string S;
	int N, Q;
	int l, r;
	int i;

	cin >> N >> Q;
	cin >> S;

	vector<int> anstmp(N);
	anstmp[0] = 0;
	for (i = 1; i < N; i++) {
		if (S[i] == 'C' && S[i - 1] == 'A') {
			anstmp[i] = anstmp[i - 1] + 1;
		}
		else {
			anstmp[i] = anstmp[i - 1];
		}
	}

	vector<int> ans(Q);
	for (i = 0; i < Q; i++) {
		cin >> l >> r;
		ans[i] = anstmp[r-1] - anstmp[l-1];
	}
	for (i = 0; i < Q; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}


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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1]; for (int i = 0; i < n + 1; i++) { a[i] = 1; }for (int i = 2; i < n + 1; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

vector<vector<pair<int,int>>> Edge;
vector<int> node;

bool bellman_ford(int n,int s) {
	node = vector<int>(n,INF);
	node[s] = 0;
	REP (i,n) {
		REP (j,Edge.size()) {
			REP (k,Edge[j].size()) {
				int from = j,to = Edge[j][k].F;
				int cost = Edge[j][k].S;
				if (node[from] != INF && node[to] > node[from] + cost) {
					node[to] = node[from] + cost;
					if (i == n - 1 && to == n - 1) return true;
				}
			}
		}
	}
	return false;
}

//0は縦1は横
int dp[60][2];

signed main() {
	int n;
	cin >> n;
	string s1,s2;
	cin >> s1 >> s2;
	if (s1[0] == s2[0]) dp[0][0] = 3;
	if (s1[1] == s2[1]) dp[1][0] = 6;
	if (s1[0] == s1[1]) dp[1][1] = 6;
	FOR (i,2,n) {
		if (s1[i] == s2[i]) dp[i][0] = (dp[i-1][0] * 2 + dp[i-1][1]) % mod;
		if (s1[i] == s1[i-1]) dp[i][1] = (dp[i-2][0] * 2 + dp[i-2][1] * 3) % mod;
	}
	if (n == 1) cout << 3 << endl;
	else {cout << (dp[n-1][0] + dp[n-1][1]) % mod << endl;}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<functional>
using namespace std;

int h,w;
int cost[128][128];
char m[128][128];

const char FLOOR='.';

struct P{
	int x,y;
	P(int x,int y):x(x),y(y){}
	P(){}
	bool operator<(const P&)const{return false;}
};
typedef pair<int,P>Pair;	//cost,Pos

int Cost(P s, P g)
{
	const int dx[]={1,0,-1,0},dy[]={0,1,0,-1,};
	bool visited[128][128]={};
	priority_queue<Pair,vector<Pair>,greater<Pair> >q;
	q.push(Pair(0,s));
	while(!q.empty())
	{
		Pair pa=q.top(); q.pop();
		P p=pa.second;
		if(visited[p.y][p.x]++)
			continue;
		else if(p.x==g.x && p.y==g.y)
			return pa.first;
		for(int i=0;i<4;++i)
		{
			int ax=p.x+dx[i];
			int ay=p.y+dy[i];
			if(m[ay][ax]!=FLOOR || visited[ay][ax])
				continue;
			q.push(Pair(pa.first+cost[p.y][p.x],P(ax,ay)));
		}
	}
	return -1e9;
}

void AddCost(int x,int y)
{
	for(int dy=-2;dy<=2;++dy)
	{
		for(int dx=-2;dx<=2;++dx)
		{
			int ax=x+dx;
			int ay=y+dy;
			if(1<=ax&&ax<=w&&1<=ay&&ay<=h)
				cost[ay][ax]=max(cost[ay][ax], 4-max(abs(dx),abs(dy)));
		}
	}
}

int main()
{
	P s,g;
	vector<P>v;
	scanf("%d%d",&w,&h);

	fill_n(&cost[0][0],128*128,1);
	memset(m,'#',sizeof(m));

	int x,y;
	for(y=1;y<=h;++y)
		scanf("%s",&m[y][1]);
	for(y=1;y<=h;++y)
	{
		for(x=1;x<=w;++x)
		{
			switch(m[y][x])
			{
			case 'S':s=P(x,y);m[y][x]=FLOOR;break;
			case 'G':g=P(x,y);m[y][x]=FLOOR;break;
			case 'M':v.push_back(P(x,y));m[y][x]=FLOOR;break;
			case '#':AddCost(x,y);break;
			}
		}
	}
	const int n=v.size();


	v.insert(v.begin(),s);
	v.push_back(g);
	int edge[8][8];
	for(int i=0;i<v.size();++i)
	{
		for(int j=i+1;j<v.size();++j)
		{
			edge[i][j]=Cost(v[i],v[j]);
			edge[j][i]=Cost(v[j],v[i]);
		}
	}
	int a[]={1,2,3,4,5,6};
	int res = 1e9;
	do
	{
		int temp=edge[0][a[0]]+edge[a[n-1]][n+1];
		for(int i=0;i+1<n;++i)
			temp+=edge[a[i]][a[i+1]];
		res = min(res,temp);
	}while(next_permutation(a,a+n));
	printf("%d\n",res);

	return 0;
}

Measured memory_bytes: 1152
N = gets.chomp.to_i
A = gets.chomp.split(" ").map(&:to_i)
sum = 0

for i in 0..N-1 do
    A[i] = Rational(1, A[i])
end

for i in 0..N-1 do 
    sum = sum + A[i]
end

puts sum.denominator.to_f/sum.numerator.to_f

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <utility>

using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  bool ans = false;
  if(s.size() < 4) {
    cout << "No" << endl;
    return 0;
  }
  if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int a[1000000];
int main(void)
{
    int n,i,j;
    int count=0;
    while (scanf("%d",&n) != EOF){
        for(i = 1; i <= n; i++){
            a[i]=0;
        }
        a[1]=1;
        for(i = 4; i <= n; i+=2){
            a[i]=1;
        }
        for(i = 3; i*i <= n; i++){
            if(a[i]==0){
                for(j = i; j<=n; j+=i){
                    a[j]=1;
                }
                a[i]=0;
            }
        }

        for(i = 1; i <= n; i++){
            if(a[i] == 0) count++;
        }
        printf("%d\n",count);
        count=0;
    }
    return 0;
}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int N; cin >> N;
    cout << "ABC" << N << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm, std.math;
void main() {
	for (;;) {
		auto n = readln.chomp.to!real;
		if (n == 0) break;
		auto d = readln.split.to!(real[]);
		"%.8f".writefln(sqrt(d.map!(a => (a - d.reduce!"a + b"/n).pow(2)).sum / n));
	}
}

Measured memory_bytes: 2524
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  cin >> s;
  int len = s.length();
  int count = 0;
  int max = 0;
  for(int i = 0;i<len;i++){
    if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
      count++;
    }else{
      if(max<count){
        max = count;
      }
      count = 0;
    }
  }
  if(max<count){
    max = count;
  }
  cout << max;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = []
for _ in range(N):
    S.append(input())
for i in range(N):
  S[i] = sorted(S[i])
  S[i] = ''.join(S[i])

t = {}
for i in range(N):
  if S[i] in t:
    t[S[i]] += 1
  else:
    t[S[i]] = 1
 
print(sum(t[k]*(t[k]-1)//2 for k in t))

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

int main()
{
    int n,m;
    vector<int> a(m);
    cin >> n >> m;
    rep(i,m) {
        cin >> a[i];
    }
    int sum_cost;
    sum_cost = accumulate(a.begin(), a.end(), 0);
    if (n < sum_cost) {
        cout << "-1" << endl;
    } else {
        cout << n - sum_cost << endl;
    }

    return 0;
}

Measured memory_bytes: 3756
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        String line = readLine();
        StringTokenizer st = new StringTokenizer(line, " ");
        int x = Integer.parseInt(st.nextToken());

        double X = (double)x;
        List<Double> list = new ArrayList<Double>();

        for (int i=1; i<=x; i++) {
        	for (int j=2;j<=32;j++) {
        		if (Math.pow((double)i, (double)j)>X) {
        			break;
        		}
        		list.add(Math.pow((double)i, (double)j));
        	}
        }
        double ans = Collections.max(list);
        System.out.println(String.valueOf((int)ans));

    }

    private static String readLine() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        return br.readLine();
    }
}


Measured memory_bytes: 21204
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(){
  int n;
  int l[200];
  int i,j;
  int sum=0;
  scanf("%d",&n);
  for(i=0;i<2*n;i++)scanf("%d",&l[i]);
  qsort(l,2*n,sizeof(int),compare_int);
  for(i=0;i<2*n;i=i+2){
    sum+=l[i];
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
H, W, K = map(int, input().split())

blacks = [[None] * W for _ in range(H)]
black_sums = [[0] * W for _ in range(H)]
black_col_sums = [[0] * W for _ in range(H)]

for i in range(H):
    for j, item in enumerate(input()):
        if item == "#":
            blacks[i][j] = 1
        else:
            blacks[i][j] = 0


ok_count = 0
for i in range(1<<H):
    for j in range(1<<W):
        # print(f"{i:b}, {j:b}")

        black_count = 0
        for m in range(H):
            for n in range(W):
                if (1 & i >> m and 1 & j >> n) == False:
                    continue
                black_count += blacks[m][n]
        if black_count == K:
            ok_count += 1

print(ok_count)

Measured memory_bytes: 9172
#include<iostream>
using namespace std;
#include<cstring>
#include<cstdio>
#include<cstdlib>
int cs = 0;

void merge(int source[], int temp[], int l, int mid, int r) {
	int i = l, j = mid + 1;
	int point = l;
	while (i < mid + 1 && j < r + 1) {
		if (source[i] < source[j])
			temp[point++] = source[i++],cs+=1;
		else
			temp[point++] = source[j++],cs+=1;
	}
	while (i < mid + 1) 
		temp[point++] = source[i++],cs+=1;
	while (j < r + 1) 
		temp[point++] = source[j++],cs+=1;
	for (i = l; i <= r; i++) 
		source[i] = temp[i];
}

void mergesort(int source[], int temp[], int l, int r) {
	if (l >= r) return;
	int mid = (l + r) / 2;
	mergesort(source, temp, l, mid);
	mergesort(source, temp, mid + 1, r);
	merge(source, temp, l, mid, r);
}
int a[510000];
int t[510000];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	mergesort(a,t,0,n-1);
	for(int i=0;i<n;i++){
		printf("%d",a[i]);
		if(i!=n-1)
			putchar(' ');
	}
	cout<<endl;
	cout<<cs<<endl;
}


Measured memory_bytes: 7004
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);

struct P {
    int a, b;
}

void main() {
    int n = read();
    P[] ps = new P[n];
    foreach (ref p ; ps)
        readf("%d %d\n", &p.a, &p.b);
    ps.sort!("a.b < b.b");

    long sm;
    foreach (p ; ps) {
        sm += p.a;
        if (sm > p.b) {
            writeln("No");
            return;
        }
    }
    writeln("Yes");
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
 
int inf = 1e18;
const int N = 1e5+5;
 
int mod = 1e9+7;
/*
    int ncr(int n , int r ){
    	r = min(r,n-r);
    	int res = 1 ;
    	for(int i = 1 ; i <= r ; i++ ){
    		( res *= n-i+1 )%= mod;
    		res /= i ;
    	}
    	return res ;
    }
*/
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
//int arr[N];
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
      int a,b,k;
      cin>>a>>b>>k;
      cout<<max(a-k,0LL)<<" ";
      k = max(k-a,0LL);
      cout<<max(b-k,0LL);
      
 
     }
    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<ll>>;

int main(){
  int N; cin>>N;
  string S; cin>>S;
  int L=0,R=0,l=0;
  for(auto c: S){
    if(c=='(')L++;
    else R++;
    if(L<R){
      l++;
      L++;
    }
  }
  
  rep(i,l)cout<<'(';
  cout<<S;
  rep(i,L-R)cout<<')';
  cout<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

struct stackStruct{
	long number;
	stackStruct *next;
};

class myStack{
private:
	stackStruct *head;
	bool isOperator(string str);
public:
	myStack(long number);
	void push(long number);
	void smartPush(string str);
	void pop();
	long top();
	void printStack();
};

bool myStack::isOperator(string str){
	if( str[0] == '+' || str[0] == '-' || str[0] == '*') return true;
	return false;
}

myStack::myStack(long number){
	stackStruct *newNode = new stackStruct;
	newNode->number = number;
	newNode->next = NULL;
	head = newNode;
}

void myStack::push(long number){
	stackStruct *newNode = new stackStruct;
	newNode->number = number;
	newNode->next = head;
	head = newNode;
	//cout << number << "is pushed" << endl;
}

void myStack::smartPush(string str){
	if(isOperator(str) == false){
		push(stol(str));
		return ;
	}

	long number1 = top();
	pop();
	long number2 = top();
	pop();
	if(str[0] == '+'){
		push( number2 + number1);
	}else if(str[0] == '-'){
		push( number2 - number1);
	}else if(str[0] == '*'){
		push( number2 * number1);
	}
}

void myStack::pop(){
	stackStruct *targetNode;
	targetNode = head;
	head = targetNode->next;
	delete targetNode;
}

long myStack::top(){
	return head->number;
}

void myStack::printStack(){
	stackStruct *node;
	node = head;
	while(node != NULL){
		cout << node->number << endl;
		node = node->next;
	}
}

int nextSpaceIndexOfString(string str){
	for(int i = 0; i < str.size(); i++){
		if(str[i] == ' ')return i;
	}
	return -1;
}

vector<string> commandSplitter(string str,vector<string> strVector){
	if(str.size() == 0) return strVector;
	if( nextSpaceIndexOfString(str) == -1){
		strVector.push_back(str);
		return strVector;
	}else{
		strVector.push_back(str.substr(0,nextSpaceIndexOfString(str)));
		return commandSplitter(str.substr(nextSpaceIndexOfString(str) + 1),strVector);
	}
}

void printVect(vector<string> strVector){
	for(int i = 0; i < strVector.size(); i++){
		cout<< strVector[i] << endl;
	}
}

int main()
{
	vector<string> strVect;
	myStack mySt = myStack(0);
	string str;
	getline(cin,str);
	strVect = commandSplitter(str,strVect);
	/*printVect(strVect);*/
	for(int i = 0; i < strVect.size(); i++){
		mySt.smartPush(strVect[i]);
	}
	cout<< mySt.top() << endl;
	/*mySt.printStack();*/
	return 0;
}





Measured memory_bytes: 3388
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};


int main(){
  int n; cin >> n;
  string s; cin >> s;
  for(int i = 0; i < s.size(); i++) {
    int num = s[i] - 'A';
    num += n;
    num %= 26;
    s[i] = char('A' + num);
  }

  cout << s << endl;
}


Measured memory_bytes: 256
let () =
  let s = read_line () in
  Array.init (String.length s / 2) (fun i -> i)
  |> Array.to_list
  |> List.filter (fun i ->
      String.sub s 0 i = String.sub s i i)
  |> List.fold_left max 0
  |> ( * ) 2
  |> Printf.printf "%d\n"



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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    while(true){
        int ans = mod;
        int N; cin >> N;
        if(N == 0) break;
        vector<int> A(N);
        rep(i, N) cin >> A[i];
        sort(A.begin(), A.end());
        rep(i, N-1) ans = min(ans, A[i+1]-A[i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <string>
#include <cfenv>
#include <cmath>
#include <string>
#include <algorithm>
#include <cassert>
#include <functional>
#include <deque>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using namespace std;

int main(){
  int n,k,tmp,ret;
  cin >> n >> k;
  vector<int> d(k);
  vector<int> s(n,0);
  rep(i,k){
    cin >> d[i];
    rep(j,d[i]){
       cin >> tmp;
      s[tmp-1]++;
    }
  }
  ret=0;
  rep(i,n){
    if(s[i]==0){
      ret++;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

char name[100000][16];
int time[100000];
int queue[1000001];

int main(){
	int n = 0, q = 0;
	int sq = 0, eq = 0;
	int i = 0, j = 0;
	int t = 0;
	int tt = 0;	//???????????????
	scanf("%d %d", &n, &q);
	for( i = 0; i < n; i++ ){
		scanf("%s %d", name[i], &time[i]);
		queue[eq++] = i;
	}
	for( t = 0; sq != eq; t += tt ){
		i = queue[sq++];
		if( time[i] <= q ){
			tt = time[i];
			printf("%s %d\n", name[i], t+time[i]);
			time[i] = 0;
		}else{
			time[i] -= q;
			tt = q;
			queue[eq++] = i;
		}
		sq %= 1000001;
		eq %= 1000001;
	}
	return 0;
}

Measured memory_bytes: 4112
import collections

N=int(input())

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

B_dict=collections.Counter(X)
B=sorted(B_dict.items())

cnt=0
for i in range(len(B)):
    cnt+=B[i][1]
    if cnt==N//2:
        ans1=B[i][0]
        ans2=B[i+1][0]
        break
    elif cnt>=N//2+1:
        ans1=B[i][0]
        ans2=B[i][0]
        break


for i in range(N):
    if X[i]<=ans1:
        print(ans2)
    else:
        print(ans1)



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

public class Main {
    Scanner sc;
    Main() {
        sc = new Scanner(System.in);
        case_n = 0;
    }
    public static void main(String[] args) {
        new Main().run();
    }
    int case_n;
    int n;
    boolean init() {
        case_n++;
        n = sc.nextInt(); 
        if (n == 0) return false;
        return true;
    }
    void run() {
        while (init()) {
            System.out.println("Case " + case_n + ":");
            int cur = 1;

            int[][] tile = new int[n][n];
            for (int i = 1; i <= n; i++) {
                int y, x;
                int dy, dx;
                if (i % 2 == 0) {
                    y = 0;
                    x = i-1;
                    dx = -1;
                    dy = 1;
                } else {
                    y = i-1;
                    x = 0;
                    dx = 1;
                    dy = -1;
                }
                for (int j = 0; j < i; j++) {
                    tile[y][x] = cur; cur++;
                    y+=dy; x+=dx;
                }
            }
            for (int i = n+1; i < 2*n; i++) {
                int y, x;
                int dy, dx;
                if (i % 2 == 0) {
                    y = i-n;
                    x = n-1;
                    dx = -1;
                    dy = 1;
                } else {
                    y = n-1;
                    x = i-n;
                    dx = 1;
                    dy = -1;
                }
                for (int j = 0; j < 2*n-i; j++) {
                    tile[y][x] = cur; cur++;
                    y+=dy; x+=dx;
                }
            }
            
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.printf("%3d", tile[i][j]);
                }
                System.out.println("");
            }
        }
    }
}

Measured memory_bytes: 12000
def check(n)
  return 1 if n == 2
  return 0 if n%2 == 0
  3.step(Math.sqrt(n),2) do |i|
    return 0 if n % i == 0
  end
  return 1
end

count = 0
gets.to_i.times do
  count = count + check(gets.to_i)
end
puts count



Measured memory_bytes: 6892
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n,k,cnt=0;
  cin>>n>>k;
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin>>tmp;
    if(tmp>=k) cnt++;
  }
  cout<<cnt;

}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 210

int main() {
  int N, M, C;
  int A[MAX][MAX], B[MAX];
  int count = 0;
  
  scanf("%d %d %d",&N, &M, &C);
  
  for(int i = 0; i < M; i++) scanf("%d",&B[i]);
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < M; j++) {
      scanf("%d",&A[i][j]);
    }
  }
 
  for(int i = 0; i < N; i++) {
    int sum = 0;
    for(int j = 0; j < M; j++) {
      sum += A[i][j] * B[j];
    }
    if(sum + C > 0) count++;
  }

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

Measured memory_bytes: 128
S = input()
T = input()
li = []
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            break
    else:
        li.append(S[:i].replace('?', 'a') + T + S[i+len(T):].replace('?', 'a'))
li.sort()
if len(li) == 0:
    print('UNRESTORABLE')
else:
    print(li[0])

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

int main() {
  int N;
  cin >> N;
  int flag = false;
  while(N!=0) {
    if(N%10==7) flag = true;
    N /= 10;
  }
  cout << (flag ? "Yes" : "No") << endl;
} 

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static vector<int> preorder(100), inorder(100);

static void inputOrder(vector<int>& order, int num) {
  for (int i = 0; i < num; i++) {
    cin >> order[i];
  }
}

static int current = 0, outIndex = 0;

static int next() {
  int c = preorder[current];
  current++;
  return c;
}

static int find(int c) {
  auto it = find(inorder.begin(), inorder.end(), c); 
  return distance(inorder.begin(), it);
}

static void reconstruction(int l, int r) {
  if (l >= r) {
    return;
  } 
  int c = next();
  int m = find(c);
  reconstruction(l, m);
  reconstruction(m + 1, r);

  if (outIndex != 0) {
    cout << " " << c;
  } else {
    cout << c;
  }
  outIndex++;
}

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

  inputOrder(preorder, n);
  inputOrder(inorder, n);
  reconstruction(0, n);

  cout << endl;

  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		cout<<(1000-n%1000)%1000;		
    }
    return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
//		int N = 100000;
		int N = scanner.nextInt();
		long power = 1;
		for (int i = 1; i <= N; i++) {
			power = (long) (power * i % (Math.pow(10, 9)+7));
		}
		System.out.println(power);
	}
}

Measured memory_bytes: 22100
#include <stdio.h>
int main(){
	int a, b, c, x, i = 0;
	scanf("%d%d%d", &a, &b, &c);
	
	if (c<a)
	{ }
	else if (c < b){
		if (c%a == 0)
			i++;
		for (x = a + 1; x <= c; x++)
		{
			if (c%x == 0)
			{
				i++;
			}
		}
	}
	else{
		if (c%a == 0)
			i++;
		for (x = a + 1; x <= b; x++)
		{
			if (c%x == 0)
			{
				i++;
			}
		}
	}
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 596
I = str(input())
A = int(I[0])
B = int(I[1])
C = int(I[2])
D = int(I[3])
flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            S = A
            a = b = c = '+' 
            if i == 0:
                S += B
                a = '+'
            else:
                S -= B
                a = '-'
            if j == 0:
                S += C
                b = '+'
            else:
                S -= C
                b = '-'
            if k == 0:
                S += D
                c = '+'
            else:
                S -= D
                c = '-'
            if S == 7:
                print(str(A)+a+str(B)+b+str(C)+c+str(D)+'=7')
                flag = True
                break
        if flag:
            break
    if flag:
        break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int ans10000 = -1;
  int ans5000 = -1;
  int ans1000 = -1;
  for(int i=0;i<=a;i++){
   for(int j=0;i+j<=a;j++){
    int k = a - i - j;
    int total = 10000*i + 5000*j + 1000*k;
    if(total==b){
     ans10000 = i;
     ans5000 = j;
     ans1000 = k;
    }
   }
  }
  cout << ans10000 << " " << ans5000 << " " << ans1000 << endl;
}


Measured memory_bytes: 3564
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
     ll a,b,c;
     cin>>a>>b>>c;
     ll x=c%gcd(a,b);
     if(x==0)
     cout<<"YES";
     else
     cout<<"NO";}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

vector<pii> b;
using data=tuple<int,int,int,int,int>;
map<data,pair<bool,int>> memo;

pair<bool,int> solve(int pos, int index, int lefttime, int carry, int totalDist){
	data d=make_tuple(pos, index, lefttime, carry, totalDist);
	if(memo.find(d)!=memo.end()) return memo[d];
	//cout<<pos<<" "<<index<<" "<<lefttime<<" "<<carry<<" "<<totalDist<<endl;
	if(index==b.size()) return memo[d]=make_pair(true, totalDist+pos);
	int bpos=b[index].first;
	int bhigh=b[index].second-lefttime;
	int dist=abs(pos-bpos);
	int need=dist*(carry+1);
	if(bhigh<need){
		return memo[d]=make_pair(false,index+1);	//目標を取れない
	}else{
		lefttime+=bhigh;
	}
	if(carry==2){	//3つめを持った
		return memo[d]=solve(0, index+1,lefttime+bpos*(carry+2), 0, totalDist+dist+bpos);
	}
	auto ans_next=solve(bpos, index+1, lefttime, carry+1, totalDist+dist);
	need=bpos*(carry+2);
	auto ans_home=solve(0, index+1,lefttime+need, 0, totalDist+dist+bpos);
	if(ans_home.first==false and ans_next.first==false) {
		if(ans_home.second>ans_next.second){
			return memo[d]=ans_home;
		}else{
			return memo[d]=ans_next;			
		}
	}
	if(ans_home.first==false) return memo[d]=ans_next;
	if(ans_next.first==false) return memo[d]=ans_home;
	if(ans_next.second > ans_home.second) return memo[d]=ans_home;
	else return memo[d]=ans_next;
}


int main(){
	int n;
	while(cin>>n,n){
		memo.clear();
		b.resize(n);
		for(auto&i:b)cin>>i.first>>i.second;
		auto res=solve(0,0,0,0,0);
		cout<<(res.first?"OK ":"NG ")<<res.second<<endl;
	}
	return 0;
}



Measured memory_bytes: 7436