akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    vector <string> ans;
    if(s.size() < t.size()){
        cout << "UNRESTORABLE"<<endl;
        return 0;
    }
    for(int i=0;i<=s.size()-t.size();i++){
        string tmp = s;
        for(int j=0;j<i;j++){
            if(tmp[j] == '?'){
                tmp[j] = 'a';
            }
        }
        for(int j=i+t.size();j<s.size();j++){
            if(tmp[j] == '?'){
                tmp[j] = 'a';
            }
        }
        for(int j=0;j<t.size();j++){
            if(s[j+i]!='?' && s[j+i] != t[j]){
                break;
            }
            else if(s[i+j] == '?'){
                tmp[i+j] = t[j];
            }
            if(j == t.size()-1){
                ans.push_back(tmp);
            }
        }
    }

    if(ans.empty()){
        cout << "UNRESTORABLE"<<endl;
        return 0;
    }
    else
    {
        sort(ans.begin(),ans.end());
        cout << ans[0] << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN	200005
#define MAXM	4005
#define DELTA	2000
#define LIMIT	4000
#define P	1000000007
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int a[MAXN], b[MAXN];
int cnt[MAXM][MAXM];
int key[MAXM][MAXM];
long long fac[MAXM * 2], inv[MAXM * 2];
long long power(long long x, long long y) {
	if (y == 0) return 1;
	long long tmp = power(x, y / 2);
	if (y % 2 == 0) return tmp * tmp % P;
	else return tmp * tmp % P * x % P;
}
long long getc(int x, int y) {
	return fac[x] * inv[y] % P * inv[x - y] % P;
}
int main() {
	int N = MAXM * 2 - 1;
	fac[0] = 1;
	for (int i = 1; i <= N; i++)
		fac[i] = fac[i - 1] * i % P;
	inv[N] = power(fac[N], P - 2);
	for (int i = N - 1; i >= 0; i--)
		inv[i] = inv[i + 1] * (i + 1) % P;
	int n; read(n);
	for (int i = 1; i <= n; i++) {
		read(a[i]), read(b[i]);
		key[a[i] + DELTA][b[i] + DELTA]++;
		cnt[DELTA - a[i]][DELTA - b[i]]++;
	}
	long long ans = 0;
	for (int i = 0; i <= LIMIT; i++)
	for (int j = 0; j <= LIMIT; j++) {
		ans = (ans + (long long) key[i][j] * cnt[i][j]) % P;
		cnt[i][j + 1] = (cnt[i][j + 1] + cnt[i][j]) % P;
		cnt[i + 1][j] = (cnt[i + 1][j] + cnt[i][j]) % P;
	}
	for (int i = 1; i <= n; i++)
		ans = (ans - getc(a[i] + a[i] + b[i] + b[i], a[i] + a[i])) % P;
	ans = (ans + P) % P;
	ans = ans * power(2, P - 2) % P;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 96640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, w, n;
  string S, T, U;
  cin >> h >> w >> T >> U;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (T.at(j) == '.') {
        n = 0;
        for (int k = j - 1; k < j + 2; k++) {
          if (k >= 0 && k < w) {
            if (i > 0) {
              if (S.at(k) == '#')
                n++;
            }
            if (T.at(k) == '#')
              n++;
        	if (i < h - 1) {
              if (U.at(k) == '#')
                n++;
            }
          }
        }
        cout << n;
      }
      else
        cout << '#';
    }
    
  cout << endl;
  S = T;
  T = U;
  if (i < h - 2)
    cin >> U;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
typedef long long ll;
#define PI 3.14159265
ll exponent(ll x,ll n,ll m)
{  if(n==0)
    return 1;
    if(n%2!=0)
    {
        return (x*exponent(((x%m)*(x%m))%m,(n-1)/2,m))%m;
    }
    else
    return exponent(((x%m)*(x%m))%m,n/2,m);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(NULL);
    ll n,k,s;
    cin>>n>>k>>s;
    for(int i=0;i<k;i++)
        cout<<s<<" ";
    for(int i=k;i<n;i++)
    {
        if(s==1)
            cout<<s+1<<" ";
        else
            cout<<s-1<<" ";
    }
    return 0;
}


Measured memory_bytes: 1280
n, k = map(int,input().split())
ans = [0]*100000
for i in range(n):
    a, b = map(int,input().split())
    ans[a-1] += b
#print(ans)

counter = 0

while(k > 0):
    k -= ans[counter]
    counter += 1

print(counter)
    
#1

Measured memory_bytes: 5744
import collections

S = input()
T = input()

reg = [None]*26
reg_flag = [0]*26

for i in range(len(S)):
    index = ord(S[i])-97
    if reg_flag[index] == 0:
        reg[index] = T[i]
        reg_flag[index] = 1

    if reg[index] != T[i]:
        print('No')
        exit()

reg = filter(lambda x: x != None, reg)
if collections.Counter(reg).most_common()[0][1] > 1:
    print('No')
else:
    print('Yes')

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

int main() {
  char ch;
  vector<int> strnum(26, 0);
  while (scanf("%c", &ch) != EOF) {
    int num;
    if ('a' <= ch && ch <= 'z')
      num = ch - 'a';
    else if ('A' <= ch && ch <= 'Z')
      num = ch - 'A';
    else
      continue;
    strnum.at(num)++;
  }
  for (size_t i = 0; i < strnum.size(); i++) {
    cout << (char)(i + 97) << " : " << strnum.at(i) << endl;
  }
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
template <typename T>
inline T  read()
{
    char c=getchar();
    T x=0,f=1;
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*f;
}
template <typename T>
inline void write(T x) 
{
    if(x < 0) x = (~x) + 1, putchar('-');
    if(x / 10) write(x / 10);
    putchar(x % 10 | 48);
}
const int INF = 0x3f3f3f3f;
int main()
{
    int n = read<int>() , r = read<int>();
    if(n < 10) r += 100*(10-n);
    write(r);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
using namespace std;
#define MAXSIZE 1e5
#define MAXL 100
typedef long long int lli;

int main(){
    int a[5], ans = 0, minrest = 10, add_later = 400;
    for(int i = 0; i < 5; ++i){
        cin >> a[i];
        //ans += (a[i] % 10 == 0)? a[i] : (i < 4)? 10 * (a[i] / 10 + 1) : a[i];
        if(a[i] % 10 == 0){
            ans += a[i];
            a[i] = 0;
        }else{
            if(a[i] % 10 < minrest){
                add_later = i;
                minrest = a[i] % 10;
            }
        }
    }

    for(int i = 0; i < 5; ++i){
        if(i == add_later){
            ans += a[i];
        }else if(a[i] != 0){
            ans += (a[i] / 10 + 1) * 10;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define o cout<<"Hello did you expect this?"<<endl;
#define ll long long
#define pb push_back
#define mp make_pair//with Z
#define F first
#define S second

using namespace std;

const int N = 2e5 + 100;
const int mod = 1e9 + 7;

void hey ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int was[N];
int main ()
{
	hey();
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; i++)
	{
		int d;
		cin >> d;
		for (int i = 1; i <= d; i++)
		{
			int x;
			cin >> x;
			was[x] = 1;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (!was[i])
		{
			ans++;
		}
	}
	cout << ans;
}




Measured memory_bytes: 3644
import heapq
import numpy as np 

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

ab_list = []
for _ in range(N):
    a,b = map(int,input().split())
    ab_list.append([a,b])
ab_list = np.array(ab_list)
ab_list = ab_list[np.argsort(ab_list[:,0])]

ans = 0
h = []
# heapq.heapify(h)
flag = 0
for i in range(1,M+1):
    while flag<N:
        a = ab_list[flag][0]
        if a >i:
            break
        else: # 終了日までに報酬がももらえる
            b = ab_list[flag][1]
            heapq.heappush(h,-1 * b)
            flag+=1
    if len(h) > 0:
        ans += -1 * heapq.heappop(h)
print(ans)


Measured memory_bytes: 30048
N = int(input())
S = []

for i in range(N):
    tmp = input()
    S.append(tmp)
S.sort()
if N == 1:
    print(S[0])
    exit()
ans = []
SS = []
count = 1

for i in range(N-1):
    if i == N-2:
        if S[i] == S[i+1]:
            count += 1
            ans.append(count)
            SS.append(S[i])
        else:
            ans.append(count)
            SS.append(S[i])
            ans.append(1)
            SS.append(S[i+1])
    elif S[i] == S[i+1]:
        count += 1
    else:
        ans.append(count)
        SS.append(S[i])
        count = 1

m = max(ans)

for i in range(len(SS)):
    if ans[i] == m:
        print(SS[i])

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   long f(long b, long n) {
      long res = 0;
      while( n != 0 ) {
         res += n % b;
         n /= b;
      }
      return res;
   }
   void solve() {
      std::string str; scan(str);
      long res = 0;
      for(long i = 0; i < (long)str.size(); ++i) {
         if( i % 2 == 0 ) {
            if( str[i] == 'p' ) res -= 1;
         }
         else {
            if( str[i] == 'g' ) res += 1;
         }
      }
      printf("%ld\n", res);
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}



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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

    cout << c - min(a - b, c) << "\n";

    return 0;
}


Measured memory_bytes: 3632
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

N = I()
X = LI()
p = round(sum(X)/N)
ans = 0
for x in X:
    ans += (x-p)*(x-p)
print(ans)

Measured memory_bytes: 63340
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5; 
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}

ll raise(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}


int n,a, mi, ans=0;

void solve()
{
    cin >> n; 
    mi=1e6;
    for (int i=0; i<n; ++i) {
        cin >> a;
        if (a<mi) {
            ans++; mi=a;
        }
    }nout(ans);
}

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

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

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

    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - 1 - i]) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

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

    int score[2] = {0};
    for (int q = 0; q < N; ++q) {
        string S[2];
        for (int i = 0; i < 2; ++i) {
            cin >> S[i];
        }

        if (S[0] > S[1]) {
            score[0] += 3;
        } else if (S[0] == S[1]) {
            score[0]++;
            score[1]++;
        } else {
            score[1] += 3;
        }
    }

    cout << score[0] << " " << score[1] << endl;
    return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
using namespace std;

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

    int n,h[(int)1e5+5],dp[(int)1e5+5];
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
        dp[i]=2e9;
    }

    dp[0]=0;

    for(int i = 0; i < n-1; i++) {
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }

    cout << dp[n-1];
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	long int ans=0;
	ans += b;
	if (a + b >= c)
		ans += c;
	else
		ans += a + b + 1;

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	static int[] boo = new int[100000];
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] st = br.readLine().split(" ");
		//boolean[] boo = new boolean[100000];
		
		for (int i = 0; i < n; i++) {
			boo[Integer.parseInt(st[i])%100000] = 1;
		}
		
		int ans = 0;
		n = Integer.parseInt(br.readLine());
		st = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			ans += boo[Integer.parseInt(st[i])%100000] ;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 45632
#include<iostream>
using namespace std;
string s,t;int cnt;
main()
{
	cin>>s;
	for(int i=s.size();i--;)
	{
		if(s[i]=='B')cnt++;
		else
		{
			if(cnt)cnt--;
			else t=s[i]+t;
		}
	}
	cout<<t;
}


Measured memory_bytes: 256
program ABC057C
    implicit none
    integer(8)::N,N_sqrt,i,result1,result2
    integer(8)::digit1=0
    integer(8)::digit2=0
    read(5,*)N
    N_sqrt=int(sqrt(real(N)))
    do i=1,N_sqrt
        if(mod(N,i)==0)then
            result1=i
            result2=N/i
        end if
    end do

    do
        result1=result1/10
        digit1=digit1+1
        if(result1<=0)then
            exit
        end if
    end do

    do
        result2=result2/10
        digit2=digit2+1
        if(result2<=0)then
            exit
        end if
    end do

    print'(i0)',max(digit1,digit2)
end program ABC057C

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 5050;

int n, odd, da[N], db[N], za, zb;
string a,b;

int get(const vi &p, int i) { return i < 0 ? -1 : i < si(p) ? p[i] : n-1; }

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

    cin >> n >> a >> b;
    odd = a[0] != b[0];
    vi pa,pb;
    forn(i,n-1) if (a[i] == a[i+1]) pa.pb(i);
    forn(i,n-1) if (b[i] == b[i+1]) pb.pb(i);
    if (si(pa) < si(pb)) swap(pa,pb);

    int ans = 1e9;
    for (int left = -n; left <= n; left++) if ((odd + left)%2 == 0) {
        int cand = 0;
        for (int i = -n; i < 2*n; i++) {
            int pi = get(pa,i), pj = get(pb,i+left);
            cand += abs(pi-pj);
        }
        ans = min(ans, cand);
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int N, M, X, Y;
vector<int>x, y;

int check[300];

int CONST = 150;

int main(void) {

	cin >> N >> M >> X >> Y;
	int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp; x.push_back(tmp);
	}
	for (int j = 1; j <= M; j++) {
		cin >> tmp; y.push_back(tmp);
	}

	sort(x.begin(), x.end() );
	sort(y.begin(), y.end());

	for (int i = x[N - 1] + 1; i <= y[0]; i++) {
		check[i + CONST] = 1;
	}

	bool ans=false;

	for (int i = X + 1; i <= Y; i++) {
		if (check[i + CONST] == 1) { ans = true; }
	}

	if (ans) { cout << "No War" << endl; }
	else { cout << "War" << endl; }

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
h = int(input())
w = int(input())
n = int(input())

if h < w:
    if n % w == 0:
        print(n // w)
    else:
        print(n // w + 1)
else:
    if n % h == 0: 
        print(n // h)
    else:
        print(n // h + 1)

Measured memory_bytes: 3060
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: u32 = itr.next().unwrap().parse().unwrap();
    let b: u32 = itr.next().unwrap().parse().unwrap();
    let mut x = 0u32;
    let mut y = 0u32;
    let mut z = 0u32;
    for _ in 0..n {
        let p: u32 = itr.next().unwrap().parse().unwrap();
        if p <= a {
            x += 1;
        } else if p <= b {
            y += 1;
        } else {
            z += 1;
        }
    }
    println!("{}", std::cmp::min(x, std::cmp::min(y, z)));
}

Measured memory_bytes: 4352
#![allow(non_snake_case)]

use std::io::stdin;

pub fn main() {
    let stdin = stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();

    let N: i32 = buf.trim_right().parse().unwrap();

    let mut ok = false;
    'a: for x in 0..100 {
        for y in 0..100 {
            if N == 7 * x + 4 * y {
                ok = true;
                break 'a;
            }
        }
    }

    if ok {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>

#define NMax 10000
#define NMin 1



int main(){
  int i,j,n,Num[NMax],cnt=0;

  scanf("%d",&n);

  if(n>=NMin && n<=NMax)
    for(i=0; i<n; i++){
      scanf("%d",&Num[i]);
      if(Num[i]%2 == 0 && Num[i]!= 2) cnt++;
      else if(Num[i] == 2) continue;
      else if(Num[i]%2 != 0)
	for(j=3; j<=sqrt(Num[i]); j+=2){
	  if(Num[i]%j == 0){
	    cnt++;
	    break;
	  }
	}
    }

  printf("%d\n",n-cnt);

  return 0;
}


 

  

  



Measured memory_bytes: 2056
# -*- coding:utf-8 -*-
"""

(例)
T0 = 2
T1 = 3

最小公倍数が答え。
よって6。
"""
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a,b)

def solve():
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))
    ans = reduce(lcm, T)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 5076
//0017 Caesar Chipher

//es²ÆÉAAt@xbgAXy[XAsIhAüsªÜÜêéÅå80¶Ì¶ñª^¦çêé
//µ½ÃÉÍAthe,this,thatÌ¢¸ê©ªK¸ÜÜêé
//EOFªüÍ³êéÜÅAµ½¶ñðoÍ¹æ

#include<iostream>
#include<string>
#include<cctype>
using namespace std;

int main(void)
{
	string str;
	//óàÜÞêsð¾é½ßÉgetline()AÈºcin.getline(str)ªÅ«È¢ñ¾
	while( getline(cin, str) )
	{
		int i;
		int s = str.size();
		const string::size_type N = string::npos;
		while( str.find("the")==N && str.find("this")==N && str.find("that")==N )
		{
			for(i = 0; i < s; i++)
			{
				if(isalpha(str[i]))
				{
					str[i] = (str[i]-'a'+1)%26+'a';
				}
			}
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    char ch[n + 1];
    for(int i = 0; i < n; i++)
    {
        cin >> ch[i];
    }
    int left_cnt = 0;
    int right_cnt = 0;
    if(ch[0] == '>' && ch[n -1] == '<')
    {
        cout << n << endl;
        return 0;
    }
    for(int i = 0; i < n; i++)
    {
        if(ch[i] == '<')
            left_cnt++;
        else
            break;
    }
    for(int i = n - 1; i >= 0; i--)
    {
        if(ch[i] == '>')
            right_cnt++;
        else
            break;
    }
    cout << n - min(left_cnt, right_cnt) << endl;
    return 0;
}


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

#define MAX 100000

int ans[MAX];

void func()
{
    int l = sqrt(MAX) + 1;
    for (int x = 1; x <= l; x++)
    {
        for (int y = 1; y <= l; y++)
        {
            for (int z = 1; z <= l; z++)
            {
                int v = x * x + y * y + z * z + x * y + y * z + z * x;
                if (v < MAX)
                {
                    ans[v] += 1;
                }
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;
    func();
    for (int i = 1; i <= n; i++)
        cout << ans[i] << endl;
}


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

s = []

for i in range(N):
    s.append(list(input().split()))
    
X = input()

ans = 0

for i in range(N):
    if s[i][0] == X:
        for i in range(i+1,N):
            ans += int(s[i][1])
        break

print(ans)


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

#define IS_DEBUG true

#define DEBUG_OUTPUT(X) if (IS_DEBUG) cout << X << endl
#define RESULT_OUTPUT(X) cout << X << endl

void sortIncrease(vector<int> &array);
void sortDecrease(vector<int> &array);

int main()
{
	string s;
	cin >> s;
	RESULT_OUTPUT(count(s.begin(), s.end(), '1'));


	if (IS_DEBUG)
	{
		int end;
		cin >> end;
	}
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)
//Map<String, Integer> map = new HashMap<String, Integer>(n);
//ArrayList<String> cc = new ArrayList<>(n);

public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	//static String eikomoji[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
	
	
	public static void main(String[] args) {
	int n=sc.nextInt();
	int k=sc.nextInt();
	Map<Integer, Integer> map = new HashMap<Integer, Integer>(n);
	boolean a=true;
	double p[]=new double[n];
	double tmp ;
	for(int i=0;i<n&&a;i++) {
		tmp= sc.nextInt();
		p[i]=(tmp+1)/2;
		//p("pi..."+p[i]);
	}
	double f1=0;
	for(int i=0;i<k;i++) {
		f1+=p[i];
	//	p("f1"+f1);
}
	double max=f1;
	double f=f1;
	for(int i=0;i+k<=n-1;i++) {
		f=f-p[i]+p[k+i];
		//p("f..."+max);
		if(max<f) {
			max=f;
			//p("max"+max);	
		}
	}


	System.out.println(max);
	
	
	
 }
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    string s;
    cin >> s;
    map<char, int> sm;
    for (char c : s) sm[c]++;
    bool ans = true;
    for (auto i : sm) {
        if (i.second != 2) ans = false;
    }
    cout << (ans?YES:NO) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int x,y;
	for(;; x=1,y=1){
		scanf("%d %d",&x,&y);
		if((x == 0) && (y ==0)) break;
		if(x<y){
			printf("%d %d\n",x,y);
		}else if(x>y){
			printf("%d %d\n",y,x);
		}else{
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	int n;cin>>n;
    vector<vector<int>> dp(n+10,vector<int>(3,0));
    rep(i,1,n+1){
        int a,b,c;cin>>a>>b>>c;
        dp[i][0] = max(dp[i-1][1]+a,dp[i-1][2]+a); 
        dp[i][1] = max(dp[i-1][0]+b,dp[i-1][2]+b); 
        dp[i][2] = max(dp[i-1][0]+c,dp[i-1][1]+c); 
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
}

Measured memory_bytes: 11892
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min((c+a-1)/a,(c+b-1)/b)<<endl;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
if a < c:
  if b < c:
    print(0)
  elif d > b:
    print(b-c)
  else:
    print(d-c)
else:
  if a > d:
    print(0)
  elif b > d:
    print(d-a)
  else:
    print(b-a)

Measured memory_bytes: 8956
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int n; cin >> n;

  num = n * (n + 1) / 2;

  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#pragma warning(disable: 4996)
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, A, x, y;
	cin >> N;
	vector<vector<int> > testament(N, vector<int>(N, -1));
	//-1 = 証言なし
	for (int i = 0; i < N; ++i) {
		cin >> A;
		for (int j = 0; j < A; ++j) {
			cin >> x >> y;
			--x;
			if (y == 1) testament[i][x] = 1; //1 = 正直者
			else if (y == 0) testament[i][x] = 0; //0 = 不親切
		}
	}
	int max_cnt = 0;
	for (int bit = 0; bit < (1 << N); ++bit) {
		vector<int> torf(N, 0);
		for (int i = 0; i < N; ++i) {
			if (bit & (1 << i)) { 
				torf[i] = 1;
			}
		}
		//正直者に証言させ矛盾をさがす
		bool ok = true;
		int cnt = 0;
		for (int i = 0; i < N; ++i) {
			if (bit & (1 << i)) {
				for (int j = 0; j < N; ++j) {
					if (testament[i][j] == 0 && torf[j] == 1)
						ok = false;
					if (testament[i][j] == 1 && torf[j] == 0)
						ok = false;
				}
			}
		}

		if (ok) {
			for (int i = 0; i < N; ++i) {
				if (torf[i]) ++cnt;
			}
			max_cnt = max(max_cnt, cnt);
		}
	}
	cout << max_cnt;
	return 0;
}

Measured memory_bytes: 384
n=int(input())
c,s,f=[],[],[]
for i in range(n-1):
    C,S,F=map(int,input().split())
    c.append(C)
    s.append(S)
    f.append(F)
for i in range(n):
    t=0
    for j in range(i,n-1):
        if t<=s[j]:
            t=s[j]
        elif t%f[j]==0:
            t+=c[j]
            continue
        else:
            t=t+f[j]-(t%f[j])
        t+=c[j]
    print(t)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e9 + 15;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll  n,a,b,c;
    cin>>n>>a>>b>>c;
    vector<string> ans;
    map<string,int> cont;
    vector<string> sl;
    rep(i,0,n){
        string s;
        cin>>s;
        cont[s]++;
        sl.push_back(s);
    }
    ll f1=0,f2=0,f3=0;
    // int turn1=1,turn2=1,turn3=1;
    bool can=true;
    rep(i,0,sz(sl)){
        if(sl[i]=="AB"){
            if(f1!=0){
                if(f1==1)b--,a++;
                else b++,a--;
                if(f1==1)ans.push_back("A");
                else ans.push_back("B");
                f1=0;
            }
            else if(a>b)ans.push_back("B"),a--,b++;
            else if(a==b && i<sz(sl)-1 && sl[i+1]=="AC" && c==0)ans.push_back("A"),a++,b--;
            else if(a==b && i<sz(sl)-1 && sl[i+1]=="BC" && c==0)ans.push_back("B"),a--,b++;
            else ans.push_back("A"),b--,a++;
        }
        else if(sl[i]=="BC"){
            if(f2!=0){
                if(f2==1)b++,c--;
                else b--,c++;
                if(f2==1)ans.push_back("B");
                else ans.push_back("C");
                f2=0;
            }
            else if(b>c)ans.push_back("C"),b--,c++;
            else if(b==c && i<sz(sl)-1 && sl[i+1]=="AC" && a==0)ans.push_back("C"),b--,c++;
            else if(b==c && i<sz(sl)-1 && sl[i+1]=="AB" && a==0)ans.push_back("B"),c--,b++;
            else ans.push_back("B"),c--,b++;
        }
        else if(sl[i]=="AC"){
            if(f3!=0){
                if(f3==1)a++,c--;
                else c++,a--;
                if(f3==1)ans.push_back("A");
                else ans.push_back("C");
                f3=0;
            }
            else if(a>c)ans.push_back("C"),a--,c++;
            else if(a==c && i<sz(sl)-1 && sl[i+1]=="AB" && b==0)ans.push_back("A"),c--,a++;
            else if(a==c && i<sz(sl)-1 && sl[i+1]=="BC" && b==0)ans.push_back("C"),a--,c++;
            else ans.push_back("A"),c--,a++;
        }
        if(a<0 || b<0 || c<0)can=false;
    }
    if(can){
        cout<<"Yes\n";
        for(auto e: ans){
            cout<<e<<'\n';
        }
    }
    else cout<<"No\n";
    return 0;   
}

Measured memory_bytes: 12424
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<size_t N> struct solve {

	lint lun[N + 5];

	constexpr solve() : lun() {

		for (int i = 1; i <= 9; i++) lun[i] = i;

		for (int st = 1, idx = 10; idx <= N; st++) {

			bool m_ok = (lun[st] % 10 != 0);
			lun[idx*m_ok] = lun[st] * 10 + lun[st] % 10 - 1;
			idx += m_ok;

			lun[idx++] = lun[st] * 10 + lun[st] % 10;

			bool p_ok = (lun[st] % 10 != 9);
			lun[idx*p_ok] = lun[st] * 10 + lun[st] % 10 + 1;
			idx += p_ok;

		}

	}

};

solve<1000000> S;

int main() {

	int N;
	scanf("%d", &N);
	printf("%lld", S.lun[N]);

	return 0;
}


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

int main() {
	vector<int> letters(30);
	string s;
	cin >> s;
	for (auto c : s)
		++letters[c - 'A'];
	bool b = true;
	int cnt = 0;
	for (auto c : letters) {
		if (!c) continue;
		++cnt;
		if (c != 2) b = false;
	}
	if (cnt == 2 && b) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

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

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = n; i >= 1; i--){
		if (L[a[i] + 1] == 0) L[a[i]] = max(L[a[i]], 1);
		else L[a[i]] = max(L[a[i]], L[a[i] + 1] + 1);
	}
	if (L[1] == 0) return cout << -1, 0;
	cout << n - L[1];












	return 0;
}


Measured memory_bytes: 1792
main::IO()
main = do
  n <- read <$> getLine
  ss <- map ox2Bool <$> getLine
  putStrLn $ solve n ss
  
ox2Bool ::  Char ->  Bool
ox2Bool ox =  case ox of
  'o' -> True
  _ -> False

solve :: Int -> [Bool] -> [Char]
solve n ss = do
  check $ map (solve0 n (head ss) (tail ss)) (sequence [[True,False],[True,False]])  

solve0 ::Int ->Bool -> [Bool] -> [Bool] ->Maybe [Bool]
solve0 n car ls ans = case ls of
  [] -> case (head ans == last ans) && (foldr (==) True [car,(head ans),(ans !! 1),((reverse ans)!!1)]) of
    True -> Just $ reverse $ tail ans
    _ -> Nothing
  x -> solve0 (n-1) car (tail x) ((foldr (==) True [(head x),(ans !! 1),(head ans)]):ans)
  
check :: [Maybe [Bool]] -> String
check ls = case ls of
  []-> "-1"
  _-> case head ls of
    Nothing -> check $ tail ls
    Just x -> map (\ b-> case b of True -> 'S'; False ->'W') x

Measured memory_bytes: 32124
s = input()
n = int(len(s))
sub = 753

for i in range(n-2):
    test = int(s[i:i+3])
    if test <= 753:
        if 753-test <= sub:
            sub = 753 - test
        else:
            pass
    else:
        if test-753 <= sub:
            sub = test - 753
        else:
            pass

print(sub)

Measured memory_bytes: 3060
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val ab = List.fill(2)(sc.nextInt)
    sc.close()

    val c = (ab.max - ab.min) / 2
    val ac = Math.abs(ab.max - c)
    val bc = Math.abs(-c - ab.min)
    ac == bc match {
      case true => println(ac)
      case _    => println("IMPOSSIBLE")
    }
  }
}

Measured memory_bytes: 27308
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
const int INF = 1000000000;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> e(n);
    for(int i = 0;i < m;i++){
        int u,v;
        cin >> u >> v;
        u--,v--;
        e[u].push_back(v);
    }

    int s,t;
    cin >> s >> t;
    s--,t--;

    vector<vector<int>> d(n,vector<int>(3,INF));

    d[s][0] = 0;
    queue<pair<int,int>> que;
    que.push(make_pair(s,0));

    while(que.size()){
        int v,mod;
        v = que.front().first;
        mod = que.front().second;
        que.pop();

        for(int next:e[v]){
            if(d[next][(mod+1)%3] > d[v][mod] + 1){
                d[next][(mod+1)%3] = d[v][mod] + 1;
                que.push(make_pair(next,(mod+1)%3));
            }
        }
    }

    cout << (d[t][0] == INF ? -1 : d[t][0] / 3) << endl;
}


Measured memory_bytes: 14004
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n :i64 = read();
    let mut counter= 0;
    let mut ans = "No";
    for _ in 0..n {
        let a1:i64 = read();
        let a2:i64 = read();
        if a1 == a2 {
            counter+=1;
        } else {
            counter = 0;
        }
        if counter >= 3 {
            ans = "Yes";
            break;
        }
    }
    print!("{}", ans);
}


Measured memory_bytes: 2156
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int H, W;
string S[21];
int bfs(int x, int y) {
    queue<PP> que;
    que.push({0, {x, y}});
    int ret = 0;
    bool visited[21][21] = {};
    visited[x][y] = true;
    while(que.size()) {
        PP p = que.front(); que.pop();
        int d = p.first;
        int x = p.second.first;
        int y = p.second.second;
        ret = max(ret, d);
        rep(i, 4) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(xx < 0 || xx >= H || yy < 0 || yy >= W) continue;
            if(S[xx][yy] == '#') continue;
            if(visited[xx][yy]) continue;
            visited[xx][yy] = true;
            que.push({d + 1, {xx, yy}});
        }
    }
    return ret;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    
    rep(i, H) cin >> S[i];
    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            if(S[i][j] == '.') {
                ans = max(ans, bfs(i, j));
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (int n = 0; n < N; ++n) {
    std::cin >> A[n];
  }

  auto min_it = A.begin();
  while (true) {
    std::sort(min_it, A.end());
    min_it = std::lower_bound(min_it, A.end(), 1);
    auto min_a = *min_it;
    if (min_it + 1 == A.end()) {
      std::cout << min_a << std::endl;
      break;
    }
    std::for_each(min_it + 1, A.end(), [min_a](auto& a) { a = a % min_a; });
  }

  return 0;
}


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

int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		int answer = 0;

		for ( int right = 1; right < n; right++ )
		{
			for ( int left = 1; left < right; left++ )
			{
				int sum = ( right - left + 1 ) * ( left + right ) / 2;
				if ( sum == n ) answer++;
			}
		}

		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,p,q,k;
  k=1;
  cin>>n;
  vector<int> vec(n);
  vector<int> vecp(n);
  vector<int> vecq(n);
  for (int i = 0; i < n; i++){
    cin>>vecp.at(i);
  }
  for (int i = 0; i < n; i++){
    cin>>vecq.at(i);
    vec.at(i)=i+1;
  }
  do {
    for(int i=0; i<n; i++){
      if(vec.at(i)!=vecp.at(i)){
        break;
      }
      if(i==n-1){
        p=k;
        }
     }
      for(int i=0; i<n; i++){
      if(vec.at(i)!=vecq.at(i)){
        break;
      }
      if(i==n-1){
        q=k;
        }
     }
    k++;
   
  }
  while(next_permutation(vec.begin(),vec.end()) );
  cout<<abs(p-q);
}

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

int main() {
   int n, m;
   cin >> n >> m;
   int a[n];

   double sum = 0;
   rep (i, n) {
       cin >> a[i];
       sum += a[i];
   }

   int count = 0;
   rep (i, n) {
       if (a[i] >= (sum / (4 * m))) count++;
   }

   if (count >= m) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int H, W, N;
    cin >> H >> W >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    auto ans = vector<vector<int>>(H, vector<int>(W));
    pair<int, int> that;
    that.first  = 1;
    that.second = a[that.first - 1];
    REP(i, H) {
        if (i % 2 == 0) {
            REP(j, W) {
                ans[i][j] = that.first;
                that.second--;
                if (that.second == 0) {
                    that.first++;
                    that.second = a[that.first - 1];
                }
            }
        } else {
            RREP(j, W - 1) {
                ans[i][j] = that.first;
                that.second--;
                if (that.second == 0) {
                    that.first++;
                    that.second = a[that.first - 1];
                }
            }
        }
    }

    REP(i, H) {
        REP(j, W) { cout << ans[i][j] << " "; }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#define  queues      priority_queue
#define mod  1000000007
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
#define fi  first
#define se  second
#define mp  make_pair
#define  pb push_back
#define mem(a,b) memset(a,b,sizeof(a));
typedef long long unsigned ull;
typedef long long ll;
const ll maxn=2000006;
//priority_queue<ll,vector<ll >,greater<ll > >q;
const ll INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
//__builtin_popcount
//priority_queue
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}
inline char nc()
{
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline ll read()
{
    char ch=nc();
    ll sum=0;
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum;
}
bool cmp(ll a,ll b)
{
    return a>b;
}int n,m;
int dd(int a,int b)
{ int x=a/b;
    if(x<2||b<2)return 0;
    if(b*10+x<=m)return 1;
    return 0;
}
ll L[2003],R[2003];
int a[2003];
int main()
{
   int n,k;
   scanf("%d%d",&n,&k);
   for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
   ll sum=0;
   for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
        if(a[i]>a[j])R[i]++;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
    {
         if(a[i]>a[j])L[i]++;
    }
    for(int i=1;i<=n;i++)
       sum=(sum+L[i]%mod*k%mod*(k-1)%mod*kc(2,mod-2)+R[i]%mod*(k+1)%mod*k%mod*kc(2,mod-2))%mod;
    cout<<sum<<endl;
}



Measured memory_bytes: 256
#079_C
S=input()
x=[int(s) for s in S]
for i in range(2**3):
    op=[]
    res=x[0]
    for j in range(3):
        if (i>>j)&1:
            op.append('+')
            res+=x[j+1]
        else:
            op.append('-')
            res-=x[j+1]
    if res==7:
        print(S[0]+op[0]+S[1]+op[1]+S[2]+op[2]+S[3]+'=7')
        exit()

Measured memory_bytes: 3064