akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    string s;cin >> s;
    for(int i = 0; i < 3; i++) {
        if(s[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long x=scan.nextInt();
		long y=scan.nextInt();
		scan.close();

		if(x<y) {
			long tmp=y;
			y=x;
			x=tmp;
		}

		long ans =(x*y)/gcd(x,y);
		System.out.println(ans);
	}

	static long gcd(long x,long y) {
		if(x%y==0)return y;
		else return gcd(y,x%y);
	}

}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;cin>>k;
    queue<ll> que;
    repr(i,1,10) {
        que.push(i);
    }
    ll res = 1;
    while(k) {
        res = que.front();
        que.pop();
        ll x = res % 10;
        if (x) {
            que.push(res*10+x-1);
        }
        que.push(res*10+x);
        if (x<9) {
            que.push(res*10+x+1);
        }
        k--;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n;
int a[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }  
  sort(a, a + n);
  int m = -1, pos = -1;
  for (int i = 0; i < n; i++) {
    int tmp = min(a[i], a[n - 1] - a[i]);
    if (tmp > m) {
      m = tmp;
      pos = i;
    }
  }
  cout << a[n - 1] << " " << a[pos] << endl;

  return 0;
}

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

int main(){
 int N;
  cin >> N;
  
  int nums[N] = {0}; 
  for(int i = 0; i< N; i++){
    cin >> nums[i];
  }
  
  int maxlen = 0;
  int maxind = 0;
  for(int i = 0; i< N; i++){
    if (nums[i] > maxlen){
     maxlen = nums[i]; 
      maxind = i;
    }
  }
  
  int sumval = 0;
  for(int i = 0; i< N; i++){
    if (i == maxind) continue;
  	sumval += nums[i];
  }
  //cout << maxlen << ", "<< sumval<< endl;
  if (maxlen < sumval) cout << "Yes" << endl;
  else cout<<"No"<< endl;

}

Measured memory_bytes: 384
// UNNECESSARY
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
// #include <cstdio>//printf/scanf/fopen/fclose/fprintf/fscanf/snprintf/putc/puts/getc/gets
// #include <fstream>//ifstream/ofstream

// DATA STRUCTURES
#include <array>
#include <bitset>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>

// MISCELLANEOUS
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <cassert>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <new>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <utility>//pair

#ifndef REP
#define REP(i,n) for (int i = 0; i < n; ++i)
#endif

#ifndef REPST
#define REPST(i,n) for (size_t i = 0; i < n; ++i)
#endif

#ifndef READ
#define READ(x) std::cin >> x
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> plli;
typedef std::pair<ull, int> puli;
typedef std::pair<double, int> pdi;
typedef std::pair<ll, ll> pllll;
typedef std::pair<ull, ull> pulul;
typedef std::pair<double, double> pdd;
typedef std::tuple<int, int, int> ti3;
typedef std::tuple<int, int, int, int> ti4;

const bool debug = true;

// --------------------------------------------------------------------------------------

using namespace std;

int main(void)
{
    int n, a, b;
    cin >> n >> a >> b;
    // each player can fight or run
    // fight fight -> mid = (a + b) / 2
    div_t mid;
    mid = div(a + b, 2);
    string s = "";
    if (mid.rem) {
        // mid isn't an integer -> a = mid - 0.5; b = mid + 0.5;
        // int a_fight = mid;
        // int b_fight = mid + 1;
        // a's turn
        // a can only move left, b chases, a loses and b wins
        // therefore a tries to run
        // int a_run = 1;
        // int b_chase = b - (a - 1);
        // if b_chase is at 3 + 2*k, after k cycles of a back-and-forth, we reach stalemate
        s = ((b - (a - 1)) % 2) ? "Draw" : "Borys";
    } else {
        // mid is an integer -> a = mid; b = mid + 1;
        // int a_fight = mid;
        // int b_fight = mid + 1;
        // b's turn
        // b can only move right, a chases, b loses and a wins
        // therefore b tries to run
        // int b_run = n;
        // int a_chase = a + (n - b);
        // if (n - a_chase) is at 3 + 2*k, after k cycles of b back-and-forth, we reach stalemate
        s = ((b - a) % 2) ? "Draw" : "Alice";
    }
    cout << s << endl;
    return 0;
}


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

int main(){

  int w,h,a[100][100],n,x,y;

  while(cin >> w >> h, w, h){

    for(int i=0;i<=w;i++){
      for(int j=0;j<=h;j++) a[i][j] = 0;
    }

    a[0][1] = 1;
    cin >> n;

    for(int i=0;i<n;i++){
      cin >> x >> y;
      a[x][y] = -1;
    }

    for(int i=1;i<=w;i++){
      for(int j=1;j<=h;j++){

	if(a[i][j] != -1){

	  if(a[i-1][j] == -1) a[i][j] = a[i][j-1];
	  else if(a[i][j-1] == -1) a[i][j] = a[i-1][j];
	  else a[i][j] = a[i-1][j] + a[i][j-1];
	}

      }
    }

    cout << a[w][h] << endl;

  }

}

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

int main(void){
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  
  vector<int>a(N+1,0);
  vector<int>b(M+1,0);
  
  a[0] = X;
  b[0] = Y;
  
  for(int i=1;i<N+1;i++){
    cin >> a[i];
  }
  for(int i=1;i<M+1;i++){
    cin >> b[i];
  }
  
  int amax = -999;
  int bmin = 999;
  
  for(int i=0;i<N+1;i++){
    if(amax < a[i])
      amax = a[i];
  }
  for(int i=0;i<M+1;i++){
    if(bmin > b[i])
      bmin = b[i];
  }
  
  if(amax < bmin)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
  
  return 0;
}
  

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC131C
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            var a = input[0];
            var b = input[1];
            var c = input[2];
            var d = input[3];

            var all = b - a + 1;

            var c1 = (a - 1) / c;
            var c2 = b / c;
            var c3 = c2 - c1;

            var d1 = (a - 1) / d;
            var d2 = b / d;
            var d3 = d2 - d1;

            var cd = Lcm(c, d);

            var cd1 = (a - 1) / cd;
            var cd2 = b / cd;
            var cd3 = cd2 - cd1;

            Console.WriteLine(all - (c3 + d3 - cd3));
        }

        static long Lcm(long a, long b)
        {
            return (a * b) / Gcd(a, b);
        }

        static long Gcd(long a, long b)
        {
            if (a == 0)
            {
                return b;
            }
            if (b == 0)
            {
                return a;
            }

            if (a > b)
            {
                a %= b;
                return Gcd(a, b);
            }
            else
            {
                b %= a;
                return Gcd(b, a);
            }
        }
    }
}


Measured memory_bytes: 13268
import sys
import numpy as np
TYPE_NUM = 26
WEIGHT = 30

def resolve():

    inp = sys.stdin.readlines()
    D = int(inp[0])
    c = np.array(list(map(int, inp[1].split(' '))))
    s = []
    last = np.zeros(TYPE_NUM, dtype=int)
    types = []

    for i in range(2, len(inp)):
        s.append(list(map(int, inp[i].split(' '))))
    s = np.array(s, dtype=int)

    for d in range(D):
        temp_delta_satis = np.zeros([TYPE_NUM, TYPE_NUM], dtype=int)
        for idx in range(TYPE_NUM):
            val = s[d, idx]
            org = last[idx]
            last[idx] = d+1
            temp_delta_satis[:, idx] = (np.sum(-c*(d+1-last)) + val)*WEIGHT
            if D != d+1:
                for idx2 in range(TYPE_NUM):
                    val2 = s[d+1, idx2]
                    org2 = last[idx2]
                    last[idx2] = d+2
                    temp_delta_satis[idx2, idx] += np.sum(-c*(d+2-last)) + val2
                    last[idx2] = org2
            last[idx] = org
        opt_idx = np.unravel_index(np.argmax(temp_delta_satis), temp_delta_satis.shape)[1]
        types.append(opt_idx+1)
    print(*types, sep='\n')

resolve()


Measured memory_bytes: 27372
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>

//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
map<LL, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, s, t, ans, cnt, sum, a[210000], dp[110000][2];
string str;
bool f[110000];
char c;

int main() {
	cin >> str;
	n = str.size();
	dp[0][1] = 1;
	rep(i, n) {
		if (str[i] == '1') {
			dp[i + 1][1] = 2 * dp[i][1];
			dp[i + 1][0] = dp[i][1] + dp[i][0] * 3;
		}
		else {
			dp[i + 1][1] = dp[i][1] ;
			dp[i + 1][0] = dp[i][0] * 3;
			
		}
		dp[i + 1][1] %= MOD;
		dp[i + 1][0] %= MOD;
	}
	cout << (dp[n][0] + dp[n][1])%MOD << endl;
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
int main()
{
    ll n, t, x, i, j ;
    string s ;
    cin >> s ;
    x=0;
    for(i=0; i<s.size(); i++)
    {
        x=(x+(s[i]-'0'))%9;
    }
    if(x==0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 3704
from bisect import bisect_left
from time import time
t0 = time()
def xorshift(seed=123456789):  # 31 bit xorshift
    y = seed
    def randint():
        nonlocal y
        y ^= (y & 0xffffff) << 7
        y ^= y >> 12
        return y# % (b-a+1) + a
    return randint
randint = xorshift()
D = int(input())
C = list(map(int, input().split()))  # 低下
S = [list(map(int, input().split())) for _ in range(D)]
Last = [-1] * 26
def calc_pena(day):
    res = 0
    for l, c in zip(Last, C):
        res += (day-l)*c
    return res
T2 = [[-1] for _ in range(26)]

def change(day, contest):
    diff = 0
    contest_old = T[day]
    T[day] = contest
    idx = bisect_left(T2[contest_old], day)
    #assert day in T2[contest_old]
    diff -= C[contest_old] * (T2[contest_old][idx+1] - day) * (day - T2[contest_old][idx-1])
    del T2[contest_old][idx]
    idx = bisect_left(T2[contest], day)
    diff += C[contest] * (T2[contest][idx] - day) * (day - T2[contest][idx-1])
    T2[contest].insert(idx, day)
    diff += S[day][contest] - S[day][contest_old]
    return diff

T = []
ans = 0
for day, s in enumerate(S):
    best_gain = -999999
    best_gain_contest = None
    pena = 0
    for cont, (l, c, s_) in enumerate(zip(Last, C, s)):
        p = (day-l)*c
        pena += p
        if best_gain < s_ + p:
            best_gain = s_ + p
            best_gain_contest = cont
    T.append(best_gain_contest)
    Last[best_gain_contest] = day
    ans += best_gain - pena
# print(T)
# print(ans)
# ans = 0
# Last = [-1] * 26
# for i, (s, t) in enumerate(zip(S, T)):
#     Last[t] = i
#     ans += s[t]
#     ans -= calc_pena(i)
#     T2[t].append(i)
for i, t in enumerate(T):
    T2[t].append(i)
for i in range(26):
    T2[i].append(D)  # 番兵


while time()-t0 < 1.9:
    r = randint()
    day = r % D
    r //= D
    contest = r % 26
    contest_old = T[day]
    ch = change(day, contest)
    if ch >= 0:
        ans += ch
        #print(ans, time()-t0)
    else:
        change(day, contest_old)

print("\n".join(str(a+1) for a in T))


Measured memory_bytes: 73240
#! /usr/bin/perl

use strict;
use warnings;

my $n = <>;
my $buf = <>;
my @numbers = split(/\s+/, $buf);

my $count = 0;
loop:
while(1) {
    foreach my $i (0 .. $n - 1) {
        if($numbers[$i] % 2 != 0) {
            last loop;
        }
        $numbers[$i] /= 2;
    }
    $count ++;
}
print $count, "\n";


Measured memory_bytes: 640
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define PRINT
#define LCERR
#endif

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

namespace {

using namespace std;

class Solution {
public:

private:

};

int solve() {
    Solution solution;
    // handle IO here
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


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

int N;
int r[105];
int s[105], p[105], c[105];
int inits, initp, initc;

void initialize() {
    s[1] = inits;
    p[1] = initp;
    c[1] = initc;
}

bool clear() {
    //cerr << s[1] << " " << p[1] << " " << c[1] << endl;
    vector<int> score(N + 1);
    vector<int> ss(N), ps(N), cs(N);
    for(int i = 1; i <= N; i++) {
        ss[i-1] = -s[i];
        ps[i-1] = -p[i];
        cs[i-1] = -c[i];
    }
    sort(ss.begin(), ss.end());
    sort(cs.begin(), cs.end());
    sort(ps.begin(), ps.end());
    for(int i = 1; i <= N; i++) {
        auto itr = lower_bound(ss.begin(), ss.end(), -s[i]);
        int rank = distance(ss.begin(), itr) + 1;
        score[i] -= r[rank];
        //cerr << "s rank " << rank << endl;
        itr = lower_bound(cs.begin(), cs.end(), -c[i]) + 1;
        rank = distance(cs.begin(), itr);
        score[i] -= r[rank];
        itr = lower_bound(ps.begin(), ps.end(), -p[i]) + 1;
        rank = distance(ps.begin(), itr);
        score[i] -= r[rank];
   }
   int myscore = score[1];
   sort(score.begin(), score.end());
   auto itr = lower_bound(score.begin(), score.end(), myscore);
   if (distance(score.begin(), itr) <= 7) return true;
   else return false;
}

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> r[i];
    for(int i = 1; i <= N; i++) cin >> s[i] >> p[i] >> c[i];
    inits = s[1];
    initp = p[1];
    initc = c[1];
    int ans = 1e9;
        while(!clear()) {
            //cerr << "CALLING S" << endl;
            if(s[1] > 100) break;
            s[1]++;
        }
        if(s[1] <= 100) ans = min(ans, s[1] - inits);
        initialize();
        while(!clear()) {
            //cerr << "CALLING C" << endl;
            if(c[1] > 100) break;
            c[1]++;
        }
        if(c[1] <= 100) ans = min(ans, c[1] - initc);
        initialize();
        while(!clear()) {
            //cerr << "CALLING P" << endl;
            if(p[1] > 100) break;
            p[1]++;
        }
        if(p[1] <= 100) ans = min(ans, p[1] - initp);
        initialize();
    if(ans == 1e9) {
        cout << "Saiko" << endl;
        return 0;
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int dis[200][200];
	fill((int*)dis, (int*)dis+(200*200) , INF);
	int N,M,R;
	cin >> N >> M >> R;
	vector<int>root(R);
	rep(i, R) {
		cin >> root[i];
		root[i]--;
	}
	int ans = INF;
	sort(root.begin(), root.end());
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		cin >> dis[a][b];
		dis[b][a] = dis[a][b];
	}
	rep(k, N) {
		rep(j, N) {
			rep(i, N)if (dis[i][k] + dis[k][j] < dis[i][j])dis[i][j] = dis[i][k] + dis[k][j];
		}
	}
	do {
		int d = 0;
		rep(i, R - 1) {
			d += dis[root[i]][root[i + 1]];
		}
		ans = min(d, ans);
	}while(next_permutation(root.begin(), root.end()));
	cout << ans << endl;
	return 0;
}

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

int main() {
ll k;
cin >> k;
vector<ll> lllist(k);
ll x=0;ll count=0; int ketasu=1;

queue<ll> que;
rep(i,9)
{que.push(i+1);}
int i=0;
while (lllist.at(k-1)==0)
{ ll x=que.front();
  que.pop();
  lllist.at(i)=x;
  i++;
  if(x%10==9)//末尾が9だったら
  {que.push(x*10+8);
   que.push(x*10+9);}
  else if(x%10==0)//末尾が0だったら
  {que.push(x*10+0);
   que.push(x*10+1);}
  else//それ以外だったら
  {int matsubi=x%10;
   que.push(x*10+matsubi-1);
   que.push(x*10+matsubi);
   que.push(x*10+matsubi+1); 
  }
  
}


cout << lllist.at(k-1)<<endl;

return 0;
}


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

int main() {
	int  n;
	cin >> n;
	set<int> se;
	for(int i;i<n;i++){
		int b;
		cin >> b;
		se.insert(b);
	}
	cout<<se.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n = int(input())
    h = input_list()
    count = 0
    while list(set(h)) != [0]:
        count += 1
        flag = False
        for i, v in enumerate(h):
            if v != 0:
                flag = True
                h[i] -= 1
            else:
                if flag:
                    break
    print(count)

def divide_two(n):
    c = 0
    while True:
        if c >= 2:
            break
        if n % 2 != 0:
            break
        n //= 2
        c += 1
    return c

def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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


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


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()


Measured memory_bytes: 64876
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back
// const ll mod = 1000000007;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void sayNo() {
	cout << "NO" << endl;
}

void sayYes() {
	cout << "YES" << endl;
}


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

	int count = 0;
	for (int i = 1; i <= N; i++) {
		int p; cin >> p;

		if (p != i) {
			count++;
		}
	}

	if (count <= 2) {
		sayYes();
	}
	else {
		sayNo();
	}

	return 0;
}

Measured memory_bytes: 256
def solve():
  n = int(input())
  mod = 10**9+7
  dp = [[[[0 for i in range(4)]for j in range(4)]for k in range(4)]for t in range(105)]
  dp[0][2][2][2] = 1
  
  for i in range(n):
    for c1 in range(4):
      for c2 in range(4):
        for c3 in range(4):
          for a4 in range(4):
            if [c2,c3,a4] == [0,1,2] or [c2,c3,a4] == [0,2,1] or [c2,c3,a4] == [1,0,2] or [c1,c2,a4] == [0,1,2] or [c1,c3,a4] == [0,1,2]:
              continue
            else:
              dp[i+1][c2][c3][a4] += dp[i][c1][c2][c3]
              dp[i+1][c2][c3][a4] %= mod
  ans = 0
  for c1 in range(4):
    for c2 in range(4):
      for c3 in range(4):
        ans += dp[n][c1][c2][c3]
        ans %= mod
  print(ans)
solve()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vint a(n);
  rep(i,n) cin >> a[i];
  int ans = 1;
  rep(i,n){
    if(a[i] % 2 == 0) ans *= 2;
  }
  cout << pow(3,n) - ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;

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

    int64_t N, ans = 0;
    cin >> N;
    //vector<int> A(N);
    //for(int i=0; i<N; i++){cin>>A[i];}
    //vector<vector<int>> A(N,vector<int>(M));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            for (int k = 1; k <= N; k++) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    //sort(A.begin(),A.end());
    //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
    //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, C; cin >> n >> C;
    vector<vi> D(C, vi(C)); rep(i, C) rep(j, C) cin >> D[i][j];
    vector<vi> f(n, vi(n)); rep(i, n) rep(j, n) cin >> f[i][j], f[i][j]--;

    vector<vi> hist(3, vi(C));
    rep(i, n){
        rep(j, n){
            int k = (i + j) % 3;
            int c = f[i][j];
            hist[k][c]++;
        }
    }

    int res = inf;
    rep(c1, C) rep(c2, C) rep(c3, C){
        if(c1 == c2 or c2 == c3 or c3 == c1) continue;

        vi T = {c1, c2, c3};
        int cur = 0;
        rep(k, 3){
            rep(c, C){
                cur += hist[k][c] * D[c][T[k]];
            }
        }
        chmin(res, cur);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int a,b,c;
	int num=2;
	int ans=0;
	
	cin>>a>>b>>c;
	if(a==b && b==c)
	{
		if(a%2==0)
		{
			cout<<-1<<endl;
		}else{
			cout<<0<<endl;
		}
		return 0;
	}
	if(a%2==1 || b%2==1 || c%2==1)
	{
		cout<<0<<endl;
		return 0;
	}
	while(a%num==0 && b%num==0 && c%num==0)
	{
		ans++;
		num*=2;
	}
	num/=2;
	a/=num;
	b/=num;
	c/=num;
	if(a%2==1 && b%2==1 && c%2==1)
		ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int64_t N, K;
  cin >> N >> K;
  int64_t number,number_before;
  
  N = N % K;
  number_before = N;
  number = N - K;
  if (number < 0){
    number *= -1LL;
  }
  N = number;
  
  while(1){
    number = N - K;
    if (number < 0){
      number *= -1LL;
    }
    if(number == number_before){
      cout << min(number,N) << endl;
      break;
    }
    number_before = N;
    N = number;
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int n;
	string temp, ans = "Three";
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		if (temp == "Y")ans = "Four";
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int x, y, z, k; cin >> x >> y >> z >> k;
  V<lint> a(x); for (auto&& e : a) cin >> e;
  V<lint> b(y); for (auto&& e : b) cin >> e;
  V<lint> c(z); for (auto&& e : c) cin >> e;
  sort(rbegin(a), rend(a));
  sort(rbegin(b), rend(b));
  sort(rbegin(c), rend(c));
  V<lint> d;
  for (int i = 0; i < x; ++i) for (int j = 0; j < y; ++j) {
    d.push_back(a[i] + b[j]);
  }
  sort(rbegin(d), rend(d));
  if ((int) d.size() > k) d.resize(k);
  V<lint> e;
  for (lint el : d) for (int i = 0; i < z; ++i) {
    e.push_back(el + c[i]);
  }
  sort(rbegin(e), rend(e));
  for (int i = 0; i < k; ++i) cout << e[i] << '\n';
}

Measured memory_bytes: 43368
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >>N;
    int d[N];
    int kaz=1;
    for (int i=0 ; i<N ; i++){
        cin >> d[i];
    }
    sort (d,d+N);
    for (int s=0 ; s<N ; s++){
        if(d[s]!=d[s+1]&&s!=N-1){
        kaz=kaz+1;}
    }
    cout << kaz << endl;
         
    
return 0;}


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

const int N = 105;
int n, dia, a[N], c[N];
bool cmp (int x, int y) {return x > y;}
int main () {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a + 1, a + 1 + n, cmp);
    dia = a[1];
    for (int i = 1; i <= n; ++i) ++c[a[i]];
    if (dia == 1 && n != 2) return puts("Impossible"), 0;
    int t = (a[1] + 1) >> 1;
    for (int i = 1; i < t; ++i) if (c[i]) return puts("Impossible"), 0;
    if ((~a[1] & 1) && c[t] != 1) return puts("Impossible"), 0;
    if ((a[1] & 1) && c[t] != 2) return puts("Impossible"), 0;
    for (int i = t + 1; i <= a[1]; ++i) if (c[i] < 2) return puts("Impossible"), 0;
    puts("Possible");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		if(n <= 9) {
			System.out.println("Yes");
			return;
		}
		for(int i = 2; i <= 9; i++) {
			if(n % i == 0 && n / i <= 9) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

}


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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define vi vector <ll>
#define hell 1000000007
#define pii pair <ll,ll>
#define inf (ll)(1e16)
#define pb push_back
#define p 31

using namespace std;

void solve()
{
    ll n,k,q;
    cin>>n>>k>>q;
    vi a(n+1,0);
    while(q--)
    {
        ll x;
        cin>>x;
        x--;
        ll l,r;
        l=0;
        r=x-1;
        if(l<=r)
        {
            a[l]--;
            a[r+1]++;
        }
        l=x+1;
        r=n-1;
        if(l<=r)
        {
            a[l]--;
            a[r+1]--;
        }
    }
    rep(i,1,n)
        a[i]+=a[i-1];
    rep(i,0,n)
    {
        if(a[i]+k<=0)
            cout<<"No\n";
        else
            cout<<"Yes\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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 long long INF = 1LL << 60;
int main()
{
    string S;
    cin >> S;

    REP(i, S.size()) cout << 'x';
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    from collections import deque
    d = deque(list(S))
    st = 0
    ad = deque()

    while(len(d)):
        t = d.pop()
        if t == ')':
            ad.appendleft(t)
            st += 1
        else:
            if(st > 0):
                st -= 1
            else:
                ad.append(')')

            ad.appendleft('(')
                    
    ad.appendleft('(' * st)
        
    print(''.join(ad))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long

int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("test.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif*/
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    
    int n;cin>>n;
    map<vector<int>,ll> m;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        vector<int> fre(26);
        for(int j=0;j<s.size();j++){
            fre[s[j] - 'a']++;
        }
        m[fre]++;
    }
    ll ans = 0;
    for(auto x:m){
        ans += x.second * (x.second - 1) / 2;
    }
    cout<<ans;


    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}

Measured memory_bytes: 19072
let calc n =
    let rec loop_i i acc =
        if i = 0 then acc else
            let acc = if n mod i = 0 then min acc (i + n / i - 2) else acc in
            loop_i (i - 1) acc
    in
    loop_i (int_of_float (sqrt (float n))) 9999999999999
;;
Scanf.sscanf (read_line ()) "%d" (fun n -> Printf.printf "%d\n" (calc n))

Measured memory_bytes: 384
N,M=map(int,input().split())
islands=[[] for _ in range(N)]
for _ in range(M):
    a,b=map(int,input().split())
    islands[a].append(b)
answer=1
for n in islands[1]:
    if N in islands[n]:
        answer=0
        print('POSSIBLE')
        break
if answer==1:
    print('IMPOSSIBLE')
    

Measured memory_bytes: 66508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    Int n; cin>>n;
    Int ans=LINF;
    Int tmp=0;
    for(Int i=1; i*i<=n; i++){
        if(n%i==0){
            Int a=to_string(i).size();
            Int b=to_string(n/i).size();
            tmp=max(a,b);
            ans=min(ans,tmp);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int n;
  double c;
  cin >> n;
  vector<double> a(n);
  vector<double> b(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i] = 1/a[i];
    c += b[i];
  }
  cout << 1/c << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int [] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		
		for (int i = a.length; i > 1; i--) {
			System.out.print(a[i-1]+" ");
		}
		System.out.println(a[0]);
	}
}



Measured memory_bytes: 26256
#include <stdio.h>
int main(){
    int c=0,i=0; 
    char s[200001],t[200001];
    scanf("%s%s",s,t);
    while(s[i]!='\0'){
        if(s[i]!=t[i])c++;
        i++;
    }
    printf("%d",c);
    return 0;
}

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, n1; cin >> n >> n1;
    bool arr[n];
    memset(arr, false, sizeof(arr));
    bool res = false;
    for(int i=0;i<n1; i++){
        int x, y; cin >> x >> y;
        if(x == 1){
            if(arr[y]) res = true;
            arr[y] = true;
        }
        else if(y == n){
            if(arr[x]) res = true;
            arr[x] = true;
        }
    }
    if(res) cout << "POSSIBLE"<< endl;
    else cout << "IMPOSSIBLE"<< endl;


    return 0;
}


Measured memory_bytes: 3852
import math

if __name__ == '__main__':
    N = int(input())
    
    A_last = N // 2
    
    for A in range(1, A_last + 1):
        B = N - A
        A_origin = A
        
        A_sum = 0
        B_sum = 0
        
        while A > 0:
            r = A % 10
            A_sum += r
            A = A // 10
        
        while B > 0:
            r = B % 10
            B_sum += r
            B = B // 10
        
        total = A_sum + B_sum
        
        if A_origin == 1:
            total_min = total
        else:
            if total < total_min:
                total_min = total
    
    print(total_min)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define pb(s) push_back(s)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }
int main() {
  ll N;
  cin >>N;
  vl vec(N-1);
  repl(i,1,N) {
    ll b=N-i;
   ll c1=i/100000;
   ll c2=i/10000-c1*10;
   ll c3=i/1000-c1*100-c2*10;
  ll  c4=i/100-c1*1000-c2*100-c3*10;
   ll c5=i/10-c1*10000-c2*1000-c3*100-c4*10;
   ll c6=i-c1*100000-c2*10000-c3*1000-c4*100-c5*10;
    
  ll  d1=b/100000;
   ll d2=b/10000-d1*10;
  ll  d3=b/1000-d1*100-d2*10;
  ll  d4=b/100-d1*1000-d2*100-d3*10;
   ll d5=b/10-d1*10000-d2*1000-d3*100-d4*10;
   ll d6=b-d1*100000-d2*10000-d3*1000-d4*100-d5*10;
    ll sum=c1+c2+c3+c4+c5+c6;
    ll sumi=d1+d2+d3+d4+d5+d6;
    ll fina=sum+sumi;
    vec.at(i-1)=fina;
  }
  
  sort(all(vec));
  cout<<vec.at(0)<<endl;
}
    
    
    
  

Measured memory_bytes: 1024
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')
for i in range(N - K + 1):
    tmp = abs(X[i]) + abs(X[i + K - 1] - X[i])
    tmp2 = abs(X[i + K - 1]) + abs(X[i + K - 1] - X[i])
    ans = min(ans, tmp, tmp2)

print(ans)

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

int main(void){
    unsigned int N;
    vector<unsigned int> A;
    cin >> N;
    for(size_t i = 0;i < N;i++) {
        unsigned Ai;
        cin >> Ai;
        A.push_back(Ai);
        
    }
    
    unsigned int C = 0;
    while(true){
        for(size_t i = 0;i < N;i++){
            if((A[i] % 2) != 0){
                cout << C;
                return 0;
            }
            A[i] /= 2;
        }
        C++;
    }
}


Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10桁出力 cout << setprecision(10) << double;
#include <queue>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	int a, b, h;
	cin >> a >> b >> h;

	cout << (((a + b)*h) / 2) << endl;


	return 0;
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

void dfs(vector< vector<int> >& G, vector<string>& name, int v, string pre) {
	cout << pre << name[v] << endl;
	EACH(to, G[v]) {
		dfs(G, name, to, pre+".");
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N; cin >> N;
	vector<string> name(N);
	vector< vector<int> > G(N);
	REP(i, N) {
		int par; cin >> par; --par;
		if (par >= 0) {
			G[par].pb(i);
		}
		cin >> name[i];
	}
	dfs(G, name, 0, "");
}

Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n+1);
    for(ll i=1;i<=n;i++)
    cin>>a[i];
    vector<vector<vector<ll> >  > dp(n+3,vector<vector<ll> > (n+3,vector<ll> (3,0)));
    // let dp[i][j] denotes that we have found the answer for i,i+1....j-1,j and we want to expand our answer. the answer will be dp[1][n];
    for(ll i=n;i>=1;i--)
    {
        for(ll j=i;j<=n;j++)
        {
            dp[i][j][0]=max(dp[i][j-1][1]+a[j],dp[i+1][j][1]+a[i]);
            dp[i][j][1]=min(dp[i][j-1][0]-a[j],dp[i+1][j][0]-a[i]);
        }
    }
    cout<<dp[1][n][0]<<endl;

    
    
}

Measured memory_bytes: 496612
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353

@njit((i8, i8[:, :]), cache=True)
def precompute(N, G):
    ng = np.zeros(N + 10, np.bool_)
    g = np.zeros(N + 1, np.int64)
    ind = np.searchsorted(G[:, 0], np.arange(N + 10))
    for v in range(N - 1, 0, -1):
        for i in range(ind[v], ind[v + 1]):
            w = G[i, 1]
            ng[g[w]] = 1
        for n in range(N + 10):
            if ng[n]:
                continue
            break
        g[v] = n
        for i in range(ind[v], ind[v + 1]):
            w = G[i, 1]
            ng[g[w]] = 0

    B = 10**18 % MOD
    power = 1
    A = np.zeros(1024, np.int64)
    for i in range(1, N + 1):
        power = power * B % MOD
        A[g[i]] += power
    return A % MOD

@njit((i8[:], i8[:]), cache=True)
def convolve(A, B):
    C = np.zeros(1024, np.int64)
    for i in range(1024):
        for j in range(1024):
            C[i ^ j] += A[i] * B[j] % MOD
    return C % MOD

N = int(readline())
nums = np.array(read().split(), np.int64)
graphs = []
for _ in range(3):
    M = nums[0]
    G = nums[1:1 + 2 * M].reshape(M, 2)
    G.sort(axis=1)
    G = G[np.argsort(G[:, 0])]
    graphs.append(G)
    nums = nums[1 + 2 * M:]

G1, G2, G3 = map(lambda G: precompute(N, G), graphs)

print(convolve(convolve(G1, G2), G3)[0])

Measured memory_bytes: 147692
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, C;
    cin >> n >> C;

    vector<ll> x(n), v(n);
    rep(i, n) cin >> x[i] >> v[i];

    vector<ll> Sv(n + 1);
    rep(i, n) {
        Sv[i+1] = Sv[i] + v[i];
    }

    vector<ll> best(n);
    ll b = 0;
    rep(i, n) {
        ll score = Sv[i+1] - x[i];
        b = max(b, score);
        best[i] = b;
    }

    vector<ll> bestInv(n);
    b = 0;
    for (int i = n -1; i >= 0; i--) {
        ll score = Sv[n] - Sv[i] - (C - x[i]);
        b = max(b, score);
        bestInv[i] = b;
    }

    ll res = max(best[n-1], bestInv[0]);
    for (ll i = 0; i < n-1; i++) {
        res = max(res, best[i] + bestInv[i+1] - x[i]);
        res = max(res, best[i] + bestInv[i+1] - (C - x[i+1]));
    }

    put(res);

}
signed main(){ Main();return 0;}

Measured memory_bytes: 7216
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

string to_string(int n)
{
	char buf[3];
	sprintf(buf,"%d",n);
	return buf;
}

int main()
{
	for(int n,k;cin>>n>>k,n|k;){
		vi a(n);
		rep(i,n)
			cin>>a[i];
		sort(allof(a));
		set<string> res;
		do{
			string s;
			rep(i,k)
				s+=to_string(a[i]);
			res.insert(s);
			reverse(k+allof(a));
		}while(next_permutation(allof(a)));
		cout<<res.size()<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0