akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>


int gcd(int c, int d)
{
if(c==0) return d;
    else if(d==0) return c;
        else if (c<d) return gcd(d, c);
            else {
    return gcd(d, c%d);
                }
}


int main(void)
{
    long long a, b, c, d, i;
    long long c1, c2, c3, c4, c5, c6;

    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);

 long long e = gcd(c, d); 
 long long f = c * d / e; //最小公倍数

c1 = b / c;
c2 = b / d;
c3 = b / f;

c4 = (a-1) / c;
c5 = (a-1) / d;
c6 = (a-1) / f;

 long long suma = (a - 1) - (c4 + c5 - c6);
 long long sum = b - c1 - c2 + c3 - suma;
 printf("%lld\n", sum);
 return 0;

}

Measured memory_bytes: 256
#include <iostream>

int main()
{
  int N;
  std::string S;
  std::cin >> N >> S;
  int stack = 0; // number of "(" char in stack

  std::string ret = "";
  int i = 0;
  while(i < N) {
    switch(S[i]) {
      case '(': {
        if(i+1 < N && S[i+1] == ')') {
          ret += "()";
          i++; // skip 2, 1 more ++ in the end of while
        } else {
          ret += "(";
          stack++;
        }
        break;
      }
      case ')': {
        if(stack > 0) {
          ret += ")";
          stack--;
        } else {
          ret = "(" + ret + ")";
        }
        break;
      }
      default:
        // never come here
        break;
    }
    // std::cout << ret << " " << stack << std::endl;
    i++;
  }

  for(i=0; i<stack; i++) {
    ret += ")";
  }

  std::cout << ret << std::endl;
  return 0;
}


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

int main() 
{
    ll n;
    string s;
    ld a,b,h,m;
    cin>>a>>b>>h>>m;
    ld ang=(60*h)+m;
    ang=5.5*ang;
    while(ang>=360)
    {
        ang-=360;
    }
    ang=min(ang,360-ang);
    ang=((ang)/180)*pi;
    ld c=(a*a)+(b*b)-((2*a*b)*cos(ang));
    ld d=c;
    c=sqrt(c);
    cout<<setprecision(10)<<c;
}

Measured memory_bytes: 4196
import itertools
 
n, k = map(int, input().split())
p = list(map(int, input().split()))
acc = [0] + list(itertools.accumulate([(x+1)/2 for x in p])) # 累積和を計算
 
ans = max(acc[i]-acc[i-k] for i in range(k, n+1)) # k番目からn番目まで計算
print(ans)


Measured memory_bytes: 110256
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

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

    int first = stoi(s.substr(0, len(s)/2));
    int second = stoi(s.substr(len(s)/2));

    // YYMM
    string ans = "";
    int amb = 0;
    if(second > 0 && second <= 12) {
        ans = "YYMM";
    }
    // MMYY
    if(first > 0 && first <= 12) {
        if(ans == "YYMM") {
            amb = 1;
        }
        else {
            ans = "MMYY";
        }
    }

    if(len(ans) == 0) {
        cout << "NA" << '\n';
    }
    else if(amb == 1) {
        cout << "AMBIGUOUS" << '\n';
    }
    else if(amb == 0){
        cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;

int ans[1010][1010];
priority_queue <pii> q;

int main() {
	int n, m, A, B; scanf("%d%d%d%d", &n, &m, &A, &B);
	swap(A, B);
	int a, b, flag = 0;
	for (a = 0; a <= n; a++) {
		for (b = 0; b <= m; b++) {
			if (a * B + (n - a) * (m - B) == b * A + (m - b) * (n - A)) {
				flag = 1;
				break;
			}
		}
		if (flag) break;
	}
	if (!flag) {
		printf("-1\n");
		return 0;
	}
	for (int i = 0; i < b; i++) {
		if (A > 0) q.push(mp(A, i));
	}
	for (int i = b; i < m; i++) {
		if (n - A > 0) q.push(mp(n - A, i));
	}
	for (int i = 0; i < n; i++) {
		int now = i < a ? B : m - B;
		while (now--) {
			pii t = q.top(); q.pop();
			if (ans[i][t.se] == 1) assert(0);
			ans[i][t.se] = 1;
			if (t.fi != 1) q.push(mp(t.fi - 1, t.se));
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			printf("%d", ans[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <cmath>
#include <string.h>
#include <stdio.h>

using namespace std;
 

int main(){
  
  	int n;
  	while(cin >> n){
      
      if(n==0)
        break;
      
  	  vector<double>s(n);
  	  double sum = 0;
	  for(int i=0; i<n; i++){
      	cin >> s.at(i);
      	sum += s.at(i);
       }
  	
  	  double m = sum/n;
  	  double sum2 = 0;
  	  for(int i=0; i<n; i++){
    	sum2 += pow((s.at(i) - m), 2);
      }
  
  	  double result = sqrt(sum2/n);
      cout.precision(8);
      cout << fixed;
      cout << result <<endl;
    }

  return 0;
  
}


Measured memory_bytes: 3236
#include <iostream>
#include <vector>

int main(int argc, char const *argv[]) {
  int64_t N, L;
  int last_knot = -1;
  std::cin >> N >> L;
  std::vector<int64_t> rope(N);
  for (size_t i = 0; i < N; i++) {
    std::cin >> rope[i];
  }
  for (size_t i = 0; i < N-1; i++) {
    if (rope[i] + rope[i+1] >= L) {
      last_knot = i;
    }
  }
  if (last_knot == -1) {
    std::cout << "Impossible" << std::endl;
  } else {
    std::cout << "Possible" << std::endl;
    for (size_t i = 0; i < last_knot; i++) {
      std::cout << i+1 << std::endl;
    }
    for (size_t i = N-2; i > last_knot; i--) {
      std::cout << i+1 << std::endl;
    }
    std::cout << last_knot+1 << std::endl;
  }
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  ld a, b;
  cin >> a >> b;

  ll ans = floor(a * b);
  cout << ans << '\n';




  
  return 0;
}

Measured memory_bytes: 3764
import java.util.Scanner;

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

		int n = sc.nextInt();

		int min = n;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			int p = sc.nextInt();
			min = Math.min(min, p);
			if (p <= min)
				cnt++;
		}

		System.out.println(cnt);

		sc.close();
	}

}


Measured memory_bytes: 66024
import math

a = [1]*1000000
for i in range(2,1000000):
    for j in range(i+i,1000000)[::i]:
        a[j] = 0

b = [0]*1000000
b[0] = b[1] = 0
for i in range(2,1000000):
    if a[i] == 1:
        b[i] = b[i-1] + 1
    else:
        b[i] = b[i-1]

while True:
    try:
        print(b[int(input())])
    except EOFError:
        break


Measured memory_bytes: 23756
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

int l,r,d;
ll solve(){
   ll ans=0;
   

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

    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0)ans++;
    }
    cout<<ans<<endl;
    //cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 3648
def resolve():
    '''
    code here
    '''
    import collections
    import math
    N = int(input())
    Ss = [sorted([item for item in input()]) for _ in range(N)]
    
    sss = []
    for line in Ss:
        sss.append(''.join(line))
    line_cnt = collections.Counter(sss)

    cnt = 0
    for letter, num in line_cnt.most_common():
        if num >=2:
            cnt += math.comb(num, 2)

    print(cnt)
if __name__ == "__main__":
    resolve()


Measured memory_bytes: 50720
a,b=input().split()
a=int(a)
b=int(b)
c=[input().split() for i in range(a)]
d=1001
for i in range(a):
  if int(c[i][1])<=b:
    if d>int(c[i][0]):
      d=int(c[i][0])
if d==1001:
  print("TLE")
else:
  print(d)
      

Measured memory_bytes: 9044
import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n = int(input())
aa = {}
for j,i in enumerate(map(int,input().split())):
    if i in aa:
        aa[i].append(j)
    else:
        aa[i] = [j]
a = [0] * n
for k,i in enumerate(sorted(list(aa))):
    for j in aa[i]:
        a[j] = k+1


class SegmentTree:
    def __init__(self, a, func=max, one=-10 ** 18):
        self.logn = (len(a) - 1).bit_length()
        self.n = 1 << self.logn
        self.func = func
        self.one = one

        self.b = [self.one] * (2 * self.n - 1)
        for i, j in enumerate(a):
            self.b[i + self.n - 1] = j
        for i in reversed(range(self.n - 1)):
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_item(self, i):
        return self.b[i + self.n - 1]

    def update(self, index, x):
        i = index + self.n - 1
        self.b[i] = x
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def update_func(self, index, x):
        i = index + self.n - 1
        self.b[i] = self.func(self.b[i], x)
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_segment(self, l, r):
        l += self.n
        r += self.n
        s = self.one
        while l < r:
            if r & 1:
                r -= 1
                s = self.func(s, self.b[r - 1])
            if l & 1:
                s = self.func(s, self.b[r - 1])
                l += 1
            l >>= 1
            r >>= 1
        return s


e = [[] for _ in range(n)]
for _ in range(n - 1):
    aa, bb = [int(i) - 1 for i in input().split()]
    e[aa].append(bb)
    e[bb].append(aa)
seg = SegmentTree([0] * (max(a)+2), max, 0)
ans1 = [0] * n
ans1[0] = 1
ans2 = [0] * n
ans2[0] = 1


def dfs(i=0, r=-1):

    y = seg.get_segment(0, a[i])
    ans1[i] = y + 1
    ans2[i] = max(ans2[r], ans1[i])

    be = seg.get_item(a[i])
    seg.update_func(a[i], ans1[i])
    for j in e[i]:
        if j == r:
            continue
        dfs(j, i)
    seg.update(a[i], be)


dfs()
print("\n".join(map(str,(ans2))))


Measured memory_bytes: 544372
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 998244353;
const long double PI = 3.1415926;
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); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/

ll d[50][50];
ll c[600][600];

int main() {
    cin >> n >> m;
    REP(i, m) {
        REP(j, m) {
            cin >> d[i + 1][j + 1];
        }
    }
    REP(i, n) {
        REP(j, n) {
            cin >> c[i + 1][j + 1];
        }
    }
    vp v0, v1, v2;
    FOR(i, 1, n + 1) {
        FOR(j, 1, n + 1) {
            if ((i + j) % 3 == 0) {
                v0.push_back({ i,j });
            }
            if ((i + j) % 3 == 1) {
                v1.push_back({ i,j });
            }
            if ((i + j) % 3 == 2) {
                v2.push_back({ i,j });
            }
        }
    }

    vp vv0, vv1, vv2;
    FOR(j, 1, m + 1) {
        REP(i, v0.size()) {
            ans += d[c[v0[i].first][v0[i].second]][j];
        }
        vv0.push_back({ ans, j });
        ans = 0;
        REP(i, v1.size()) {
            ans += d[c[v1[i].first][v1[i].second]][j];
        }
        vv1.push_back({ ans, j });
        ans = 0;
        REP(i, v2.size()) {
            ans += d[c[v2[i].first][v2[i].second]][j];
        }
        vv2.push_back({ ans, j });
        ans = 0;
    }
    sort(ALL(vv0));
    sort(ALL(vv1));
    sort(ALL(vv2));
    ans = 0;
    cnt = INF;
    REP(i, vv0.size()) {
        REP(j, vv1.size()) {
            REP(k, vv2.size()) {
                ans = 0;
                if (vv0[i].second == vv1[j].second || vv0[i].second == vv2[k].second || vv1[j].second == vv2[k].second) {
                    continue;
                }
                ans += vv0[i].first + vv1[j].first + vv2[k].first;
                chmin(cnt, ans);
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 7008
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static readonly int[] dh = new int[4] { -1, 0, 1, 0 };
	public static readonly int[] dw = new int[4] { 0, -1, 0, 1 };

	public static void Main()
	{
		int H = GetInt();
		int W = GetInt();
		char[,] grid = new char[H, W];		
		int[] numWhite = new int[H * W];
		int[] numBlack = new int[H * W];
		for(int h = 0; h < H; h++)
		{
			string S = GetString();
			for(int w = 0; w < W; w++)
			{
				grid[h, w] = S[w];

				int v = h * W + w;
				if(grid[h, w] == '.')
					numWhite[v] = 1;
				else
					numBlack[v] = 1;
			}
		}

		var uf = new UnionFindEx(H * W, numWhite, numBlack);
		for(int h = 0; h < H; h++)
		{
			for(int w = 0; w < W; w++)
			{
				for(int i = 0; i < 4; i++)
				{
					int nh = h + dh[i];
					int nw = w + dw[i];
					if(nh < 0 || nh >= H || nw < 0 || nw >= W)
						continue;

					if(grid[h, w] == grid[nh, nw])
						continue;

					int v = h * W + w;
					int u = nh * W + nw;
					if(!uf.IsSame(v, u))
						uf.Merge(v, u);
				}
			}
		}

		var rootSet = new HashSet<int>();
		for(int h = 0; h < H; h++)
			for(int w = 0; w < W; w++)
				rootSet.Add(uf.Root(h * W + w));

		var rootList = rootSet.ToList();
		long ans = 0;
		foreach(int root in rootList)
			ans += (long)(uf.NumWhite(root)) * (long)(uf.NumBlack(root));
		
		Console.WriteLine(ans);
	}
}


public class UnionFindEx
{
	private int[] par = null;
	private int[] rank = null;
	private int[] m_numWhite = null;
	private int[] m_numBlack = null;
	
	public UnionFindEx(int n, int[] numWhite, int[] numBlack)
	{
		m_numWhite = numWhite;
		m_numBlack = numBlack;

		par = new int[n];
		rank = new int[n];
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}

	public bool IsSame(int x, int y)
	{
		return (Root(x) == Root(y));
	}

	public int Root(int x)
	{
		if(par[x] == x)
			return x;

		int r = Root(par[x]);
		par[x] = r;
		return r;
	}
	
	public bool Merge(int x, int y)
	{
		int rx = Root(x);
		int ry = Root(y);
		if(rx == ry)
			return false;
		
		if(rank[rx] < rank[ry])
		{
			int tmp = rx;
			rx = ry;
			ry = tmp;
		}
		else if(rank[rx] == rank[ry])
			rank[rx]++;

		par[ry] = rx;
		m_numWhite[rx] = m_numWhite[rx] + m_numWhite[ry];
		m_numBlack[rx] = m_numBlack[rx] + m_numBlack[ry];
		return true;
	}

	public int NumWhite(int x)
	{
		return m_numWhite[Root(x)];
	}

	public int NumBlack(int x)
	{
		return m_numBlack[Root(x)];
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 16864
n, p = map(int, input().split())
s = input()

def nC2(n):
    if n == 0:
        return 0
    return n*(n-1)//2

p_joyo = [] # 10^m % p は p_joyo[m]に対応
r = 1
for i in range(n):
    p_joyo.append(r)
    r = r*10 % p

if p != 2 and p != 5:
    u = []
    r = int(s[n-1])%p
    for i in range(1,n):
        u.append(r)
        j = n-i-1
        r = (r + int(s[j])*p_joyo[i])%p
    u.append(r)
    onaji = {}
    for i in u:
        if not i in onaji:
            onaji[i] = 1
        else:
            onaji[i] += 1
    ans = 0
    for key, r in onaji.items():
        ans += nC2(r)
        if key == 0:
            ans += r
    print(ans)

elif p == 2:
    ans = 0
    for i in range(n):
        if int(s[i]) in [0,2,4,6,8]:
            ans += i+1
    print(ans)

else:
    ans = 0
    for i in range(n):
        if int(s[i]) in [0,5]:
            ans += i+1
    print(ans)


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

using P = pair<int,int>;
int n;

int dfs(vector<int> &won,vector<int> &lost,vector<P> &vp,int depth){
    if(depth == (int)vp.size()){
        int w = won[0];
        rep(i,n){
            if(won[i] != w) return 0;
        }
        return 1;
    }
    rep(i,n){
        if(won[i]  > n/2) return 0;
        if(lost[i] > n/2) return 0;
    }

    int x = vp[depth].first;
    int y = vp[depth].second;
    int res = 0;
    rep(_,2){
        won[x]++, lost[y]++;
        res += dfs(won,lost,vp,depth+1);
        won[x]--, lost[y]--;
        swap(x,y);
    }
    return res;
}

int main(void){
    while(cin>>n, n){
        int table[9][9] = {};
        int m;
        cin>>m;
        vector<int> won(n),lost(n);
        rep(i,m){
            int x,y;
            cin>>x>>y;
            x--,y--;
            won[x]++, lost[y]++;
            table[x][y] = +1;
            table[y][x] = -1;
        }
        vector<P> vp;
        rep(i,n)rep(j,i){
            if(table[i][j] == 0) vp.push_back(P(i,j));
        }
        cout<<dfs(won,lost,vp,0)<<endl;
    }
}



Measured memory_bytes: 3104
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
  int a, b, c, d; //かっている数//最大100
  string s, t;

  cin >> s;
  bool ans =true;
  if (s[0]!='A')ans = false;
  int count=0;
  for(int i=2;i<s.size()-1;i++){
    if (s[i]=='C')count++;
  }
  if (count!=1)ans=false;

  for(int i=1;i<s.size();i++){
    if (!(s[i]>='a' && s[i]<='z')) {
      if (i>=2 && i<=s.size()-2)continue;
      ans=false;
    }
  }


  cout << (ans? "AC":"WA");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    char c;
    cin>>c;
    if(c=='A'){cout<<'T'<<endl;}
    else if(c=='T'){cout<<'A'<<endl;}
    else if(c=='C'){cout<<'G'<<endl;}
    else{cout<<'C'<<endl;}
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(void)
{
	int H, W;
	int i, j;
	
	while(1){
		scanf("%d %d", &H, &W);
		if(H==0 && W==0){
			break;
		}
		
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){
				if(i==0 || i==H-1){
					printf("#");
				}
				if(i>0 && i<H-1){
					if(j==0 || j==W-1){
						printf("#");
					}else if(j>0 && j<W-1){
						printf(".");
					}
				}
				
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}
					

Measured memory_bytes: 572
import java.util.Arrays;
import java.util.Scanner;
class Player implements Comparable<Player>{
	int party;
	int num;
	String time;
	Player(int p,int n,String t){
		this.party = p;
		this.num = n;
		this.time = t;
	}
	@Override
	public int compareTo(Player o) {
		// TODO Auto-generated method stub
		return this.time.compareTo(o.time);
	}	
}
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Player[] person = new Player[24];
		int[][] rank = new int[3][8];
		int[] cnt = new int[3]; 
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < 8;j++){
				person[i*8+j] = new Player(i,sc.nextInt(),sc.next());
			}
		}
		Arrays.sort(person);
		for(int i = 0;i < 24;i++){
			rank[person[i].party][cnt[person[i].party]] = i;
			cnt[person[i].party]++;
		}
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < 2;j++){
				System.out.println(person[rank[i][j]].num+" "+person[rank[i][j]].time);
				person[rank[i][j]].time = "999";
			}
		}
		Arrays.sort(person);
		for(int j = 0;j < 2;j++){
			System.out.println(person[j].num+" "+person[j].time);
		}
		
	}
}

Measured memory_bytes: 26176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef vector<ll> vecll;
typedef vector<ld> vecld;
typedef vector<vector<ll> > matll;
typedef vector<vector<ld> > matld;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

bool my_comp(pll a, pll b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}

	return a.second < b.second;
}

int main() {

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

	return 0;
}


Measured memory_bytes: 256
(a,b,c)=gets.split.map(&:to_i)
k=gets.to_i


r1 = (0...1000).to_a.index{|i| a < b*2**i} 
r2 = (0...1000).to_a.index{|i| b*2**r1 < c*2**i} 



if r1+r2 <= k
    print 'Yes'
else
    print 'No'
end

Measured memory_bytes: 14324
loop do
    t, num = gets.split.map(&:to_i)
    break if t == 0 && num == 0
    d = num.to_s.length - 1
    num = num.to_s
    max = -1
    maxp = []
    twice = false
    (1 << d).times do |bit|
        cur = 1 << (d - 1)
        cur_s = 0
        sum = 0
        parts = Array.new
        d.times do |i|
            if bit & cur != 0
                sum += num[cur_s..i].to_i
                parts.push(num[cur_s..i].to_i)
                cur_s = i + 1
            end
            cur = cur >> 1
        end
        parts.push(num[(cur_s)...num.length].to_i)
        sum += num[(cur_s)...num.length].to_i
        if sum > max && sum <= t
            max = sum
            maxp = parts
            twice = false
        elsif sum == max
            twice = true
        end
    end
    puts max == -1 ? "error" : (twice ? "rejected" : "#{max} #{maxp * " "}")
end

Measured memory_bytes: 6128
#include <stdio.h>

int main (void)
{
  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  if (a == b) {
    printf("%d", c);
  } else {
    if (a == c) {
      printf("%d", b);
    } else {
      printf("%d", a);
    }
  }

  return 0;
}

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



namespace CSharpSample01
{
    
    class Program
    {
        
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] m = { 25, 10, 5, 1 };
            int cnt = 0;
            
            for(int i = 0; i < 4; i++)
            {
                cnt += n / m[i];
                n %= m[i];
                if (n == 0) break;
            }

            Console.WriteLine(cnt);
        }
    }

}


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

int main(){
  int n, t[50];
  string x, s[50];
  int flag=0;
  int ans=0;

  cin >> n;
  for(int i;i<n;i++){
    cin >> s[i];
    cin >> t[i];
  }
  cin >> x;

  for(int i=0;i<n;i++){
    if(flag==1){
      ans+=t[i];
    }
    if(x==s[i]){
      flag=1;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
a = int(input())
if (a >= 400) and (a <= 599) :
    print(8)
if (a >= 600) and (a <= 799) :
    print(7)
if (a >= 800) and (a <= 999) :
    print(6)
if (a >= 1000) and (a <= 1199) :
    print(5)
if (a >= 1200) and (a <= 1399) :
    print(4)
if (a >= 1400) and (a <= 1599) :
    print(3)
if (a >= 1600) and (a <= 1799) :
    print(2)
if (a >= 1800) and (a <= 1999) :
    print(1)

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
int s[2010][2010], r[2010][2010], c[2010][2010];
int cum_s[2010][2010], cum_r[2010][2010], cum_c[2010][2010];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, q; cin >> n >> m >> q;
    for (int i = 0; i < n; i++) {
        string t; cin >> t;
        for (int j = 0; j < m; j++) {
            s[i][j] = t[j] - '0';
            if (s[i][j]) {
                if (i && s[i-1][j]) r[i][j]++;
                if (j && s[i][j-1]) c[i][j]++;
            } 
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cum_s[i+1][j+1] = cum_s[i+1][j] + s[i][j];
            cum_r[i+1][j+1] = cum_r[i+1][j] + r[i][j];
            cum_c[i+1][j+1] = cum_c[i+1][j] + c[i][j];
        }
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            cum_s[i+1][j] += cum_s[i][j];
            cum_r[i+1][j] += cum_r[i][j];
            cum_c[i+1][j] += cum_c[i][j];
        }
    }
    for (int i = 0; i < q; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int sum_s = cum_s[x2][y2] - cum_s[x2][y1-1] - cum_s[x1-1][y2] + cum_s[x1-1][y1-1];
        int sum_r = cum_r[x2][y2] - cum_r[x2][y1-1] - cum_r[x1][y2] + cum_r[x1][y1-1];
        int sum_c = cum_c[x2][y2] - cum_c[x2][y1] - cum_c[x1-1][y2] + cum_c[x1-1][y1];
        cout << sum_s - sum_r - sum_c << "\n";
        
    }
    return 0;
}

Measured memory_bytes: 96256
#include<stdio.h>

int main()
{
  int i,j,k,l,m,n;
  int a[100][100];

  scanf("%d",&n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      a[i][j] = 0;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d %d",&k,&l);
    k--;
    for(j=0; j<l; j++){
      scanf("%d",&m);
      m--;
      a[k][m] = 1;
    }
  }

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

  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main(){
	uint16_t A, B;
	cin >> A >> B;
	uint16_t res = 0;

	if(A == B)
		res = A + B;
	else if(A > B)
		res = (2 * A) - 1;
	else
		res = (2 * B) - 1;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define all(c) (c).begin(),(c).end()
#define f first
#define s second
#define INF (1<<29)

using namespace std;

typedef pair<int,int>pii;
typedef pair<pii,pii> P;

string s;
int h,w;
char g[51][51],tmp[51][51];
map<char,P>v;

void make(string s){
	fill(tmp[0],tmp[51],'.');
	for(int i=0;i<s.size();i++){
		for(int j=v[s[i]].f.s;j<=v[s[i]].s.s;j++){
			for(int k=v[s[i]].f.f;k<=v[s[i]].s.f;k++){
				tmp[j][k]=s[i];
			}
		}
	}
}

bool ok(){
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(g[i][j]!=tmp[i][j])return false;
		}
	}
	return true;
}

int main(void){

	int tc;
	cin >> tc;

	while(tc--){
		cin >> h >> w;
		for(int i=0;i<h;i++)cin >> g[i];

		s.clear();
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				if(g[i][j]!='.')s+=g[i][j];

		sort(all(s));
		s.erase(unique(all(s)),s.end());
		v.clear();
		for(int i=0;i<s.size();i++){
			int xmn=INF,ymn=INF,xmx=-1,ymx=-1;
			for(int j=0;j<h;j++){
				for(int k=0;k<w;k++){
					if(g[j][k]==s[i]){
						xmn=min(xmn,k);
						ymn=min(ymn,j);
						xmx=max(xmx,k);
						ymx=max(ymx,j);
					}
				}
			}
			v[s[i]]=P(pii(xmn,ymn),pii(xmx,ymx));
		}

		bool fg=false;
		do{
			make(s);
			if(ok()){fg=true;break;}
		}while(next_permutation(all(s)));

		if(fg)cout << "SAFE" << endl;
		else cout << "SUSPICIOUS" << endl;
	}

	return 0;
}

Measured memory_bytes: 1232
def quick_sort(seq, left, right):
  if left == right:
    return 0
  mid = (left + right)//2
  pivot = seq[mid]
  L = left
  R = right
  while True:
    if seq[L] >= pivot and seq[R] <= pivot:
      seq[L], seq[R] = seq[R], seq[L]
      L += 1
      R -= 1
    elif seq[L] > pivot:
      R -= 1
    elif seq[R] < pivot:
      L += 1
    else:
      L += 1
      R -= 1
    if L >= R:
      break
  quick_sort(seq,left,R)
  quick_sort(seq,L,right)

N = int(input())
vec = list(map(int,input().split()))
quick_sort(vec,0,N-1)
ans = vec[0]
for i in range(N-1):
  ans = (ans + vec[i+1])/2
print(ans)




Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 924844033, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head


const int N = 2e3+10;
int n,k,vis[2*N],dp[2*N][N][2],fac[N];
void add(int &a, int b) {a+=b;if(a>=P)a-=P;}

int main() {
	fac[0]=1;
	REP(i,1,N-1) fac[i]=(ll)fac[i-1]*i%P;
	scanf("%d%d",&n,&k);
	int cnt = 0;
	//分别对2k条链进行dp, 
	REP(i,1,k) {
		for(int j=i;j<=n;j+=k) vis[++cnt]=i!=j;
		for(int j=i;j<=n;j+=k) vis[++cnt]=i!=j;
	}
	dp[0][0][0] = 1;
	REP(i,1,2*n) REP(j,0,min(n,i)) {
		add(dp[i][j][0],dp[i-1][j][0]);
		add(dp[i][j][0],dp[i-1][j][1]);
		if (vis[i]) add(dp[i][j+1][1],dp[i-1][j][0]);
	}
	int ans = 0;
	REP(i,0,n) {
		int t = (dp[2*n][i][0]+dp[2*n][i][1])%P;
		if (i&1) ans=(ans-(ll)t*fac[n-i])%P;
		else ans=(ans+(ll)t*fac[n-i])%P;
	}
	if (ans<0) ans += P;
	printf("%d\n", ans);
}








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

#define M_PI       3.14159265358979323846

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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;


//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 SQ(a) ((a)*(a))
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


struct Edge {
    int to, from;
    ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

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

    
    int M, D; cin >> M >>D;

    int cnt=0;
    for(int i=1; i<=M; ++i){
        for(int j=1; j<=D; ++j){
            int a = j/10, b = j%10;
            if(a >= 2 && b >= 2 && a*b==i) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;

}

Measured memory_bytes: 256
from itertools import accumulate

n, c = map(int, input().split())
xxx = list(map(int, input().split()))
xxx.append(0)
xxx.reverse()
acc = list(accumulate(xxx))
coe = list(range(3, 4 + 2 * n, 2))
coe[0] = 5
ans = float('inf')
for k in range(1, (n + 1) // 2 + 1):
    tmp = k * c
    for i, b in zip(range(0, n, k), coe):
        tmp += (acc[min(i + k, len(acc) - 1)] - acc[i]) * b
    ans = min(ans, tmp)

print(ans + n * c)


Measured memory_bytes: 28740
#include <stdio.h>

int pattern(int x)
{
	if(x==0) return 1;
	if(x==1) return 2;
	if(x==2) return 3;
	if(x==3) return 5;
	if(x==4) return 8;
	if(x==5) return 13;
	if(x==6) return 21;
	if(x<0||x>6) return 1;
	
	printf("error");
	return 0;
}

int main(void)
{
	//変数の宣言
	int h,w,k;
	long int now[10];
	//intだと桁あふれするのであとでlongに直す
	long int kako[10];
	int left,right;
	int i,j;
	
	
	//データの読み込み
	scanf("%d %d %d",&h,&w,&k);
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(j=0;j<10;j++){
		kako[j]=0;
	}
	kako[0]=1;
	
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			left=j-1;
			right=w-j-2;
			now[j]=kako[j]*pattern(left)*pattern(right);
			if(j!=0) now[j]=now[j]+kako[j-1]*pattern(left-1)*pattern(right);
			if(j!=w) now[j]=now[j]+kako[j+1]*pattern(left)*pattern(right-1);
		}
		for(j=0;j<w;j++){
			kako[j]=(now[j]%1000000007);
		}
		
//		printf("%d回目",i);
		for(j=0;j<w;j++){
//			printf("now[%d]=%ld",j,kako[j]);
		}
//		printf("\n");
	}
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",kako[k-1]);
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <climits>
#include <vector>
#include <string>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

const int len = 1000010;
int b,c,n;
int s[len],a[len];

int main() {
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> s[i];
	}
	if (n%2 == 0)
	{
        int k = 1;
		for (int i=n;i>=1;i--) {
		if (i%2 == 0) {a[k] = s[i];k++;}
	}
	for (int i=1;i<=n;i++) {
		if (i%2) {a[k] = s[i];k++;}
	}
	for (int i=1;i<k;i++) {
		cout << a[i] << ' ';
	}
	}
	else {
		int k = 1;
		for (int i=n;i>=1;i--) {
		if (i%2) {a[k] = s[i];k++;}
	}
	for (int i=1;i<=n;i++) {
		if (i%2 == 0) {a[k] = s[i];k++;}
	}
	for (int i=1;i<k;i++) {
		cout << a[i] << ' ';
	}
	}
    return 0;
}

Measured memory_bytes: 7040
using System;

namespace C___Build_Stairs
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver() ? "Yes" : "No");
        }
        static bool solver()
        {
            var N = int.Parse(Console.ReadLine());
            var Hi = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            for (int i = N - 1; i > 0; i--) if (Hi[i - 1] > Hi[i]) Hi[i - 1]--;
            for (int i = 0; i < N - 1; i++) if (Hi[i + 1] < Hi[i]) return false;
            return true;
        }
    }
}


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

typedef long long int ll;
typedef pair<int, int> P;

const int N = 1e5, M = 1e5;
int arr[N] = { 0 };
P rep[N];

int main() {
	int n, m, b, c, i, j;
	ll ans = 0;
	cin >> n >> m;
	for(i = 0;i < n;++i) {
		cin >> arr[i];
		ans += arr[i];
	}
	sort(arr, arr + n);
	// for(i = 0;i < n;++i) {
	// 	cout << arr[i] << endl;
	// }
	for(i = 0;i < m;++i) {
		cin >> b >> c;
		rep[i] = make_pair(c, b);
	}
	sort(rep, rep + m, greater<P>());
	// for(i = 0;i < m;++i) {
	// 	cout << rep[i].first << ' ' << rep[i].second << endl;
	// }
	for(i = 0, j = 0;i < n && j < m;) {
		if(rep[j].second == 0) {
			++j;
		}
		else if(rep[j].first - arr[i] <= 0) {
			break;
		}
		else {
			ans += rep[j].first - arr[i];
			++i;
			rep[j].second -= 1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
cout<<fixed<<setprecision(10);

int N,M;
  cin >>N>>M;
  
  vector<int> A(N);
  for (int i=0;i<N;i++){
    cin >> A.at(i);
  }
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int sum=0;
  for (int i=0;i<N;i++){
    sum += A.at(i);
  }
  if (A.at(M-1)*4*M>=sum) cout <<"Yes";
  else cout << "No";
  
	
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	string s, t;
	cin >> s >> t;
	if (s.size() + 1 != t.size()) {
		cout << "No" << endl;
	} else {
		for (size_t i = 0; i < s.size(); i++) {
			if (s[i] != t[i]) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int 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;
}

struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降はMODが素数のみ
  mint inv() const {
    return pow(MOD - 2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

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


  vector<int> x(N);
  rep(i, N) {
    cin >> x[i];
  }

  if (N == 2) {
    cout << (x[1] - x[0]) << endl;
    return 0;
  }

  N--;

  vector<mint> F(N + 5);
  F[0] = 1;
  rep(i, N + 3) {
    F[i + 1] = F[i] * (i + 1);
  }

  vector<mint> stir(N + 5);
  stir[0] = 0;
  rep(i, N + 3) {
    stir[i + 1] = stir[i] * (i + 1) + F[i];
  }


  vector<mint> fact(N);
  fact[N - 1] = 1;
  fact[N - 2] = N;
  repr(i, N - 3, 0) {
    fact[i] = fact[i + 1] * (i + 2);
  }

  vector<mint> k(N);
  rep(i, N) {
    k[i] = stir[i + 1] * fact[i];
  }

  // rep(i, N) {
  //   cout << k[i].x << endl;
  // }

  mint ans = 0;
  rep(i, N) {
    ans += k[i] * (x[i + 1] - x[i]);
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(void)
{
	int num;
	char str[256];
	
	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d",&num);
	
	fgets(str,sizeof(str),stdin);
	
	for(int i=0;i<num;i++)
	{
		printf("%c",str[i]);
		printf("%c",str[i+num+1]);
	}
	
	return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        int answer = 0;
        for (int i = 1; i <= n; i += 2)
        {
            if (GetDivisorCount(i) == 8)
            {
                answer++;
            }
        }

        Console.WriteLine(answer);
    }

    private static int GetDivisorCount(int n)
    {
        int count = 0;
        for (int i = 1; i <= n; i++)
        {
            if (n % i == 0)
            {
                count++;
            }
        }
        return count;
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
#define MAXN 8020

using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int 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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
bool dp_x[MAXN][MAXN * 2] = {false};
//(i 回目の x 軸方向の移動の後に x 座標が x になっているようにできるか)
bool dp_y[MAXN][MAXN * 2] = {false};
// plus とminus を考えるので二倍

int main() {
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;
    //はじめは00
    vector<int> t;
    int cnt = 0;
    REP(i, s.size()) {
        if(s[i] == 'T') {
            // change direction
            if(cnt != 0) {
                t.push_back(cnt);
            }
            t.push_back(0);
            cnt = 0;
        } else {
            cnt++;
            if(i == s.size() - 1) {
                t.push_back(cnt);
            }
        }
    }
    // print(t);
    dp_x[0][8000] = true; //これは(0,0)を示してる
    dp_y[0][8000] = true; //これも(0,0)を示してる
    bool xy = true;       // trueならx軸について見ている
    bool flag =
        false; //文字列の最初がFのときはx軸の正の方向にしか動けないことに注意する。
    int cnt_x = 0;
    int cnt_y = 0;
    REP(i, t.size()) {
        if(t[i] == 0) {
            xy = !xy;
        } else if(xy) {
            // x軸について考える
            cnt_x++;
            for(int j = 0; j < MAXN * 2; j++) {
                if(dp_x[cnt_x - 1][j]) {
                    if(j + t[i] < MAXN * 2)
                        dp_x[cnt_x][j + t[i]] = true;
                    if(j - t[i] >= 0 && flag)
                        dp_x[cnt_x][j - t[i]] = true;
                }
            }
        } else {
            cnt_y++;
            for(int j = 0; j < MAXN * 2; j++) {
                if(dp_y[cnt_y - 1][j]) {
                    if(j + t[i] < MAXN * 2)
                        dp_y[cnt_y][j + t[i]] = true;
                    if(j - t[i] >= 0)
                        dp_y[cnt_y][j - t[i]] = true;
                }
            }
        }
        if(!flag)
            flag = true;
    }
    cout << ((dp_x[cnt_x][x + 8000] && dp_y[cnt_y][y + 8000]) ? "Yes" : "No")
         << endl;
    return 0;
}

Measured memory_bytes: 64384
#include <bits/stdc++.h>
#define maxn 2000005
using namespace std;
char str1[maxn],str2[maxn];
int Next[maxn],vis[maxn],kmpcount;
struct Node{
    int to,next;
}q[maxn<<1];
int head[maxn],cnt=0,inde[maxn];
void add_edge(int from,int to){
    q[cnt].to=to;
    q[cnt].next=head[from];
    head[from]=cnt++;
}
void init(){
    memset(head,-1,sizeof(head));
    cnt=0;
}
void kmp_pre(char x[],int m,int next[]){
    int i,j;
    j=next[0]=-1;
    i=0;
    while(i<m){
        while(j!=-1&&x[i]!=x[j]) j=next[j];
        next[++i]=++j;
    }
}
int kmp(char x[],int m,char y[],int n){
    int i,j;
    int ans=0;
    kmp_pre(x,m,Next);
    i=j=0;
    while(i<n){
        while(j!=-1&&y[i]!=x[j]) j=Next[j];
        i++,j++;
        if(j>=m){
            ans++;
            j=Next[j];
            vis[i-m]=1;
        }
    }
    return ans;
}
vector<int>vec;
int dp[maxn];
bool topsort(int n){
    int cnt=0;
    queue<int>que;
    for(int i=0;i<n;i++) if(!inde[i]&&vis[i])que.push(i);
    while(!que.empty()){
        int x=que.front();
        vec.push_back(x);
        cnt++;
        que.pop();
        for(int i=head[x];i!=-1;i=q[i].next){
            int to=q[i].to;
            inde[to]--;
            if(inde[to]==0) que.push(to);
        }
    }
    return kmpcount==cnt;
}
int main()
{
    scanf("%s%s",str1,str2);
    int len1=strlen(str1),len2=strlen(str2);
    int Len1=len1,Len2=len2;
    while(Len2>0){
        for(int i=0;i<Len1;i++){
            str1[len1++]=str1[i];
        }
        Len2-=Len1;
    }
    str1[len1]='\0';
    kmpcount=kmp(str2,len2,str1,len1);
    init();
    for(int i=0;i<Len1;i++){
        int k=(i+len2)%Len1;
        if(vis[k]&&vis[i]) inde[k]++,add_edge(i,k);
    }
    if(!topsort(len1)) puts("-1");
    else{
        for(int i=0;i<vec.size();i++){
            int x=vec[i];
            if(dp[x]==0) dp[x]=1;
            for(int i=head[x];i!=-1;i=q[i].next){
                int to=q[i].to;
                dp[to]=max(dp[to],dp[x]+1);
            }
        }
        int res=0;
        for(int i=0;i<vec.size();i++){
            res=max(res,dp[vec[i]]);
        }
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 41196
#include <stdio.h>

typedef struct {
	int x,y;
} xy_t;

int width;
char visited[100][100];
xy_t floor_map[100][100];

int main(void) {
	int i,j,k,l;
	int x,y,nx,ny;
	int count;
	while(1) {
		scanf("%d",&width);
		if(width==0)break;
		for(i=0;i<width;i++) {
			for(j=0;j<width;j++) {
				scanf("%d%d",&floor_map[i][j].x,&floor_map[i][j].y);
				visited[i][j]=0;
			}
		}
		count=0;
		for(i=0;i<width;i++) {
			for(j=0;j<width;j++) {
				if(!visited[i][j]) {
					x=j;y=i;
					while(!visited[y][x]) {
						visited[y][x]=2;
						nx=floor_map[y][x].x;
						ny=floor_map[y][x].y;
						x=nx;y=ny;
					}
					if(visited[y][x]==2)count++;
					for(k=0;k<width;k++) {
						for(l=0;l<width;l++) {
							if(visited[k][l]==2)visited[k][l]=1;
						}
					}
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 500
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

int n, cnt[16], ans, now, f[101000], g[77777];
vector<pii>vec;
void U(int &x,int y){ x=min(x,y); }

int main(){
  memset(g,33,sizeof g); g[0]=0;
  for (int i=2;i<(1<<16);i+=2){
    int x=0, c=-1;
    for (int j=1;j<16;++j)
      if (i>>j&1)
        x^=j, ++c;
    if (!x) vec.push_back((pii){i,c});
  }
  
  for (int i=0;i<16;++i)
    for (int x=0;x<(1<<16);x+=2) if (g[x]==i){
      for (auto o:vec)
        U(g[x^o.fi],i+o.se);
    }
  
  cin>>n;
  int x, y, z;
  for (int i=1;i<n;++i){
    scanf("%d%d%d",&x,&y,&z); f[++x]^=z; f[++y]^=z;
  }
  for (int i=1;i<=n;++i) ++cnt[f[i]];
  for (int i=1;i<16;++i){
    ans+=cnt[i]>>1;
    now|=(cnt[i]&1)<<i;
  }
  cout<<ans+g[now];
}

Measured memory_bytes: 1024