akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

const int N = 25;
int g[N][N];

int bfs(int n, int s, int G){
    int dis[N]; //?????¢
    queue<int> q; //?¨??????????????????\??????
    rep(i,N) dis[i] = INF;

    dis[s] = 0;
    q.push(s);

    int u;
    while(!q.empty()){
        u = q.front(); q.pop();
        rep(v,n){
            if(dis[v] > dis[u] + g[u][v]){
                dis[v] = dis[u] + g[u][v]; //??°???????????±??? 
                q.push(v);
            }
        }
    }
    return dis[G];
}

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

    rep(i,N) rep(j,N) g[i][j] = INF;
    char k;
    rep(i,m){
        int a, b, c, d;
        cin >> a >>k>> b>>k >> c>>k >> d;
        a--; b--;
        g[a][b] = c;
        g[b][a] = d;
    }

    int s, g, v, p;
    cin >> s >>k>> g >> k>>v >>k>> p;
    s--; g--;

    int a = bfs(n,s,g);
    int b = bfs(n,g,s);
    cout << v - p - a - b << endl;

}

Measured memory_bytes: 3112
SA=input()
SB=input()
SC=input()
cards=[]
cards.append(SA[0])
SA=SA[1:]
ans=''
while len(SA)>0 or len(SB)>0 or len(SC)>0:
  if cards[-1]=='a':
    if len(SA)==0:
      ans='A'
      break
    else:
      cards.append(SA[0])
      SA=SA[1:]
  elif cards[-1]=='b':
    if len(SB)==0:
      ans='B'
      break
    else:
      cards.append(SB[0])
      SB=SB[1:]
  else:
    if len(SC)==0:
      ans='C'
      break
    else:
      cards.append(SC[0])
      SC=SC[1:]
print(ans)

Measured memory_bytes: 3064
from bisect import bisect_left,bisect_right
n,k=map(int,input().split())
a=list(map(int,input().split()))
inf=10**20
a.sort()
mc=zc=pc=0
m=[]
p=[]
for i in a:
  if i<0:
    mc+=1
    m.append(i)
  elif i==0:
    zc+=1
  else:
    pc+=1
    p.append(i)
if mc*pc>=k:
  #ans<0
  for i in range(len(m)):m[i]*=-1
  k=mc*pc-k+1
  m=m[::-1]
  p=[0]+p
  ng=0
  ok=10**19+7
  mi=10**19+7
  while ng+1!=ok:
    ma=0
    mid=(ng+ok)//2
    co=0
    j=len(p)-1
    for i in m:
      while p[j]*i>mid:j-=1
      co+=j
      ma=max(ma,p[j]*i)
    if co<k:ng=mid
    else:
      ok=mid
      mi=min(mi,ma)
  print(-mi)
elif mc*pc+zc*(zc-1)//2+zc*(pc+mc)>=k:
  #ans=0
  print(0)
else:
  k-=mc*pc+zc*(zc-1)//2+zc*(pc+mc)
  for i in range(len(m)):m[i]*=-1
  m=m[::-1]
  m=[0]+m
  p=[0]+p
  ng=0
  ok=10**19+7
  mi=10**19+7
  while ng+1!=ok:
    ma=0
    mid=(ok+ng)//2
    co=0
    jjj=0
    j=len(p)-1
    pok=[]
    for i in range(len(p)):
      if p[i]==0:continue
      while p[j]*p[i]>mid:j-=1
      co+=max(0,j-i)
      ma=max(ma,p[j]*p[i])
    j=len(m)-1
    for i in range(len(m)):
      if m[i]==0:continue
      while m[j]*m[i]>mid:j-=1
      co+=max(0,j-i)
      ma=max(ma,m[j]*m[i])
    if co<k:ng=mid
    else:
      ok=mid
      mi=min(mi,ma)
  print(mi)

Measured memory_bytes: 101764
from operator import itemgetter

N, M = map(int, input().split())
in_hand = list(map(int, input().split()))
in_hand.sort()

change_list = []

for line in range(M):
    change_count, change_number = map(int, input().split())

    change_list.append([change_count, change_number])


change_list.sort(key=itemgetter(1), reverse=True)

index = 0
try:
    for change in change_list:
        for i in range(change[0]):
            if in_hand[i+index] < change[1]:
                in_hand[i+index] = change[1]
            else:
                break
        else:
            index += change[0]
            continue
        break
except:
    pass

print(sum(in_hand))


Measured memory_bytes: 25652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)

int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,Q;
    ll s[100010], t[100010], x[100010];
    cin >> A >> B >> Q;
    rep(i,0,A) cin >> s[i];
    rep(i,0,B) cin >> t[i];
    rep(i,0,Q) cin >> x[i];
    rep(i,0,Q){
        ll ans = INF;
        ll p1 = lower_bound(s, s+A, x[i]) - s;
        ll p2 = lower_bound(t, t+B, x[i]) - t;
        if(p1 < A && p2 < B){
            ans = min(ans, max(s[p1] - x[i], t[p2] - x[i]));
        }
        if(p1 >= 1 && p2 >= 1){
            ans = min(ans, max(x[i] - s[p1-1], x[i] - t[p2-1]));
        }
        if(p1 < A && p2 >= 1){
            ans = min(ans, s[p1] - t[p2-1] + min(s[p1]-x[i], x[i]-t[p2-1]));
        }
        if(p1 >= 1 && p2 < B){
            ans = min(ans, t[p2] - s[p1-1] + min(t[p2]-x[i], x[i]-s[p1-1]));
        }
        print(ans);
    }


}


Measured memory_bytes: 3712
#動的計画法
#A 問題 - Frog 1 
#部分的WAになる理由？
n = int(input())
h = list(map(int,input().split()))
dp = [float("INF")]*n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(n-2):
    dp[i+2] = min((dp[i+1]+abs(h[i+2]-h[i+1]),(dp[i]+abs(h[i+2]-h[i]))))
print(dp[n-1])

Measured memory_bytes: 13928
import Data.List
import Text.Printf

main = do
    ss <- getContents
    let l1 = map (\x->read ("("++x++")")::(Int,Int)) $ takeWhile (\l->l/="") $ lines ss
    let l2 = map (\x->read ("("++x++")")::(Int,Int)) $ drop ((length l1)+1) $ lines ss
    let l1' = map fst l1
    let l2' = map fst l2
    let l12' = l1' ++ l2'
    let comp = sort $ nub $ filter (\i->elem i l2') l1'
    let ans = map (\i->(i,(length $ filter (==i) l12'))) comp
    mapM_ (\x->printf "%d %d\n" (fst x) (snd x)) ans

Measured memory_bytes: 4120
#include<stdio.h>
int
main (void)
{
  double a, b, c, d, e, f;
  double x, y, m;
  while (EOF != scanf ("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f))
    {
      m = a * e - b * d;
      x = c * e - b * f;
      y = a * f - c * d;
      if (x == 0)
	{
	  if (y == 0)
	    printf ("0.000 0.000\n");
	  else
	    printf ("0.000 %.3f\n", y / m);
	}
      else
	{
	  if (y == 0)
	    printf ("%.3f 0.000\n", x / m);
	  else
	    printf ("%.3f %.3f\n", x / m, y / m);

	}
    }
  return 0;
}

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

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

    int ans = 1;
    for (int i = 1; i < S.size(); i++)
    {
        if (S[i] != S[i - 1])
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

//typedef vector<pair<int, int>> Numbers;
int n,x,y;

int main(){
    cin >> n >> x >> y;
    //Numbers numbers;
    vector<int> nums(n);
    for(int i = 1; i < n+1; i ++){
        for(int j = i+1; j < n+1; j++){
            nums[min({j-i, abs(x-i)+abs(j-y)+1, abs(y-i)+abs(j-x)+1})]++;
        }
    }
    //あとでキューでも早さがどうなるか試してみる。

    int cnt;
    for(int j = 1; j < n; j++){
        cout << nums[j] << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main(){
  string S,T;
  cin >> S >> T;

  string res = "";

  ll Smin = min(S.size(), T.size());

  sort(S.begin(), S.end());
  sort(T.begin(), T.end(),greater<ll>());

  REP(i, Smin)
  {
    if(S[i] - '0' < T[i] - '0')
    {
      res = "Yes";
      break;
    }
    else if(S[i] - '0' == T[i] - '0')continue;
    else
    {
      res = "No";
      break;
    }
  }

  if(res == "")
  {
    //Sのほうが短いなら
    if(S.size() < T.size())
    {
      res = "Yes";
    }
    else
    {
      res = "No";
    }
  }
  cout << res << endl;

  return 0;
}

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	int N, a[21], b[21], c[21];
	cin >> N;
	REP(i, N) cin >> a[i];
	for(int i = 1; i <= N; i++) cin >> b[i];
	for(int i = 1; i <= N-1; i++) cin >> c[i];
	int bef = 99;
	REP(i, N){
		int now = a[i];
		ans += b[now];
		if(i > 0 && bef + 1 == now) ans += c[bef];
		bef = now;
	}
    cout << ans << endl;
}

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

int main() {
  int LA = 0;
  int LB = 0;
  int LC = 0;
  int LD = 0;
  int RA = 0;
  int RB = 0;
  int RC = 0;
  int RD = 0;

  float l, r;
  while(cin >> l) {
    cin >> r;
    if(l >= 1.1) LA++;
    else if(l >= 0.6) LB++;
    else if(l >= 0.2) LC++;
    else LD++;
    if(r >= 1.1) RA++;
    else if(r >= 0.6) RB++;
    else if(r >= 0.2) RC++;
    else RD++;
  }
  cout << LA << ' ' << RA << '\n'
       << LB << ' ' << RB << '\n'
       << LC << ' ' << RC << '\n'
       << LD << ' ' << RD << endl;
  return 0;
}


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
     
int main(){
  int a,b,c,d,l,A,B;
  cin>>l>>a>>b>>c>>d;
  if(a%c==0){
    A=a/c;
  }else{
    A=a/c+1;
  }
  if(b%d==0){
    B=b/d;
  }else{
    B=b/d+1;
  }
  if(A>B){
    cout<<l-A<<endl;
  }else{
    cout<<l-B<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int N;
    cin >> N;
    map<Pii, int> mp;
    rep(i, N) {
        int x, y, w;
        cin >> x >> y >> w;
        mp[Pii(x, y)] += w;
        mp[Pii(x + 1, y)] += w;
        mp[Pii(x, y + 1)] += w;
        mp[Pii(x + 1, y + 1)] += w;
    }

    int a = -1;
    for (auto p : mp) {
        a = max(a, p.second);
    }
    cout << a << " / 1" << endl;
}

Measured memory_bytes: 28176
N,M = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(N)]
points = [list(map(int, input().split())) for _ in range(M)]

ans = []
for i in range(N):
  distances = []
  for j in range(M):
    d_x = abs(students[i][0] - points[j][0])
    d_y = abs(students[i][1] - points[j][1])
    distances.append(d_x + d_y)
  ans.append(distances.index(min(distances)) + 1)

for x in ans:
  print(x)

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

int main(){
 int n,count=0,a=0;
 cin >> n;
 vector<int> goal(n),len(n,0);
 rep(i,n) cin >> goal[i];

 while(a<n){
  if(len[a]==goal[a]) a++;
  if(len[a]<goal[a]){
   count++;
   for(int j=a; len[j]<goal[j]; j++) len[j] += 1;
  }
  
 }
 
  cout << count << endl;
}

Measured memory_bytes: 3580
import math
N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
counter = 0
set256 = {i ** 2 % 256 for i in range(256)}
for i in range(N - 1):
    for j in range(N - i - 1):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[i + j + 1][k]) ** 2
        if {d % 256} & set256 != set():
            r = math.sqrt(d)
            if r == int(r):
                counter += 1
print(counter)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, ok = false;
	string s;
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7')
		ok = true;
	if (ok)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long T = sc.nextLong();
		
		long[] t = new long[N + 1];
		
		for(int i = 1; i <= N; i++) {
			t[i] = sc.nextLong();
		}
		
		long sum = 0;
		
		for(int i = 1; i <= N; i++) {
			if(t[i] - t[i - 1] >= T) {
				sum += T;
			} else {
				sum += t[i] - t[i - 1];
			}
		}
		System.out.println(sum + T);
	}
}


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

int main() {
  
  int n;
  cin >> n;
  int d;
  cin >> d;
  
  if (n%(d*2+1)!=0) cout << n/(d*2+1)+1 << endl;
  else cout << n/(d*2+1) << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

total = 0
for i in range(n):
    if b[i] > a[i]:
        total += a[i]
        if b[i]-a[i] > a[i+1]:
            total += a[i+1]
            a[i+1] = 0
        else:
            total += b[i] - a[i]
            a[i+1] -= b[i] - a[i]
    else:
        total += b[i]
print(total)

Measured memory_bytes: 81892
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

#define in std::cin
#define out std::cout

int32_t H, W,K;
char block[30][30];
char block_tmp[30][30];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> H>>W>>K;
	for (int i = 0; i < H; i++)
	{
		in >> block[i];
	}

	if (K > W) {
		out << 0 << endl; return 0;
	}
	if (K == 1) {
		int32_t res = 0;
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
			{
				res+= block[i][j]-'0';
			}
		out << res << endl; return 0;
	}

	int32_t result = 0;
	for (int delete_pos_H = 0; delete_pos_H < H; delete_pos_H++)for (int delete_pos = 0; delete_pos < W; delete_pos++)
	{
		for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) {
			block_tmp[i][j] = block[i][j];
		}

		bool updated = true;
		int32_t bottom = delete_pos_H;
		int32_t count = 0;
		int32_t result_tmp = 0;
		int32_t spos = delete_pos;
		for (int i = bottom - 1; i >= 0; --i) {
			block_tmp[i + 1][spos] = block_tmp[i][spos];
		}
		block_tmp[0][spos] = 'd';
		while(updated)
		{
			updated = false;
			for (int h = 0; h <= bottom; h++)
			{
				for (int w = 0; w < W; w++)
				{
					if (block_tmp[h][w] == 'd') {
						continue;
					}
					int32_t www = 1;
					for (int j = w + 1; j < W && block_tmp[h][j] == block_tmp[h][w]; j++) {
						++www;
					}
					for (int j = w - 1; j >= 0 && block_tmp[h][j] == block_tmp[h][w]; --j) {
						++www;
					}
					if (www >= K) {
						updated = true;
						result_tmp += (block_tmp[h][w]-'0')*www*(1 << count);
						for (int j = w + 1; j < W && block_tmp[h][j] == block_tmp[h][w]; j++) {
							block_tmp[h][j] = 'd';
						}
						for (int j = w - 1; j >= 0 && block_tmp[h][j] == block_tmp[h][w]; --j) {
							block_tmp[h][j] = 'd';
						}
						block_tmp[h][w] = 'd';
					}
				}
			}
			if (updated)
			{
				for (int w = 0; w < W; w++)
				for (int h = bottom; h >= 0; h--)
				{
					bool notd = true;
					while (notd&&block_tmp[h][w] == 'd') {
						notd = false;
						for (int j = h-1; j >= 0; j--) {
							block_tmp[j + 1][w] = block_tmp[j][w];
							if (block_tmp[j + 1][w]!='d') { notd = true; }
						}
						block_tmp[0][w] = 'd';
					}
				}
			}
			++count;
		}
		result = std::max(result, result_tmp);
	}
	out << result << endl;

	return 0;
}
#endif


Measured memory_bytes: 888
def main
  answers = []
  loop do
    str,pattern = gets.chomp.split(' ')
    break if pattern.eql?('X')

    answers << case pattern
    when 'U'
      conversion_to_upper_camel_case(str)
    when 'L'
      conversion_to_lower_camel_case(str)
    when 'D'
      conversion_to_snake_case(str)
    end
  end

  answers.each {|answer|puts answer}
end

def split_word str
  words = []
  word = ''
  str.length.times do |i|
    if str[i].match(/_/)
      words << word
      word = ''
    elsif str[i].match(/[A-Z]/)
      words << word unless i == 0
      word = str[i]
    else
      word << str[i]
    end
  end
  words << word
  words
end

def conversion_to_upper_camel_case str
  words = split_word(str)
  words.map{|word|word.capitalize}.join
end

def conversion_to_lower_camel_case str
  conversion_word = ''
  words = split_word(str)
  words.each_with_index do |word, i|
    if i == 0
      conversion_word << word.downcase
    else
      conversion_word << word.capitalize
    end
  end
  conversion_word
end

def conversion_to_snake_case str
  words = split_word(str)
  words.each.map{|word|word.downcase}.join('_')
end

main

Measured memory_bytes: 6128
import java.util.*;

public class Main {
	public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if(A<10 && B<10){
      System.out.println(A*B);
        }else{
      System.out.println("-1");          
}
}
}


Measured memory_bytes: 22868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void)
{
    int i, j;
    scanf("%d%d", &i, &j);
    if (i > j)
    {
        printf("safe\n");
    }
    else
    {
        printf("unsafe\n");
    }
    return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("a.in", "r", stdin));
    #else
    #endif
    string a, b;
    cin >> b;
    reverse(b.begin(), b.end());
    while (!b.empty()) {
        while (!a.empty() && !b.empty() && a.back() == 'S' && b.back() == 'T')
            a.pop_back(), b.pop_back();
        if (!b.empty()) {
            a.push_back(b.back());
            b.pop_back();
        }
    }
    cout << sz(a) << '\n';
}

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

int main(void){
  string s;
  int diff = INT_MAX;
  cin >> s;
  for(int i = 0; i < (int)s.length()-2; i++){
    int n  = 100*(s[i] - '0')+10*(s[i+1] - '0')+1*(s[i+2]-'0');
    if(abs(n - 753) < diff) diff = abs(n - 753);
  }
  cout << diff << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input().rstrip())
eat = [ int(ch) for ch in input().rstrip().split(' ') ]
bs = [ int(ch) for ch in input().rstrip().split(' ') ]
cs = [ int(ch) for ch in input().rstrip().split(' ') ]

pre = -1
sum = 0
for k in eat:
  sum += bs[k - 1]
  #print(pre, k)
  if k - pre == 1:
    sum += cs[pre - 1]
  pre = k
  
print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n;

vector<pair<int, int> > g[210000];

pair<int, int> tddfs(int v, int par = -1) {
	pair<int, int> ret = { 0, v };
	for (auto &x : g[v]) {
		int w, cost;
		tie(w, cost) = x;
		if (w == par)
			continue;
		auto r = tddfs(w, v);
		ret = max(ret, { cost + r.first, r.second });
	}
	return ret;
}

int treeDiameter() {
	auto v = tddfs(0);
	auto w = tddfs(v.second);
	return w.first;
}

int main() {
	ll n;
	cin >> n;
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back({ b,1 });
		g[b].push_back({ a,1 });
	}
	//cout << treeDiameter() << endl;
	cout << (treeDiameter() % 3 == 1 ? "Second" : "First") << endl;

}

Measured memory_bytes: 23936
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * 0007:Debt Hell
 * 
 * @author MS14A
 * @version 2015/04/08
 */
public class Main {

    /** 初期借金額：10万円 */
    private static final BigDecimal INITIAL_DEBT = new BigDecimal("100000");

    /** 利子：5% */
    private static final BigDecimal INTEREST_RATE = BigDecimal.valueOf(0.05);

    /** 繰り上げ計算用 */
    private static final BigDecimal DIVISOR = BigDecimal.valueOf(1000);

    /**
     * 某国に住んでいる友達がお金に困って、あるヤミ金融業者から 10 万円の借金をしたまま、<br>
     * 全く返済していないといいます。<br>
     * この業者は、一週間ごとに 5% の利子を借金に加え、さらに借金の 1,000 円未満を切り上げます。<br>
     * n を入力したとき、n 週間後の借金の残高を出力し終了するプログラムを作成して下さい。<br>
     * n は 100 以下とします。
     * 
     * @param args
     *            n
     */
    public static void main(String[] args) {
        Scanner scanned = new Scanner(System.in);
        int weeks = scanned.nextInt();
        BigDecimal finalDebt = INITIAL_DEBT;

        for (int i = 0; i < weeks; i++) {
            // 利子額計算。1000で割った小数部を繰り上げる。
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                                                            .divide(DIVISOR, 0, BigDecimal.ROUND_UP);

            // 借金額 = 前週の借金額 + 利子額
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR));
        }

        System.out.println(finalDebt);
    }

}

Measured memory_bytes: 17240
import math
while True:
    ins = input().split()
    x = int(ins[0])
    op = ins[1]
    y = int(ins[2])
    if op == "+":
        print(x + y)
    elif op == "-":
        print(x - y)
    elif op == "/":
        print(math.floor(x / y))
    elif op == "*":
        print(x * y)
    elif op == "?":
        break
    else:
        break

Measured memory_bytes: 7640
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from bisect import bisect_left

s = str(input())
t = str(input())

d = defaultdict(list)
for i,ch in enumerate(s):
    d[ch].append(i)

i = 0
n = 1
for ch in t:
    temp = d[ch]
    if temp == []:
        print(-1)
        exit()
    place = bisect_left(temp,i)
    if place==len(temp):
        n += 1
        i = temp[0]+1
    else:
        i = temp[place]+1

print((n-1)*len(s)+i)


Measured memory_bytes: 46832
# abc170_a.py
# https://atcoder.jp/contests/abc170/tasks/abc170_a

# A - Five Variables /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 5つの変数 x1,x2,x3,x4,x5があります。
# 最初、変数 xiには整数 iが代入されていました。
# すぬけくんは、これらの変数の中から 1つを選んで、その変数に 0を代入する操作を行いました。
# すぬけくんがこの操作を行ったあとの 5つの変数の値が与えられます。
# すぬけくんが 0を代入した変数がどれであったかを答えてください。

# 制約
#     入力として与えられる x1,x2,x3,x4,x5の値は、すぬけくんが操作を行ったあとのものとしてありえるものである。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# x1 x2 x3 x4 x5

# 出力
# すぬけくんが 0を代入した変数が xi であるとき、整数 iを出力せよ。

# 入力例 1
# 0 2 3 4 5

# 出力例 1
# 1

# この場合、すぬけくんが 0を代入した変数は x1 なので、1を出力します。

# 入力例 2
# 1 2 0 4 5

# 出力例 2
# 3


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[0].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    for n in range(5):
        if values[n] == 0:
            result = n+1

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['0 2 3 4 5']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['1 2 0 4 5']
        lines_export = [3]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = N - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}
int main() {
	int A[100], N, sw;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];

	sw = bubbleSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i)cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
}


Measured memory_bytes: 3136
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  int N;
  cin >> N;
  string col;
  cin >> col;

  vector<int> cnt(N + 1, 0);
  rep(i, N) { cnt[N - (i + 1)] = cnt[N - i] + (col[N - 1 - i] == 'R' ? 1 : 0); }

  int result = N;
  irep(i, N) {
    int left = cnt[0] - cnt[i];
    int w = i - left;
    int cost = max(w, cnt[i]);
    // cerr << w << " " << cnt[i] << " " << cost << "\n";
    chmin(result, cost);
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 4052
#include <stdio.h>

int main()
{
	int n, i, m=100000, r;

	scanf("%d", &n);
	for(i=0; i<n; i++ ){
		r=m*0.05;
		m=m+r;
		if( m%1000 ){
			m=(m/1000+1)*1000;
		}
	}
	printf("%d\n", m);
	return 0;
}

Measured memory_bytes: 592
N = gets.to_i
Ary = gets.split.map(&:to_i)
count = []
RESULT = Array.new(N, 0)
SUM_MEMO = 0
def sum(i)
  result = 0

  (1..(N / (i + 1))).each do |n|
    result += RESULT[(i + 1) * n - 1]
  end

  result
end

(0...N).reverse_each do |i|
  if Ary[i] == 1 && sum(i).even?
    RESULT[i] = 1
    count << i + 1
  elsif Ary[i] == 0 && sum(i).odd?
    RESULT[i] = 1
    count << i + 1
  end
end

puts count.size

if count.size > 0
  puts count.join(' ')
end


Measured memory_bytes: 23564
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

#define MAX 100000

struct TRAMP{
    char mark;
    int number,inputed_order;
};

TRAMP cards[MAX];

int n;

int Partition(int left,int right){
    int i = left-1,pivot = cards[right].number;
    for(int start = left; start < right; start++){
        if(cards[start].number <= pivot){
                i++;
                std::swap(cards[i],cards[start]);
        }
    }

    std::swap(cards[i+1],cards[right]);

    return i+1;
}

void quickSort(int left,int right){
    if(left < right){
        int q = Partition(left,right);
        quickSort(left,q-1);
        quickSort(q+1,right);
    }
}


int main(){

    bool stableFLG = true;
    scanf("%d",&n);

    for(int i = 0; i < n; i++){
        scanf("%s %d",&cards[i].mark,&cards[i].number);
        cards[i].inputed_order = i;
    }

    quickSort(0,n-1);

    for(int i = 1; i < n; i++){
        if(cards[i].number == cards[i-1].number && cards[i].inputed_order < cards[i-1].inputed_order){
        	stableFLG = false;
        	break;
        }
    }

    if(stableFLG){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }

    for(int i = 0; i < n; i++)   printf("%c %d\n",cards[i].mark,cards[i].number);
}


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

int main(){
    int N,X; cin >> N >> X;
    int bounce[N+1];
    bounce[0]=0;

    for(int i=0;i<N;i++){
        int L; cin >> L;
        bounce[i+1]=bounce[i]+L;
    }

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

    cout << ans << endl;

}

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

bool kaibun(string& s) {
	int n = s.size();
	n /= 2;
	for (int i = 0; i < n; ++i) {
		if (s.substr(i,1) != s.substr(s.size()-1-i,1)){
			return false;
		}
	}
	return true;
}

int main()
{
	string s;
	cin >> s;
	int N = s.size();
	string s0, s1;
	s0 = s.substr(0, (N - 1) / 2);
	s1 = s.substr((N + 3) / 2-1, (N - 1) / 2);
	//cout << s0 << endl;
	//cout << s1 << endl;
	if (kaibun(s) && kaibun(s0) && kaibun(s1))
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if (H % h == 0 && W % w == 0) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  for (int r = 0; r < H; r++) {
    for (int c = 0; c < W; c++) {
      if (c > 0) cout << " ";
      if (r % h == 0 && c % w == 0) cout << (int) 1e9 - 1;
      else if (r % h == h - 1 && c % w == w - 1) cout << (int) -1e9;
      else cout << 0;
    }
    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 2944
// C++ program to find the longest 
// path in the DAG 

#include <bits/stdc++.h> 
using namespace std; 

// Function to traverse the DAG 
// and apply Dynamic Programming 
// to find the longest path 
void dfs(int node, vector<int> adj[], int dp[], bool vis[]) 
{ 
	// Mark as visited 
	vis[node] = true; 

	// Traverse for all its children 
	for (int i = 0; i < adj[node].size(); i++) { 

		// If not visited 
		if (!vis[adj[node][i]]) 
			dfs(adj[node][i], adj, dp, vis); 

		// Store the max of the paths 
		dp[node] = max(dp[node], 1 + dp[adj[node][i]]); 
	} 
} 

// Function to add an edge 
void addEdge(vector<int> adj[], int u, int v) 
{ 
	adj[u].push_back(v); 
} 

// Function that returns the longest path 
int findLongestPath(vector<int> adj[], int n) 
{ 
	// Dp array 
	int dp[n + 1]; 
	memset(dp, 0, sizeof dp); 

	// Visited array to know if the node 
	// has been visited previously or not 
	bool vis[n + 1]; 
	memset(vis, false, sizeof vis); 

	// Call DFS for every unvisited vertex 
	for (int i = 1; i <= n; i++) { 
		if (!vis[i]) 
			dfs(i, adj, dp, vis); 
	} 

	int ans = 0; 

	// Traverse and find the maximum of all dp[i] 
	for (int i = 1; i <= n; i++) { 
		ans = max(ans, dp[i]); 
	} 
	return ans; 
} 

// Driver Code 
int main() 
{ 
	int n, m;
	cin>>n>>m; 
	vector<int> adj[n + 1]; 
	for(int i = 0; i<m; i++){
		int x,y;
		cin>>x>>y;
		addEdge(adj, x, y);
	}

	cout << findLongestPath(adj, n); 
	return 0; 
} 


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

int main() {
  int l,r,d;
  int cnt = 0;
  cin >> l >> r >> d;
  for(int i = l; i <= r;i++) {
    if(i % d == 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

class DSU {
	private:
		int *data;
		int *size;
	public:
		DSU(int n) {
			data = new int[n];
			size = new int[n];
			for(int i = 0; i < n; i++) {
				data[i] = i;
				size[i] = 1;
			}
		}

		~DSU() {delete[] data; delete[] size;}

		int find(int i) {
			int parent;
			int back_to = -1;
			for(; i != (parent = data[i]); i = parent) {
				data[i] = back_to;
				back_to = i;
			}
			int root = i;
			while(back_to != -1) {
				i = back_to;
				back_to = data[i];
				data[i] = root;
			}
			return root;
		}

		void merge(int i, int j) {
			int ri = find(i), rj = find(j);
			if (ri == rj)
				return;
			if (size[ri] < size[rj]) {
				int t = ri;
				ri = rj;
				rj = t;
			}
			data[rj] = ri;
			size[ri] = size[ri] + size[rj];
		}

		int get_size(int i) {
			return size[find(i)];
		}
};
using namespace std;

int main() {
	int n, m, k;
	int excluded[100000] = {};
	cin >> n >> m >> k;
	DSU forest{n};
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		forest.merge(a, b);
		excluded[a]++;
		excluded[b]++;
	}
	for(int i = 0; i < k; i++) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		if (forest.find(c) == forest.find(d)) {
			excluded[c]++;
			excluded[d]++;
		}
	}
	for(int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << forest.get_size(i) - 1 - excluded[i];
	}
	cout << endl;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long mod = 1e9 + 7;
    vector<long long>power(n + 3);
    power[0] = 1;
    for(int i = 1; i <= n; i++){
        power[i] = (power[i - 1] * 2) % mod;
    }
    map<pair<long long, long long>, int>mp;
    set<pair<long long, long long> >st;
    long long cnt = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 1; i <= n; i++){
        long long a, b;
        cin >> a >> b;
        if(a == 0 && b == 0){
            cnt++;
        }
        else if(a == 0){
            cnt2++;
        }
        else if(b == 0){
            cnt3++;
        }
        else{
            long long x = abs(a);
            long long y = abs(b);
            long long z = __gcd(x, y);
            a = a/z;
            b = b/z;
            //cout << a << ' ' << b << '\n';
            mp[make_pair(a, b)]++;
            mp[make_pair(-a, -b)]++;
            st.insert(make_pair(a, b));
            st.insert(make_pair(-a, -b));
        }
    }
    long long ans = 1;
    map<pair<long long, long long>, int>::iterator it;
    for(it = mp.begin(); it != mp.end(); it++){
        pair<long long, long long>p = it->first;
        if(st.find(p) == st.end()){
            continue;
        }
        long long a = p.first, b = p.second;
        int val = it->second;
        long long cur = power[val];
        if(st.find(make_pair(-b, a)) == st.end()){
            ans = (ans * cur) % mod;
            st.erase(p);
            st.erase(make_pair(-a, -b));
        }
        else{
            int x = mp[make_pair(-b, a)];
            cur = (cur + power[x] + 2 * mod - 1) % mod;
            ans = (ans * cur) % mod;
            st.erase(p);
            st.erase(make_pair(-a, -b));
            st.erase(make_pair(-b, a));
            st.erase(make_pair(b, -a));
        }
    }
    long long x = (power[cnt2] + power[cnt3] - 1 + 3 * mod) % mod;
    ans = (ans * x) % mod;
    ans = (ans + cnt) % mod;
    cout << (ans + mod - 1) % mod;
    return 0;
}

Measured memory_bytes: 54624
n = int(input())
for _ in range(n):
    data = list(map(int, input().split()))
    B, C = 0, 0
    flag = True
    for d in data:
        if B < d:
            B = d
        elif C < d:
            C = d
        else:
            print("NO")
            flag = False
            break
    if flag:
        print("YES")

Measured memory_bytes: 7668
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if (a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,j,k,l,c=0;
    cin>>n;
    long long int ar[n+5];
    for(i=0;i<n-1;i++)
    {
        cin>>ar[i];
    }
    c=ar[0]+ar[n-2];
    for(i=1;i<n-1;i++)
    {

        c=c+min(ar[i],ar[i-1]);
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main() {
    int n,q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> is(26);
    rep(i,n) is[s[i] - 'a'].insert(i);
    rep(qi,q) {
        int ty;
        cin >> ty;
        if(ty == 1) {
            int i; char c;
            cin >> i >> c;
            --i;
            is[s[i] - 'a'].erase(i);
            s[i] = c;
            is[s[i] - 'a'].insert(i);
        } else {
            int l,r;
            cin >> l >> r;
            --l;
            int ans = 0;
            rep(i,26) {
                auto it = is[i].lower_bound(l);
                if(it != is[i].end() && *it < r) ++ans;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 26244
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============BIT============================
const ll MAX_N = pow(10, 5) * 5 + 1;
ll n;
vector<ll> bit(MAX_N + 1, 0);

ll sum(ll i) {
  ll s = 0;
  while (i > 0) {
    s += bit.at(i);
    i -= i & -i;
  }
  return s;
}

void add(ll i, ll x) {
  while (i <= n) {
    bit.at(i) += x;
    i += i & -i;
  }
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, Q;
  cin >> N >> Q;
  n = N;
  for (ll i = 1; i <= N; ++i) {
    ll a;
    cin >> a;
    add(i, a);
  }
  for (ll i = 0; i < Q; ++i) {
    ll q, p, x;
    cin >> q >> p >> x;
    p += 1;
    if (q == 0) {
      add(p, x);
    }
    else {
      x += 1;
      ll ans = sum(x - 1);
      if (p != 1) {
        ans -= sum(p - 1);
      }
      cout << ans << "\n";
    }
  }
}


Measured memory_bytes: 8240
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll ans = 1;
    while(1)
    {
        n = n*2;
        if(n > m)break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#define waru 1000000000+7

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c;
    bool guu = (n%2 == 0);
    rep(i,n){
        cin >> a[i];
            if(i+1 > n/2){
                b[i] = a[i];
                if(b[i] == 1){
                    c.push_back(i+1);
                }
            }
            else{
                b[i] = -1;
            }
    }
    // showa(b);
    rep(j,n){
        int i = n-1-j;
        if(b[i] == -1){
            int t = n/(i+1) -1;
            int sum = 0;
            for(int k = 0; k < t; k++){
                sum += b[(i+1)*(k+2)-1];               
            }
            // shows("sum:") show(sum)
            if(sum%2 == a[i]){
                b[i] = 0;
            }
            else{
                b[i] = 1;
                c.push_back(i+1);
            }
        }
    }
    // showa(b)
    cout << c.size() << endl;
    // cout << "a";
    if(c.size() != 0){
        for(int i = 0; i< c.size(); i++){
            cout << c[i] << " ";
        }
    }


}

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

using namespace std;

int main()
{
   string s;
   cin>>s;
   int cn=0;
   int mx=0;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]=='R')
       {
           cn++;
           mx=max(cn,mx);
       }
       else
       cn=0;
   }
   cout<<mx;
   
   return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

bool syuryou_zyoken(int want_aite_idx[], int N) {
    bool ret = true;

    for (int n = 0; n < N; n++) {
        if (want_aite_idx[n] != N - 1) {
            ret = false;
        }
    }
    return ret;
}

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

    int A[N][N];
    for (int n = 0; n < N; n++) {
        for (int m = 0; m < N - 1; m++) {
            cin >> A[n][m];
            A[n][m]--;
        }
        A[n][N - 1] = -1;
    }

    int want_aite[N];
    int want_aite_idx[N] = {0};
    int day = 0;
    for (int n = 0; n < N; n++) {
        want_aite[n] = A[n][0];
    }

    while (!syuryou_zyoken(want_aite_idx, N)) {
        // ペア探し
        vector<pair<int, int>> siai_pair;
        for (int n = 0; n < N; n++) {
            int m = want_aite[n];
            if ((n < m) && (want_aite[m] == n)) {
                siai_pair.emplace_back(make_pair(n, m));
            }
        }

        if (siai_pair.size() == 0) {
            cout << "-1" << "\n";
            return 0;
        }

        // 試合して、次の対戦相手募集
        for (auto p : siai_pair) {
            want_aite_idx[p.first] += 1;
            want_aite[p.first] = A[p.first][want_aite_idx[p.first]];
            want_aite_idx[p.second] += 1;
            want_aite[p.second] = A[p.second][want_aite_idx[p.second]];
        }
        day++;
    }

    cout << day << "\n";

    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
char getClass(int m, int e, int j) {
	if (m == 100 || e == 100 || j == 100 || (m + e) / 2 >= 90
			|| (m + e + j) / 3 >= 80)
		return 'A';
	if ((m + e + j) / 3 >= 70 || (m + e + j) / 3 >= 50 && m >= 80 || e >= 80)
		return 'B';
	return 'C';
}
int main() {
	int n, pm, pe, pj;
	while (cin >> n && n) {
		for (int i = 0; i < n; i++) {
			cin >> pm >> pe >> pj;
			cout << getClass(pm, pe, pj) << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main(){
    string str;
    long long k;
    cin >> str;
    cin >> k;
    long long n = str.size();
    bool check = true;
    for(int i = 1; i < n; i++){
        if(str[i] != str[i - 1]){
            check = false;
            break;
        }
    }
    if(check){
        cout << n * k / 2 << "\n";
        return 0;
    }
    check = str[0] == str.back();
    long long ans = 0, cnt = 1;
    for(int i = 1; i < n; i++){
        if(str[i - 1] == str[i]){
            cnt++;
        }else{
            ans += k * (cnt / 2);
            cnt = 1;
        }
    }
    ans += k * (cnt / 2);
    if(check){
        long long a = 0, b = cnt;
        for(int i = 0; str[i] == str[0]; i++){
            a++;
        }
        ans -= (k - 1) * ((a / 2) + (b / 2) - ((a + b) / 2));
    }
    cout << ans << "\n";
}



Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt()
	originalArray := make([]int, N)
	sortedArray := make([]int, N)
	for i := 0; i < N; i++ {
		v := nextInt()
		originalArray[i] = v
		sortedArray[i] = v
	}
	sort.Ints(sortedArray)
	for _, v := range originalArray {
		if v != sortedArray[N-1] {
			fmt.Printf("%d\n", sortedArray[N-1])
		} else {
			fmt.Printf("%d\n", sortedArray[N-2])
		}
	}
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 7680
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int n;
  cin >> n;
  
  int a[n];
  REP(i,n){
    cin >> a[i];
  }
  
  int cnt = 0;
  REP(i,n-1){
    if(a[i] == i+1){
      swap(a[i],a[i+1]);
      cnt++;
    }
  }
  
  if(a[n-1] == n) cnt++;

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int A,B;
	scanf("%d",&A);
	scanf("%d",&B);
	char S[A+B+2];
	int i;
	scanf("%s",&S);	
	int flag = 0;
	for(i=0;i<=A+B;i++){
		if(i==A){
			if(S[i] == '-'){flag=0;}
			else	{flag=1; break;}
		}
		if(i != A){
			if(S[i] != '-') flag=0;
			else {flag=1; break;}
		}
	}
	if(flag==1) printf("No");
	else printf("Yes");
	
	
	return 0;
}

Measured memory_bytes: 128