akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
import math


def solve(K: int):

    ans = 0
    for a in range(1,K+1):
        for b in range(a,K+1):
            for c in range(b,K+1):
                p=1
                if (a == b) or (b == c) or (a ==c):
                    p+=1
                    if (a==b==c):
                        p+=4
                ans += math.gcd(math.gcd(a,b),c)*(int(6/p))
                
    print(ans)

    return


# Generated by 1.1.6 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()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000

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

  int n=s.size();
  vector<int> x_move,y_move;
  int turn=0;
  int count=0;
  for(int i=0;i<n;i++){
    if(s.at(i)=='T'){
      if(turn==0){
        x_move.push_back(count);
      }else{
        y_move.push_back(count);
      }
      count=0;
      turn=1-turn;
    }else{
      count++;
    }
  }
  if(turn==0){
    x_move.push_back(count);
  }else{
    y_move.push_back(count);
  }

  int X=x_move.size();
  int Y=y_move.size();
  int x_sum=0,y_sum=0;
  for(int i=1;i<X;i++){
    x_sum+=x_move.at(i);
  }
  for(int i=0;i<Y;i++){
    y_sum+=y_move.at(i);
  }
  bool flag=true;
  x-=x_move.at(0);
  if(abs(x)>x_sum){
    flag=false;
  }
  if(abs(y)>y_sum){
    flag=false;
  }
  vector<bool> x_dp(x_sum+1,false);
  x_dp.at(x_sum)=true;
  for(int i=1;i<X;i++){
    for(int j=0;j<=x_sum-2*x_move.at(i);j++){
      x_dp.at(j)=x_dp.at(j)||x_dp.at(j+2*x_move.at(i));
    }
  }
  vector<bool> y_dp(y_sum+1,false);
  y_dp.at(y_sum)=true;
  for(int i=0;i<Y;i++){
    for(int j=0;j<=y_sum-2*y_move.at(i);j++){
      y_dp.at(j)=y_dp.at(j)||y_dp.at(j+2*y_move.at(i));
    }
  }
  if(flag){
    if(!x_dp.at(abs(x))){
      flag=false;
    }
    if(!y_dp.at(abs(y))){
      flag=false;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }


}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int a[105];
int dp[100005];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,k; 
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	dp[0] = 0;
	for(int i=0;i<=k;i++){
		int z = 0;
		for(int j=0;j<n;j++){
			if(i>=a[j] and dp[i-a[j]]==0)z++;
		}
		dp[i] = 0;
		if(z)dp[i] = 1;
	}
	if(dp[k])cout<<"First\n";
	else cout<<"Second\n";
	return 0;
}


Measured memory_bytes: 640
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args){
            int a, b, c;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = int.Parse(str[2]);
            if(a<b&&b<c){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
		}
    }
}

Measured memory_bytes: 8824
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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




int main()
{
  // input & declare
  int n,Y;
  cin >> n >> Y;

  // process
  for(int x = 0;x < n+1; x++)
  {
    for(int y = 0; y < n+1-x; y++)
    {
      if (9 * x + 4 * y == (Y/1000) - n && x >= 0 && y >= 0 && (n - (x + y)) >= 0) {
        std::cout << x << ' ' << y << ' ' << n - x - y << '\n';
        exit(0);
      }
    }
  }

  std::cout << "-1 -1 -1" << '\n';
  // output
}


Measured memory_bytes: 256
N = int(input())
T, X, Y = 0, 0, 0
count = 0
for i in range(N):
  t, x, y = map(int, input().split())
  dt = t - T
  dist = abs(x - X) + abs(y - Y)
  if dist <= dt and t%2 == (x+y)%2:
    count += 1
  T, X, Y = t, x, y
print('Yes' if count == N else 'No')
    
 


       


Measured memory_bytes: 3060
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    ans = 0
    b = 0

    for char in s:
        if char == "B":
            b += 1
        else:
            ans += b

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication50
{
    class Program
    {
        static void Main()
        {
            List<string> n = new List<string>();
            while (true)
            {
                List<int> s = new List<int>();
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (a[0] == 0 && a[1] == 0) break;
                for (int b = a[0]; b <= a[1]; b++)
                {
                    if (b % 400 == 0) { s.Add(b); continue; }
                    if (b % 100 == 0) { continue; }
                    if (b % 4 == 0) { s.Add(b); continue; }
                }
                if (s.Count == 0) { n.Add("NA");n.Add(""); }
                else
                {
                    foreach (int u in s)
                    {
                        n.Add(u.ToString());
                    }
                    n.Add("");
                }
            }
           for(int t = 0; t < n.Count - 1; t++)
            {
                Console.WriteLine(n[t]);
            }
        }
    }
}

Measured memory_bytes: 9636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int k,l;
	cin>>k>>s;
	l=s.length();
	if(l>k)
	{
		for(int i=0;i<k;i++)
			cout<<s[i];
		cout<<"...";
	}
	else
		cout<<s;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, M;
  cin >> N >> M;
  set<long> foo, bar;
  rep (i, M) {
    long a, b;
    cin >> a >> b;
    if (a == 1) foo.insert(b);
    if (b == N) bar.insert(a);
  }
  for (auto it: foo) {
    if (bar.count(it)) {
      cout << "POSSIBLE" << endl;
      return;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

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


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

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
 
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
 

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}


vector<pair<ll, ll>> factorize(ll x)
{
    vector<pair<ll, ll>> ret;
    for(ll i=2;i*i <= x; ++i)
    {
        int count_divided = 0;
        while(x % i == 0)
        {
            x /= i;
            count_divided++;
        }

        if(count_divided != 0)
        {
            ret.push_back(make_pair(i, count_divided));
        }
    }
    if(x != 1)
    {
        ret.push_back(make_pair(x, 1));
    }

    return ret;
}

int main(){
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    auto factor = factorize(n);
    int ret = 0;
    for(auto p : factor)
    {
      int times = 1;
      int count = p.second;
      while(count >= times)
      {
        count -= times;
        ret++;
        times++;
      }
    }

    cout << ret << endl;
}

Measured memory_bytes: 3656
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;
	static int[] parent;//union-find用
	static int[] rank;//union-find用

	public static void main(String[] args) throws IOException {
		//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//		String W	 = in.readLine();
		//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int R = sc.nextInt();
		int d = sc.nextInt();

		for(int i = L;i<=R ; i++) {
			if(i%d==0) {
				ans++;
			}
		}
		System.out.println(ans);

	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

	//Union-Find用の配列を要素数nで初期化
	static void ufInit(int n){
		parent = new int[n];
		rank = new int[n];
	}

	//Union-Findの要素の最上位の親（グループ名）を返す
	static int ufFind(int a) {
		if(parent[a]==a) {
			return a;
		}else {
			return ufFind(parent[a]);
		}
	}

	//Union-Find木を連結する
	static void ufUnite(int a, int b) {
		a = parent[a];
		b = parent[b];

		if(a==b) {
			return;
		}
		if(rank[a] > rank[b]){
			parent[b]=a;
		}else {
			parent[a]=b;
			if(rank[a]==rank[b]) {
				rank[b]++;
			}
		}
	}

	static boolean ufSame(int a, int b) {
		return ufFind(a)==ufFind(b);
	}
}


Measured memory_bytes: 35540
#include<stdio.h>

int main() {
        char s[100000];
        scanf("%s", s);
        for (int left = 0; *(s + left + 1) != '\0'; left++) {
                if (*(s + left) == *(s + left + 1)) {
                        printf("%d %d\n", left + 1, left + 2);
                        return 0;
                }
        }
        for (int left = 0; *(s + left + 2) != '\0'; left++) {
                if (*(s + left) == *(s + left + 2)) {
                        printf("%d %d\n", left + 1, left + 3);
                        return 0;
                }
        }
        printf("-1 -1\n");
        return 0;
}

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

using namespace std;

int main(){
  int a = 0, b, c;
  for(int i = 0; i < 4; i++){
    cin >> b;
    a += b;
  }
  printf("%d\n", a / 60);
  a -= a / 60 * 60;
  printf("%d\n", a);
  return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  ll l;
  cin >> l;
  vl a(n);
  REP(i, n) { cin >> a[i]; }

  int j = -1;
  REP(i, n - 1) {
    if (a[i] + a[i + 1] >= l)
      j = i;
  }
  if (j == -1) {
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;

  REP(i, j) { cout << i + 1 << endl; }

  for (int i = n - 2; i > j; i--) {
    cout << i + 1 << endl;
  }
  cout << j + 1 << endl;
}


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

int main(){
  int N; cin >> N;
  vector<vector<int>> AB(N, vector<int>(2));
  for (int i=0; i<N; i++) cin >> AB[i][0] >> AB[i][1];
  sort(AB.begin(), AB.end(), [](const auto& x, const auto& y){ return x[1]<y[1];});
  int sum = 0;
  int now = 0;
  for (int i=0; i<N; i++){
    now = AB[i][1];
    sum += AB[i][0];
    if (sum > now){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 11136
N, Y = map(int, input().split())

for i in range(N+1):
  if Y < 10000 * i:
    break
  for j in range(N-i+1):
    if Y < 10000 * i + 5000 * j:
      break
    if Y == 10000 * i + 5000 * j + 1000 * (N-i-j):
      print(i,j,N-i-j)
      exit(0)

print(-1,-1,-1)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str1 = sc.next();
        char[] c1 = str1.toCharArray();
        String str2 = sc.next();
        char[] c2 = str2.toCharArray();
        
        int count = 0;
        int n = c1.length;
        for (int i = 0; i < n; i++) {
            if (c1[i] == c2[i]) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21716
n,q = gets.split.map(&:to_i)
s = gets.chomp
c = Array.new(n,0)
num=0
n.times do |i|
    next if i == 0
    num+=1 if s[i-1]=='A'&&s[i]=='C'
    c[i]=num
end
q.times do |i|
    l,r = gets.split.map(&:to_i)
    puts c[r-1]-c[l-1]
end

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int main() {

    //ifstream cin("testC.in");

    int n; cin >> n;
    vector<int> t(n, 0);
    vector<int> a(n, 0);

    for(int i = 0; i < n; ++i)
        cin >> t[i];
    
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    
    int last = -1;
    
    vector<int> f(n, -1);
    
    auto bad = [] () {
        cout << "0\n";
        exit(0);
    };

    for(int i = 0; i < n; ++i) {
        if(t[i] != last) {
            f[i] = t[i];
            if(a[i] < f[i])
                bad();
        }
        last = t[i];
    }
    
    last = -1;

    for(int i = n - 1; i >= 0; --i) {
        if(a[i] != last) {
            if(f[i] >= 0 && f[i] != a[i])
                bad();
            f[i] = a[i];
            if(t[i] < f[i])
                bad();
        }
        last = a[i];
    }
    
    int ans = 1;

    for(int i = 0; i < n; ++i)
        if(f[i] == -1) {
            int minn = min(a[i], t[i]);
            ans = 1LL * ans * minn % MOD;
        }

    cout << ans << "\n";
}

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

int main(){
    int r;
    cin >> r;
    cout << 2*r*3.14 << endl;
}


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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	//aka s aka 7
	int n = (s.size() - 1) / 2;

	string t; t = s;
	bool f = true;

	for (int i = 0; i < n; i++) {
		if (s[i] != s[n-1- i])f = false;
	}

	reverse(s.begin(), s.end());

	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i])f = false;
	}

	if (t != s)f = false;


	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
    ll x;
    cin >> x;
    ll ans = 0;

    ans += (x / 500) * 1000;
    ans += (x % 500) / 5 * 5;

    cout << ans << endl;
}

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

int main() {
    long long int h;
    long long int ans = 0;
    long long int add = 1;
    cin >> h;
    while(h != 0){
        h /= 2;
        ans += add;
        add *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

#include <iostream>

int main()
{
	int H, W, h, w;
	cin >> H >> W >> h >> w;

	cout << (H - h) * (W - w) << endl;
}

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

long long N, P;
long long A[100];
long long odd;
long long even;



vector<vector<long long> > comb;

void combination(int n)
{
	comb.assign(n+1, vector<long long>(n+1, 0));
	for(int i=0; i<=n; ++i){
		comb[i][0] = 1;
		for(int j=1; j<=i; ++j){
			comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
		}
	}
}


int main(){
	cin >> N >> P;
	for(long long i = 0; i < N; i++){
		cin >> A[i];
		if(A[i] % 2 == 0){
			even++;
		}else{
			odd++;
		}
	}

	combination(100);


	long long ans = 0;
	long long ecount = 0;
	long long ocount = 0;
	if(P == 0){
		for(long long i = 0; i <= even; i++){
			ecount += comb[even][i];
		}

		for(long long i = 0; i <= odd; i+=2){
			ocount += comb[odd][i];
		}
		cout << ecount * ocount << endl;
	}else{
		for(long long i = 0; i <= even; i++){
			ecount += comb[even][i];
		}

		for(long long i = 1; i <= odd; i+=2){
			ocount += comb[odd][i];
		}
		cout << ecount * ocount << endl;
	}
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;

int findSumOfDigits(int n) {
	int sum = 0;
	while (n > 0) { // n が 0 になるまで
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main()
{
	int n;
	cin >> n;
	int sum = findSumOfDigits(n);
	if (n % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace 
std;int main() {
  int N;
  cin>>N;
  vector<int> S;
  S={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<S.at(N-1)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main(){
  int n,sum=0,m;
  cin>>n;
  int t[n];
  REP(i,n){
    cin>>t[i];
    sum+=t[i];
  }
  int copysum=sum;
  cin>>m;
  REP(i,m){
    int p=0,x=0;
    cin>>p>>x;
    sum+=x;sum-=t[p-1];
    cout<<sum<<endl;
    sum=copysum;
  }
  
  
  }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<cstdlib>



using namespace std;

long long int n,ans;

long long int f(long long int nn){
    long long int rec;
    if(nn/5 == 0) return 0;
    else{
        rec = nn/5 + f(nn/5);
    }
    return rec;
}

int main(){
    cin >> n;
    if(n % 2 == 1){
        ans = 0;
    }
    else{
        ans = f(n/2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7,N=2e5+5;
int n,A[N],L[N],C[N];
int a[N],cnt;
int CNT[N],D[N];
void add(int x,int d) {
	while(x<=n+1) {
		D[x]=(D[x]+d)%P;
		x+=(x&(-x));	
	}
}
int sum(int x) {
	int res=0;
	while(x) {
		res=(res+D[x])%P;
		x-=(x&(-x));
	}
	return res%P;
}
int main() {
	scanf("%d",&n);cnt=1;
	for(int i=1; i<=n; i++) {
		scanf("%d",&a[i]);
		if(a[i]!=a[i-1])
			A[++cnt]=a[i];
	} n=cnt;
	for(int i=2; i<=n; i++)
		L[i]=C[A[i]],C[A[i]]=i;
	add(1,1);
	for(int i=2; i<=n; i++) {
		if(L[i]==0)continue;
		int c=sum(L[i]-1);
		CNT[A[i]]=(CNT[A[i]]+c)%P;
		add(i,CNT[A[i]]);
	}
	printf("%d\n",sum(n+1));
	return 0;	
}

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

int main(void){
	int n, w=0, e=0;
	string s;
	cin >> n >> s;
	for(int i=1; i<n; i++) if(s[i]=='E') e++;
	int ans=e;
	for(int i=1; i<n; i++){
		if(s[i]=='E') e--;
		if(s[i-1]=='W') w++;
		if(ans>w+e) ans = w+e;
	}
	cout << ans << endl;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,w;
    cin>>n>>w;ll wt[n];ll val[n];
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
    }
     ll dp[n+1][w+1];
     for(int i=0;i<n+1;i++)
     {
         dp[i][0]=0;
     }
     for(int j=0;j<w+1;j++)
     {
         dp[0][j]=0;
     }
     for(int i=1;i<n+1;i++)
     {
         for(int j=1;j<w+1;j++)
         {
             if(j>=wt[i-1])
             {
                 dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-wt[i-1]]);
             }
             else
             {
                 dp[i][j]=dp[i-1][j];
             }
         }
     }
     cout<<dp[n][w];
}



Measured memory_bytes: 79232
N,M = map(int,input().split())
P = list(map(int,input().split()))
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
par = []
rank = []
for i in range(N):
  par.append(i)
  rank.append(0)
def find(x,par):
  if par[x] == x:
    return x
  else:
    return find(par[x],par)
def unite(x,y,par,rank):
  x = find(x,par)
  y = find(y,par)
  if x != y:
    if rank[x] < rank[y]:
      par[x] = y
    else:
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1
for i in range(M):
  unite(L[i][0]-1,L[i][1]-1,par,rank)
ans = 0
for i in range(N):
  if find(P[i]-1,par) == find(i,par):
    ans += 1
print(ans)

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

int main() {
    int N, X; cin >> N >> X;
    int D[100]; D[0] = 0;
    int Li = 0;
    for (int i = 1; i < N + 1; i++) {
        cin >> Li;
        D[i] = D[i - 1] + Li;
    }

    int c = 0;
    for (int i = 0; i < N + 1; i++) {
        if (D[i] <= X) c++;
    }

    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
typedef long long int ll;

using namespace std;

// nまでにk桁目が1である数がいくつあるか
ll sum1(ll n, ll k) {
    return ((n+1) / ((1LL << k) * 2) * (1LL << k)) + max((n+1) % ((1LL << k) * 2) - (1LL << k), 0LL);
}

int main() {
    ll a,b;
    cin >> a >> b;
    ll ans = 0;
    for(ll k = 0; b >= (1LL<< k) ;k++) {
        ll n = sum1(b, k) - sum1(a-1, k);
        //cout << k << ' ' << sum1(b, k) << " " << sum1(a-1, k) << endl;
        ans += (1LL << k) * (n%2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import permutations
from math import factorial
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
XY = [list(map(int, readline().split())) for _ in range(N)]

dist = 0
for route in permutations(XY, N):
    acc = 0
    dists = [
        np.sqrt(
            pow(route[i][0] - route[i + 1][0], 2) +
            pow(route[i][1] - route[i + 1][1], 2)) for i in range(N - 1)
    ]
    dist += sum(dists)
print(dist / factorial(N))

Measured memory_bytes: 14452
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, c;
    cin >> n >> c;
    set<tuple<int, int, int>> stcs;
    for(int i = 0; i < n; i++){
        int s, t, c;
        cin >> s >> t >> c;
        stcs.emplace(s, t, c);
    }
    int ans = 0;
    prints(stcs);
    while(stcs.size()){
        ans++;
        auto next = stcs;
        int time = -1, channel = -1;
        for(auto& stc : stcs){
            if(time + (channel != get<2>(stc)) <= get<0>(stc)){
                time = get<1>(stc);
                channel = get<2>(stc);
                next.erase(stc);
            }
        }
        next.swap(stcs);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 10232
#include<bits/stdc++.h>
#define int long long int
using namespace std;
const int INF = 3e18;
int n, m, k;
int a[20001];
int dp[20001];
signed main()
{
  scanf("%lld%lld%lld", &n, &m, &k);
  for(int i = 1; i <= n; i++){
    scanf("%lld", &a[i]);
  }

  fill(dp + 1, dp + n + 1, INF);

  for(int i = 0; i < n; i++){
    int mx = 0, mn = INF;
    for(int j = i + 1; j <= min(i + m, n); j++){
      mx = max(mx, a[j]);
      mn = min(mn, a[j]);

      dp[j] = min(dp[j], dp[i] + k + ((j - i) * (mx - mn)));
    }
  }
  printf("%lld\n", dp[n]);
  return 0;
}

Measured memory_bytes: 1500
N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

def f(x)
  cnt = 0

  while x % 2 == 0 
    x /= 2
    cnt += 1
  end

  cnt
end

B = A.map { |a| f(a / 2) }

if B.uniq.size > 1
  puts 0
  exit
end

T = A.map { |a| a / 2 }.inject(&:lcm)

puts (M / T / 2.0).ceil


Measured memory_bytes: 14220
#include <iostream>

using namespace std;

int main(void) {
	int A,B;
	cin >> A >> B;
	int res = 0;
	if (A >= 13) {
		res = B;
	}
	else if (A >= 6) {
		res = B/2;
	}
	cout << res << endl;
	return 0;
}


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

int main() {
    int N;
    scanf("%d", &N);
    char S[605][605], T[605][605];
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            char c;
            scanf(" %c", &c);
            S[i][j] = S[i + N][j] = S[i][j + N] = S[i + N][j + N] = c;
            T[j][i] = T[j + N][i] = T[j][i + N] = T[j + N][i + N] = c;
        }
    }

    int ans = 0;
    for (int a = 0; a < N; ++a) for (int b = 0; b < N; ++b) {
        int ok = 1;
        for (int i = 0; i < N; ++i) {
            if (memcmp(S[i + a] + b, T[i + b] + a, i + 1)) {
                ok = 0;
                break;
            }
        }
        ans += ok;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    long long n,m,k;
    cin>>n>>m>>k;
    if(n>=k){
        n=n-k;
    }else{k=k-n;n=0;
    if(m>=k){
        m=m-k;
    }else{
        m=0;
    }

    }cout<<n<<" "<<m;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
int N;
std::cin >> N;
int a,b,c;
if(N>=900)
a=1; //本当は9
else
a=9;
	if(N%10==9){
	c=1;
	if(N%100==99)
	b=1;
	else
	b=9;
	}

	else{
	c=9;
	if(N%100==11)
	b=9;
	else
	b=1;
	}
std::cout << a << b << c << std::endl;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var num string
	fmt.Scan(&num)

	num = strings.Replace(num, "9", "A", -1)
	num = strings.Replace(num, "1", "9", -1)
	num = strings.Replace(num, "A", "1", -1)
	fmt.Printf("%s\n", num)
}


Measured memory_bytes: 640
#include <iostream>
#define int long long
using namespace std;

int k;
int a[100000];

int f(int n) {
	for (int i = 0; i < k; i++) {
		n = (n / a[i]) * a[i];
	}
	return n;
}

int getMin() {
	int st = 0, ed = 1e+18, mid; //xxxxoooo. (st, ed]
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (f(mid) >= 2) ed = mid;
		else st = mid;
	}
	return ed;
}

int getMax() {
	int st = 0, ed = 1e+18, mid;	//ooooxxx. [st, ed)
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (f(mid) <= 2) st = mid;
		else ed = mid;
	}
	return st;
}

signed main() {
	int i;
	
	cin >> k;
	for (i = 0; i < k; i++) cin >> a[i];
	int low = getMin();
	int high = getMax();
	if (low > high) { cout << -1 << endl; }
	else { cout << low << " " << high << endl; }
	return 0;
}

Measured memory_bytes: 1024
# 上位ノードほど @rank が大きい数字となる
class Node
  attr_accessor :parent, :rank

  # 親は自分自身、ランクは 0 として初期化する
  def initialize(n)
    @parent = n
    @rank = 0
  end
end

class UnionFind
  # 0 から n - 1 までのノードを初期化する
  def initialize(n)
    @nodes = (0...n).map { |i| Node.new(i) }
  end

  # 再帰で最も上位の親を探し、その値を返す（更新しないため少し遅い）
  def root(x)
    return x if @nodes[x].parent == x
    root(@nodes[x].parent)
  end

  # a と b を仲間にする
  def unite(a, b)
    a_root = root(a)
    b_root = root(b)
    # a 及び b の親が同じ場合は何もしない
    return if a_root == b_root

    # a親ランク < b親ランク の場合は、b親をa親の親とする
    # なお、ランクをいじる必要はなし
    if @nodes[a_root].rank < @nodes[b_root].rank
      @nodes[a_root].parent = b_root
    # その他の場合は、a親をb親の親とする
    else
      @nodes[b_root].parent = a_root
    # a親、及びb親のランクが同じ場合は、a親のランクを +1 する
      @nodes[a_root].rank += 1 if @nodes[a_root].rank == @nodes[b_root].rank
    end
  end

  # a と b の最も上位の親が同じかどうかを返す
  def same?(a, b)
    root(a) == root(b)
  end

  # 各ノードの親を全て出力する確認用
  def parents
    @nodes.map(&:parent)
  end
  
  # 各ノードの最も上位の親を全て出力する確認用
  def roots
    @nodes.size.times.map { |i| root(i) }
  end
end

n, m = gets.split.map(&:to_i)
numbers = gets.split.map(&:to_i).map(&:pred)
edges = []
m.times { edges << gets.split.map(&:to_i).map(&:pred) }
tree = UnionFind.new(n)
edges.each { |x, y| tree.unite(x, y) }
count = 0
numbers.each_with_index { |num, i| count += 1 if tree.same?(num, i) }
puts count


Measured memory_bytes: 17660
let is_prime = function
    2|3|5|7 -> true
    | n when n mod 2 = 0 -> false
    | n ->
       let rec loop = function
           i when i*i > n -> true
         | i -> if n mod i = 0 then false
                else loop (i+2);
       in loop 3

let () =
  let n = read_int () in
  let rec read ct = function
      0 -> ct
    | i ->
       let m = read_int () in
       read (if is_prime m then ct+1 else ct) (i-1)
  in
  Printf.printf "%d\n" (read 0 n)

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    int k;cin>>k;
     string s;cin>>s;
     int l=s.length();
     if(l<=k)cout<<s;
     else {
         rep(i,0,k)cout<<s[i];
         cout<<"...";
     }

 
return 0;
}

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

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

	vector<int> s(m),c(m); for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
	
	if (n == 1 && m == 0){
		cout << 0 << endl;
		return 0;
	}
	else if (n == 2 && m == 0) {
		cout << 10 << endl;
		return 0;
	}
	else if (n == 3 && m == 0) {
		cout << 100 << endl;
		return 0;
	}

	bool end = false;
	
	if (2 <= n) {
		for (int i = 0; i < m; i++) {
			if (s[i] == 1 && c[i] == 0) end = true;
		}
	}

	if (2 <= m) {
		for (int i = 0; i < m - 1; i++) {
			for (int j = i + 1; j < m; j++) {
				if (s[i] == s[j] && c[i] != c[j]) end = true;
			}
		}
	}

	if (end) {
		cout << -1 << endl;
		return 0;
	}


	vector<int> vec(3, 0);
	for (int i = 0; i < m; i++) {		
		if (vec[s[i] - 1] < c[i]) {
			vec[s[i] - 1] = c[i];
		}
	}
	
	int ans;
	
	if (n == 1) {
		ans = vec[0];
	}
	else if (n == 2) {
		ans = max(1, vec[0]) * 10 + vec[1];
	}
	else {
		ans = max(1,vec[0]) * 100 + vec[1] * 10 + vec[2];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    a = S.count("a")
    b = S.count("b")
    c = S.count("c")

    if abs(a - b) <= 1 and abs(b - c) <= 1 and abs(c - a) <= 1:
        ans = "YES"
    else:
        ans = "NO"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := readi()
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = readi()
	}

	tmp := make([]int, n)
	copy(tmp, x)
	sort.Ints(tmp)

	l := n - 1
	median := (l + 1) / 2
	for i := 0; i < n; i++ {
		if x[i] >= tmp[median] {
			fmt.Println(tmp[median-1])
		} else {
			fmt.Println(tmp[median])
		}
	}
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 8576
S = input()
N = len(S)
MOD = 10 ** 9 + 7

# dp[i][j] := i文字目までみた時に13で割ってj余るような数の通り数
dp = [[0] * 13 for i in range(N + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(13):
        if s != '?':
            dp[i + 1][((j * 10) % 13 + int(s)) % 13] += dp[i][j]
            dp[i + 1][((j * 10) % 13 + int(s)) % 13] %= MOD
        else:
            for k in range(10):
                dp[i + 1][((j * 10) % 13 + k) % 13] += dp[i][j]
                dp[i + 1][((j * 10) % 13 + k) % 13] %= MOD

print(dp[-1][5] % MOD)


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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const ll llinf = LLONG_MAX;
const ull ullinf = ULLONG_MAX;

int n, m;
vector<pair<int, int> > v;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;
#endif
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back({b, a});
  }
  sort(v.begin(), v.end());
  int ans = 0;
  int l_cut = 0;
  int r_cut = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    int right = v[i].fi;
    int left = v[i].se;
    if (i == 0) {
      l_cut = right - 1;
      r_cut = right;
      ans++;
    } else {
      if (left >= r_cut || right <= l_cut){
        l_cut = right - 1;
        r_cut = right;
        ans++;
      }
    }
  }
  cout << ans << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int series_sum(long long int);

int main(){
    int t,a,b,c,maxv,minv,mid;
    cin>>t;
    rep(l,t){
        cin>>a>>b>>c;
        maxv=max(a,max(b,c));
        minv=min(a,min(b,c));
        mid=a+b+c-minv-maxv;
        YN(maxv*maxv==minv*minv+mid*mid);
    }
}


Measured memory_bytes: 3048
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	h, w := scanInt(), scanInt()

	a := make([][]int, h+1)
	b := make([][]int, h+1)

	for i := 1; i < h+1; i++ {
		a[i] = make([]int, w+1)
		for j := 1; j < w+1; j++ {
			a[i][j] = scanInt()
		}
	}

	for i := 1; i < h+1; i++ {
		b[i] = make([]int, w+1)
		for j := 1; j < w+1; j++ {
			b[i][j] = scanInt()
		}
	}

	dp := [81][81][160*80]bool{}

	dp[0][1][0], dp[1][0][0] = true, true

	for i := 1; i<w+1 || i<h+1; i++ {
		for j := i; j < w+1; j++ {
			if i > h {
				break
			}
			for k := 0; k < (w+h)*80; k++ {
				if dp[i-1][j][k] || dp[i][j-1][k] {
					diff := abs(a[i][j] - b[i][j])
					if k + diff < (w+h)*80 {
						dp[i][j][k+diff] = true
					}

					if k - diff < 0 {
						dp[i][j][diff-k] = true
					} else {
						dp[i][j][k-diff] = true
					}
				}
			}
		}

		for j := i; j < h+1; j++ {
			if i > w {
				break
			}
			for k := 0; k < (w+h)*80; k++ {
				if dp[j-1][i][k]|| dp[j][i-1][k] {
					diff := abs(a[j][i] - b[j][i])
					if k + diff < (w+h)*80 {
						dp[j][i][k+diff] = true
					}
					if k - diff < 0 {
						dp[j][i][diff-k] = true
					} else {
						dp[j][i][k-diff] = true
					}
				}
			}
		}
	}

	var ans int
	for i := 0; i < (w+h)*80; i++ {
		if dp[h][w][i] {
			ans = i
			break
		}
	}

	fmt.Println(ans)
}

func abs(a int) int {
	if a<0 {
		return -a
	}
	return a
}


Measured memory_bytes: 85504
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;

int cnt[100010];

int one;
int two;

int main(){

  n = in();
  REP( i , n ){
    cnt[in()]++;
  }

  REP( i , 100010 ){
    if( cnt[i] > 0 ){
      if( cnt[i] % 2 == 1 ){
        one++;
      } else {
        two++;
      }
    }
  }

  if( two % 2 == 1 ){
    cout << one + two - 1 << endl;
  } else {
    cout << one + two << endl;
  }
  
  return 0;
}


Measured memory_bytes: 640
# A さん、B さん、C さんの 3 人が以下のようなカードゲームをプレイしています。
# 最初、3 人はそれぞれ a、b、c いずれかの文字が書かれたカードを、何枚か持っている。
# これらは入力で与えられた順番に持っており、途中で並べ替えたりしない。
# A さんのターンから始まる。
# 現在自分のターンである人がカードを 1 枚以上持っているならば、そのうち先頭のカードを捨てる。
# その後、捨てられたカードに書かれているアルファベットと同じ名前の人 (例えば、カードに a と書かれていたならば A さん) のターンとなる。
# 現在自分のターンである人がカードを 1 枚も持っていないならば、その人がゲームの勝者となり、ゲームは終了する。
# 3 人が最初に持っているカードがそれぞれ先頭から順に与えられます。
# 具体的には、文字列 SA、SB、SC が与えられます。
# 文字列 SA の i 文字目 ( 1≤i≤|SA| ) に書かれている文字が、
# A さんの持っている中で先頭から i 番目のカードに 書かれている文字です。
# 文字列 SB、 SC についても同様です。
# 最終的に誰がこのゲームの勝者となるかを求めてください。

# 情報を取得
a = gets.chomp
b = gets.chomp
c = gets.chomp

# 最初のカードに書かれた文字を返し、そのカードを捨てる関数を定義
def process(card)
  if card.empty?
    result = "end"
  else
    result = card.chr.upcase
  end
  
  card.slice!(0)
  
  return result
end

# カードゲームを行うための情報を整理
result = String.new
last_player = a.chr.upcase
next_card = a
next_player = process(next_card)

# カードゲームを行い、勝者を判定
loop do
  case next_player
  when "A"
    next_card = a
  when "B"
    next_card = b
  when "C"
    next_card = c
  else
    next_card = false
  end
  
  if next_card
    last_player = next_player
    next_player = process(next_card)
  else
    result = last_player
    break
  end
end

# 結果を出力
puts result

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

const int maxn = 3e5 + 5;
char s[maxn];
int e[maxn],w[maxn];

int main(){
	int n; scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf(" %c",&s[i]);
		if(s[i] == 'W'){
			w[i] = w[i - 1] + 1;
		}
		else w[i] = w[i - 1];

		if(s[i] == 'E'){
			e[i] = e[i - 1] + 1;
		}
		else e[i] = e[i - 1];
	}
	int mi = n;
	for(int i = 1;i <= n;i++){
		mi = min(mi,w[i - 1] + (e[n] - e[i]));
	}
	printf("%d\n",mi);
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

double calc(auto i, auto j, auto k, auto &dp, auto &N)
{
  if (dp[i][j][k] != -1) return dp[i][j][k];
  if (i+j+k == 0) return dp[0][0][0] = 0.0;
  if (i == 1 && j == 0 && k == 0) return dp[1][0][0] = N;
  double y1 = 0.0, y2 = 0.0, y3 = 0.0;
  if (k != 0) y3 = (1.0 + calc(i, j+1, k-1, dp, N)) * (double)k/N;
  if (j != 0) y2 = (1.0 + calc(i+1, j-1, k, dp, N)) * (double)j/N;
  if (i != 0) y1 = (1.0 + calc(i-1, j, k, dp, N)) * (double)i/N;
  return dp[i][j][k] = (N*(y3+y2+y1)+N-i-j-k)/(double)(i+j+k);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  double N;
  cin >> N;
  vector<double> a(N);
  INPUT(a);
  int ct_1 = 0, ct_2 = 0, ct_3 = 0;
  REPx(x, a)
  {
    if (x == 1) ct_1++;
    if (x == 2) ct_2++;
    if (x == 3) ct_3++;
  }
  vector<vector<vector<double>>> dp(N+1, vector<vector<double>>(ct_2+ct_3+1, vector<double>(ct_3+1, -1.0)));
  cout << setpre(10) << calc(ct_1, ct_2, ct_3, dp, N) << endl;

  return 0;
}

Measured memory_bytes: 216960