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

def solve(A: int, B: int, C: int, D: int):
    numCount = B - A + 1
    initialDivideC = A-A%C + C if A%C != 0 else A
    initialDivideD = A-A%D + D if A%D != 0 else A
    lcmCD = C*D//fractions.gcd(C,D)
    initialDivideLCM = A-A%lcmCD + lcmCD if A%lcmCD != 0 else A
    countC = (B - initialDivideC)//C + 1
    if initialDivideC > B:
        countC = 0
    countD = (B - initialDivideD)//D + 1
    if initialDivideD > B:
        countD = 0
    countLCM = (B - initialDivideLCM)//lcmCD + 1
    if initialDivideLCM > B:
        countLCM = 0
    print(numCount - countC - countD + countLCM)
    return


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

if __name__ == '__main__':
    main()


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

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

    map<string, vector<pair<int, int>>> mp;
    for (int i = 0; i < n; i++){
        string s;
        int p;
        cin >> s >> p;
        mp[s].push_back({p, i + 1});
    }

    for (auto i: mp){
        sort(i.second.begin(), i.second.end());
        for (int j = i.second.size() - 1; j >= 0; j--)
            cout << i.second[j].second << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int N;
vector<vector<int>> G;
vector<int> B, W;
void recur(int n, int prev)
{
    long long b = 1, w = 1;
    for (int k : G[n]) {
        if (k == prev) continue;
        recur(k, n);
        b = b * W[k] % MOD;
        w = w * (W[k] + B[k]) % MOD;
    }
    B[n] = b;
    W[n] = w;
}
int main()
{
    cin >> N;
    G.resize(N);
    B.resize(N);
    W.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int x, y; cin >> x >> y; x--, y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    recur(0, -1);
    cout << (B[0] + W[0]) % MOD << endl;
    return 0;
}

Measured memory_bytes: 13440
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#include<bitset>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
struct S{
    int u, v, w;
};

signed  main(){
    int l;
    cin >> l;
    int r = 0;
    for(int i = 19; i >= 0; i--){
        if(l & (1 << i)){
            r = i; break;
        }
    }
    vector<S> G;
    for(int i = 0; i < r; i++){
        G.push_back({i, i + 1, 1 << i});
        G.push_back({i, i + 1, 0});
    }
    int rest = l;
    int tmp = 1 << r;
    for(int i = r - 1; i >= 0; i--){
        if(rest & (1 << i)){
            G.push_back({i, r, tmp});
            tmp += 1 << i;
        }
    }
    cout << r + 1 << ' ' << G.size() << endl;
    for(int i = 0; i < G.size(); i++){
        cout << G[i].u + 1 << ' ' << G[i].v + 1 << ' ' << G[i].w << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
   unsigned long long int n,i,j,temp;
   scanf("%lld",&n);
   for(i=1;i<=sqrt(n);i++)
   {
       temp=i*i;
       if(temp<=n&&((i+1)*(i+1))>n)
        break;

   }
   printf("%lld",temp);
}


Measured memory_bytes: 128
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
int a[100005];
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];int op=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==i)
		{
			swap(a[i],a[i+1]),op++;
		}
	}cout<<op;
	return 0;
}

Measured memory_bytes: 640
S = input()

if S == "SUN":
    print("7")

elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)


Measured memory_bytes: 2940
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    string a;
    cin >> a;
    int ans = 700;
    if (a[0] == 'o') {
        ans += 100;
    }
    if (a[1] == 'o') {
        ans += 100;
    }
    if (a[2] == 'o') {
        ans += 100;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	int X; cin >> X;
	if(X == 7 or X == 5 or X == 3) cout << "YES" << endl;
	else cout << "NO" << endl;


	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

struct Node
{
	int key;
	Node *parent, *left, *right; 
};

Node *root, *NIL;

void insert(Node *z)
{
	Node *x = root;	//current node.
	Node *y = NIL; //current node's parrent node.

	while(x != NIL) //first time root == NIL?
	{
		y = x;
		if(z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}
	z->parent = y;
	
	if(y == NIL) root = z;
	else if(z->key < y->key)
	{
		y->left = z;
	}
	else
	{
		y->right = z;
	}
}

void preParse(Node *u)
{
	if(u == NIL) return;
	cout << " " << u->key;
	preParse(u->left);
	preParse(u->right);
}


void inParse(Node *u)
{
	if(u == NIL) return;
	inParse(u->left);
	cout << " " << u->key;
	inParse(u->right);
}

void print()
{
	inParse(root);
	cout << endl;
	preParse(root);
	cout << endl;
}

int main(){

//	char S[10];  // is this one ok?
	string s;
	int k;
	int m;
	
	cin >> m;
	for(int i = 0; i < m; i++)
	{
		cin >> s;
		if(s == "insert")
		{
			cin >> k;
			
			Node *z = new Node;	//delete?
//			z = (new *)malloc(sizeof(Node));
			z->key = k;
			z->left = NIL;
			z->right = NIL;
			
			insert(z);
//			delete z;
		} 
		else if(s == "print") print();
	}
	

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


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

int main(){
	int n;
	cin >> n;
	int a[n+1];
	for(int i=1; i<=n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	for(int i=2; i<=n; i++){
		if(a[i]==a[i-1]) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,j=0,k,x;
    cin>>a>>b;
    for(i=0;i<=a;i++)
    {
        x=a-i;
        k=(i*2)+(x*4);
        if(k==b)
        {
            j=1;
            break;
        }
    }
    if(j==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3580
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace mytest
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
          	if(N%2 == 0)
            {
              Console.WriteLine(0.5);
            }
            else
            {
              Console.WriteLine((Math.Ceiling((double)(N/2d)))/N);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


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


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m;
struct node{int l,r;}a[300010];
bool cmp(node x,node y){return x.r-x.l<y.r-y.l;}

int tree[100010];
void add(int id,int x){for(;id<=m;id+=id&-id) tree[id]+=x;}
int query(int id){int re=0;for(;id;id-=id&-id) re+=tree[id];return re;}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+n+1,cmp);
	for (int i=1,j=1;i<=m;i++)
	{
		while (j<=n&&a[j].r-a[j].l<i)
		{
			add(a[j].l,1);
			add(a[j].r+1,-1);
			j++;
		}
		int cnt=0;
		for (int t=i;t<=m;t+=i) cnt+=query(t);
		printf("%d\n",cnt+n-j+1);
	}
}


Measured memory_bytes: 3712
# 写経

n = int(input())
lst_F = [list(map(int, input().split())) for _ in range(n)]
lst_P = [list(map(int, input().split())) for _ in range(n)]


ans = -float("INF")
for b in range(1, 2**10):
    tmp = 0
    for i in range(n):
        c = 0
        for k in range(10):
            if b&(1<<k) and lst_F[i][k]:
                c += 1
        tmp += lst_P[i][c]
    ans = max(tmp, ans)


print(ans)

Measured memory_bytes: 42220
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;


int main() {

    vector<int> poloq;
    for (int i = 0; i < 190; i++) poloq.push_back((i + 1) * (i + 2) * (i + 3) / 6);
    //for (int i = 0; i < 190; i++) cout << poloq[i] << " ";


    vector<int> all = poloq;
    vector<int> odd;
    for (int i = 0; i < all.size(); i++) if (all[i] % 2 == 1) odd.push_back(all[i]);
//
//    for (int i = 0; i < poloq.size(); i++)cout << poloq[i] << " ";
//    cout << endl;
//    for (int i = 0; i < odd.size(); i++)cout << odd[i] << " ";

    vector<int> ans1(1300000);
    vector<int> ans2(1300000);

    ans1[0] = 0;
    ans1[1] = 1;
    for (int i = 2; i <= 1200000; i++) {
        ans1[i] = ans1[i - 1] + 1;
        for (int j = 0; j < all.size(); j++) {
            if (all[j] <= i) ans1[i] = min(ans1[i], ans1[i - all[j]] + 1);
            else break;
        }
    }
    // for (int i = 0; i < 10000; i++) cout << ans1[i] << " ";

    ans2[0] = 0;
    ans2[1] = 1;
    for (int i = 2; i <= 1200000; i++) {
        ans2[i] = ans2[i - 1] + 1;
        for (int j = 0; j < odd.size(); j++) {
            if (odd[j] <= i) ans2[i] = min(ans2[i], ans2[i - odd[j]] + 1);
            else break;
        }
    }
    //for (int i = 0; i < 10000; i++) cout << ans2[i] << " ";

    while (true) {
        int N;
        cin >> N;

        if (N == 0) break;

        cout << ans1[N] << " " << ans2[N] << endl;

    }

    return 0;
}


Measured memory_bytes: 12652
#include <stdio.h>

int main(void) {
  int a,b,c,d,e,g,x[100][100],y[100][100];
  long int r;
  scanf("%d %d %d",&a,&b,&c);
  for(d=0;d<a;d++)
    for(e=0;e<b;e++)
     scanf("%d",&x[d][e]);
  
  for(d=0;d<b;d++)
   for(e=0;e<c;e++)
    scanf("%d",&y[d][e]);

  for(d=0;d<a;d++)
   for(e=0;e<c;e++){
     r=0;
    for(g=0;g<b;g++)
    r+=x[d][g]*y[g][e];
    printf("%ld",r);
    if(e+1==c)
    printf("\n");
    else
    printf(" ");
   }
  return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    char prev = '\0';
    int score = 0;
    for (auto c:s) {
        if (c == prev) score++;
        prev = c;
    }
    cout << score + min(2*k, n - score - 1) << '\n';
    return 0;
}


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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<ll> VL;

/**
 * Segment Tree. This data structure is useful for fast folding on intervals of an array
 * whose elements are elements of monoid M. Note that constructing this tree requires the identity
 * element of M and the operation of M.
 * Header requirement: vector, algorithm
 * Verified by AtCoder ABC017-D (http://abc017.contest.atcoder.jp/submissions/660402)
 */
template<class I, class BiOp = I (*) (I, I)>
class SegTree {
  int n;
  std::vector<I> dat;
  BiOp op;
  I e;
public:
  SegTree(int n_, BiOp op, I e) : op(op), e(e) {
    n = 1;
    while (n < n_) { n *= 2; } // n is a power of 2
    dat.resize(2 * n);
    for (int i = 0; i < 2 * n - 1; i++) {
      dat[i] = e;
    }
  }
  /* ary[k] <- v */
  void update(int k, I v) {
    k += n - 1;
    dat[k] = v;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  void update_array(int k, int len, const I *vals) {
    for (int i = 0; i < len; ++i) {
      update(k + i, vals[i]);
    }
  }
  /*
    Updates all elements. O(n)
   */
  void update_all(const I *vals, int len) {
    for (int k = 0; k < std::min(n, len); ++k) {
      dat[k + n - 1] = vals[k];
    }
    for (int k = std::min(n, len); k < n; ++k) {
      dat[k + n - 1] = e;
    }
    for (int b = n / 2; b >= 1; b /= 2) {
      for (int k = 0; k < b; ++k) {
	dat[k + b - 1] = op(dat[k * 2 + b * 2 - 1], dat[k * 2 + b * 2]);
      }
    }
  }
  /* l,r are for simplicity */
  I querySub(int a, int b, int k, int l, int r) const {
    // [a,b) and  [l,r) intersects?
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return dat[k];
    I vl = querySub(a, b, 2 * k + 1, l, (l + r) / 2);
    I vr = querySub(a, b, 2 * k + 2, (l + r) / 2, r);
    return op(vl, vr);
  }
  /* [a, b] (note: inclusive) */
  I query(int a, int b) const {
    return querySub(a, b + 1, 0, 0, n);
  }
};


const int N = 200100;
const ll inf = 1e16;

struct min_fun {
  ll operator()(ll x, ll y) const {
    return min(x, y);
  }
};

int main(void){
  int n;
  ll e, t;
  cin >> n >> e >> t;
  VL x(n);
  SegTree<ll, min_fun> raw(n + 1, min_fun(), inf); // dp[i]
  SegTree<ll, min_fun> boiled(n + 1, min_fun(), inf); // dp[i] - 2 * x[i]
  REP(i, 0, n) {
    cin >> x[i];
  }
  raw.update(0, 0);
  boiled.update(0, -2 * x[0]);
  REP(i, 0, n) {
    // Compute the range of j s.t. t <= 2 * (x[i] - x[j]) (0 <= j <= i)
    int j_boundary =
      upper_bound(x.begin(), x.begin() + i + 1, x[i] - (t+1)/2) - x.begin();
    ll ret = inf;
    ret = min(ret, boiled.query(0, j_boundary - 1) + 2 * x[i]);
    ret = min(ret, raw.query(j_boundary, i) + t);
    raw.update(i + 1, ret);
    if (i < n - 1) {
      boiled.update(i + 1, ret - 2 * x[i + 1]);
    }
  }
  cout << raw.query(n, n) + e << endl; 
}


Measured memory_bytes: 5248
S = list(input())

for i in range(2**3):
  ans = int(S[0])
  res = ["-","-","-"]
  for j in range(3):
    if ((i >> j) & 1):
      ans += int(S[j+1])
      res[j] = "+"
    else:
      ans -= int(S[j+1])
  if ans == 7:
    print(S[0]+res[0]+S[1]+res[1]+S[2]+res[2]+S[3]+"=7")
    exit()

Measured memory_bytes: 9176
n=int(input())
l = list(map(int, input().split()))
flag=True
for i in range(n):
    if l[i]%2==0:
        if l[i]%3!=0 and l[i]%5!=0:
            flag=False
if flag==True:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
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();
        int k = sc.nextInt();
        for(int i=a<b?a:b;i>0;i--){
          if(a%i==0 && b%i==0) k--;
          if(k==0){
             System.out.println(i);
             return;
          }
        }
        // 出力
       
    }
}


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

using namespace std;
#define ll long long
int n, h[100000], dp[100000];

int cost(int i){
	//base case
	if(i>= n-1){
		return 0;
	}
	//recursive case
	if(dp[i]!=-1){return dp[i];}

	int op1 = abs(h[i]-h[i+1]) + cost(i+1);
	int op2 = (i!=n-2)?abs(h[i]-h[i+2]) + cost(i+2):INT_MAX;

	dp[i]=min(op1, op2);
	return dp[i];
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>h[i];
	}
	memset(dp, -1, sizeof(dp));
	cout<<cost(0);
}

Measured memory_bytes: 4224
import java.io.*;

public class Main{
  public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String numStr = br.readLine();
    int n = Integer.parseInt(numStr);
    int result = 0;
    
    for(int i=numStr.length()-1; 0<i; i--) if( i%2 == 1 )
      result += (int)(Math.pow(10, i)-Math.pow(10, i-1));
    if( numStr.length() % 2 == 1 )
      result += n - Math.pow(10, numStr.length()-1) + 1;
    
    System.out.println(result);
  }
}


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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -1e18;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
}

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

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

	for (int i = 0; i < n; ++i) {
		string cmd;
		cin >> cmd;
		if (cmd == "print") {
			int a, b;
			cin >> a >> b;
			cout << s.substr(a, b - a + 1) << endl;
		}
		else if (cmd == "reverse") {
			int a, b;
			cin >> a >> b;
			reverse(s.begin() + a, s.begin() + b + 1);
		}
		else if (cmd == "replace") {
			int a, b;
			string p;
			cin >> a >> b >> p;
			s.replace(a, b - a + 1, p);
		}
	}
}



Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
bool chk(string str1 , string str2)
{
    if (str1 > str2)
    {
        return false;
    }
    else
    {
        return true;
    }
}
int main()
{
    int N;
    cin >> N;
    map<string, int> Map;
    for (int i = 0; i <N; i++)
    {
        string x;
        cin >> x;
        Map[x]++;
    }
    int Max = 0;
    for (auto it : Map)
    {
        Max = max(Max, it.second);
    }
    vector<string> str;
    for (auto it : Map)
    {
        if (it.second == Max)
            str.push_back(it.first);
    }
    sort(str.begin(), str.end(), chk);
    for (int i = 0; i < str.size(); i++)
    {
        cout << str[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 26868
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int gcd(int x, int y) {
	if (x < y) {
		swap(x, y);
	}
	if (y == 0) {
		return x;
	}
	return gcd(y, x%y);
}

int main() {
	int N;
	cin >> N;
	vi A(N);
	REP(i, N) {
		cin >> A[i];
	}
	sort(RALL(A));

	int ans = gcd(A[0], A[1]);
	FOR(i, 2, N - 1) {
		ans = gcd(ans, A[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
NMAX = 1000; MMAX = 2000

INF = 10**15

edge = []
for _ in range(m):
    a, b, c = map(int, input().split())
    # 最短距離の問題に変える
    a -= 1; b -= 1; c = -c
    edge.append([a, b, c])

# Bellman-Ford O(NM)
dist = [INF for _ in range(NMAX)] # 頂点1からの最短距離を格納する配列
dist[0] = 0
for loop in range(n):
    for i in range(m):
        a, b, c = edge[i]
        if dist[a] == INF:
            continue
        dist[b] = min(dist[b], dist[a]+c)

ans = dist[n-1]

# 負の閉路検出 O(NM)
## すでにBellman-Fordを実施しているので、distには頂点1から各頂点vまでの最短距離が格納されているはず
## もしまだ更新されるようなら、負の閉路(問題に合わせると正の閉路)が存在していることになる
negative = [False for _ in range(NMAX)] # 頂点iが負の閉路に含まれる場合はTrue
for loop in range(n):
    for i in range(m):
        a, b, c = edge[i]
        if dist[a] == INF:
            continue
        if dist[b] > dist[a]+c:
            dist[b] = dist[a]+c
            negative[b] = True
        if negative[a]:
            negative[b] = True

if negative[n-1]:
    print("inf")
else:
    print(-ans)

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

int main() {

    vector<int> a(10);
    for(int i = 0;i < 10;i++) cin >> a[i];
    
    sort(a.begin(),a.end());
    
    cout << a[9] << "\n" << a[8] << "\n" << a[7] << "\n";
    
return 0;
}

Measured memory_bytes: 3140
import java.util.*;

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

        int n = sc.nextInt();   //可変長配列要素数
        int q = sc.nextInt();   //クエリ数

        ArrayList<ArrayList<Integer>> list = new ArrayList<>(); //可変長配列
        for(int i = 0;i < n;i++){   //初期化
            list.add(new ArrayList<>());
        }

        int num,t;    //命令番号、指定された配列要素番号
        for(int i = 0;i < q;i++){
            num = sc.nextInt();
            t = sc.nextInt();

            switch(num){
                case 0: //pushBack
                    int x = sc.nextInt();   //整数x
                    list.get(t).add(x);
                    break;
                case 1: //dump
                    for(int j = 0;j < list.get(t).size();j++){
                        if(j != 0)  System.out.print(" ");
                        System.out.print(list.get(t).get(j));
                    }
                    System.out.println();
                    break;
                case 2: //clear
                    list.get(t).clear();
                    break;
            }
        }
    }
}



Measured memory_bytes: 310572
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=(input.trim()).split("\n");
while(true){
   var n=arr.shift()-0;
   if(n==0)break;
   var ary=arr.shift().split(" ");
   var L=0;
   var R=0;
   var UD=2;
   var cnt=0;
   ary.forEach(function(v){
      if(v=="lu")L=1;
      else if(v=="ru")R=1;
      else if(v=="ld")L=0;
      else if(v=="rd")R=0;
      if(UD==L+R){
         cnt++;
         UD=(UD==2)?0:2;
      }
   });
   console.log(cnt);
}

Measured memory_bytes: 16792
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
flag = True
if d[0] != 0:
    flag = False
count = {}
for i in range(len(d) - 1):
    count.setdefault(d[i + 1], 0)
    count[d[i + 1]] += 1
count2 = []
for i, j in count.items():
    count2.append([i, j])
count2.sort()

ans = 1
if count2[0][0] == 1:
    for i in range(len(count2) - 1):
        if count2[i + 1][0] - count2[i][0] == 1:
            temp = count2[i][1] ** count2[i + 1][1]
            ans *= temp
            ans %= mod
        else:
            flag = False
            break
else:
    flag = False
if flag == True:
    print(ans)
else:
    print(0)

Measured memory_bytes: 23388
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
  cerr << ' ' << head;
  debug_cerr(tail...);
}
void chmax(lint &a, lint b) { if (a < b) a = b; }
void chmin(lint &a, lint b) { if (a > b) a = b; }
struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout << fixed << setprecision(20);
      cerr << fixed << setprecision(20);
    }
} iosetup;

int main() {
  int n; cin >> n;
  int x = (n+1) * 100 / 108;
  if (x * 108 / 100 == n) {
    cout << x << '\n';
  } else {
    cout << ":(" << '\n';
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	string s;
	cin >> s;
	bool a=false,b = false;
	int u = (s[0]-'0')*10+(s[1]-'0');
	int v = (s[2]-'0')*10+(s[3]-'0');
	// /cout << u << ' ' << v << endl;
	if(1<=u&&u<=12)a=true;
	if(1<=v&&v<=12)b=true;
	if(a&&b)cout << "AMBIGUOUS" << endl;
	else if(a){
		cout << "MMYY" << endl;
	}else if(b){
		cout << "YYMM" << endl;
	}else{
		cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;

int main(){
	int n,m,x;
    
    cin >> n >> m;
    
    x = (n - 1) * (m - 1);
    
    cout << x;
    
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int a,b,c,x,y;
  std::cin >> a >> b >> c >> x >> y;

  int piza_a = 0;
  int piza_b = 0;
  int piza_ab = x+y;
  int ans = piza_ab*2*c;
  while (piza_ab >= 0) {
    if(x >= piza_ab)
      piza_a = x - piza_ab;
    if(y >= piza_ab)
      piza_b = y - piza_ab;

    int min = a*piza_a + b*piza_b + c*piza_ab*2;
    if(min < ans)
      ans = min;
    piza_ab--;
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=2010;
const ll inf=1e18;
int n,sz[N];char s[N];ll ds[N],dz[N],sn[N];
vector<int>g[N];

void dfs(int u,int fa){
	sz[u]=s[u]-'0';
	ll sum=ds[u]=sn[u]=0,mx=0;
	for(int v : g[u]){
		if(v==fa)continue;
		dfs(v,u);
		ds[u]+=ds[v]+sz[v];sz[u]+=sz[v];
		if(ds[v]+sz[v]>=mx)sum+=mx,mx=ds[sn[u]=v]+sz[v];
		else sum+=ds[v]+sz[v];
	}
	dz[u] = dz[sn[u]] + ((mx>=sum) ? sum : ((mx+sum)>>1));
}

int main(){
//	freopen("E.in","r",stdin);
//	freopen("E.out","w",stdout);
	scanf("%d%s",&n,s+1);
	for(int i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	ll ans=inf;
	for(int i=1;i<=n;++i){
		dfs(i,0);
		if(ds[i]&1)continue;
		if(dz[i]*2 >= ds[i])ans=min(ds[i]>>1,ans);
	}
	if(ans==inf)puts("-1");else cout<<ans<<endl;
	return 0;
}


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

ll n,m,a[100009],sum;

ll f(ll x){
    ll num=0,y=n-1;
    rep(i,n){
        while(y>=0&&a[i]+a[y]>=x){
            sum+=a[y]*(n-i);
            y--;
        }
        sum+=(n-y-1)*a[i];
        num+=n-y-1;
    }
    return num;
}

int main(){
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    ll l=0,r=1e18;
    while(l+1<r){
        ll mid=(l+r)/2;
        if(f(mid)<=m)r=mid;
        else l=mid;
    }
    sum=0ll;
    cout<<l*(m-f(r))+sum<<endl;
}

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const ll mod = 1e9 + 7;

ll fact[1000010], ifact[1000010];

ll power(ll a, ll b)
{
    ll r = 1;
    while (b)
    {
        if (b & 1)
        {
            r = r * a % mod;
        }
        b /= 2;
        a = a * a % mod;
    }
    return r;
}

void init()
{
    fact[0] = 1;
    for (int i = 1; i <= 1e6; ++i)
    {
        fact[i] = fact[i - 1] * i % mod;
    }
    ifact[1000000] = power(fact[1000000], mod - 2);
    for (int i = 999999; i >= 0; --i)
    {
        ifact[i] = ifact[i + 1] * (i + 1) % mod;
    }
}

ll nCk(int n, int k)
{
    if (k < 0 || k > n)
    {
        return 0LL;
    }
    return fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}

int s;
ll ans = 0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    cin >> s;
    for1(i, s)
    {
        int d = s - i * 2;
        ans += nCk(d - 1, i - 1);
    }
    ans %= mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 19268
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


int main(){FIN

    ll n,k;cin>>n>>k;
    ll cnt=0;
    map<ll,ll> mp;
    REP(i,k){
        ll d;cin>>d;
        REP(j,d){
            ll a; cin>>a;
            mp[a]++;
        }
    }
    for(auto p:mp){
        if(p.second)cnt++;
    }
    cout<<n-cnt<<endl;
    return 0;
}

Measured memory_bytes: 3656
import math
a,b,C=map(float,input().split())
θ=math.radians(C)
h=b*math.sin(θ)
S=(a*h)/2
c=math.sqrt(a**2+b**2-2*a*b*math.cos(θ))
L=a+b+c
print(S,L,h,sep="\n")



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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  for (int i = n;; i--) {
    int sq = sqrt(i) + 0.5;
    if (sq * sq == i) {
      std::cout << i << std::endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 998244353;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll MODPOW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = MODPOW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * MODPOW(n, m - 1)) % MOD;
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl D(N);
  REP(i, N) cin >> D[i];
  if (D[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  vl DP(N, 0);

  REP(i, N) { DP[D[i]]++; }
  if (DP[0] != 1) {
    cout << 0 << endl;
    return 0;
  }
  bool ok = true;
  ll ans = 1;
  FOR(i, 1, N) {
    if (DP[i] > 0 && DP[i - 1] == 0)
      ok = false;
    else if (DP[i] > 0) {
      ans = (ans * MODPOW(DP[i - 1], DP[i])) % MOD;
    }
  }
  if (!ok)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<vector<llong> > edges;
	vector<llong> num, c;

	cin >> N;
	edges.resize(N+1);
	num.resize(N+1);
	c.resize(N+1);

	llong to, from;
	llong maxi_child = 0;
	llong root = 0;
	for (int i = 0; i < N-1; i++) {
		cin >> to >> from;
		edges[to].push_back(from);
		edges[from].push_back(to);
		if (edges[to].size() > maxi_child) {
			maxi_child = edges[to].size();
			root = to;
		} else if (edges[from].size() > maxi_child) {
			maxi_child = edges[from].size();
			root = from;
		}
	}
	for (int i = 0; i < N; i++)
		cin >> c[i];
	sort(ALL(c), greater<>());

	int id = 0;
	queue<int> q;
	vector<bool> used(N+1, false);
	q.push(root);
	used[root] = true;
	while(q.size()) {
		int now = q.front();
		q.pop();
		num[now] = c[id++];
		for (auto next : edges[now]) {
			if (used[next]) continue;
			used[next] = true;
			q.push(next);
		}
	}

	fill(ALL(used), false);
	llong ans = 0;
	q.push(root);
	used[root] = true;
	while(q.size()) {
		int now = q.front();
		q.pop();
		for (auto next : edges[now]) {
			if (used[next]) continue;
			ans += min(num[now], num[next]);
			used[next] = true;
			q.push(next);
		}
	}

	cout << ans << endl;
	for (int i = 1; i <= N; i++)
		cout << num[i] << " ";
	cout << endl;

	return 0;
}

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

int main()
{
	int n;
	int sub[200001];

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		sub[i] = 0;
	}

	for (int j = 2; j <= n; j++)
	{
		int x;
		cin >> x;
		sub[x]++;
	}

	for (int k = 1; k <= n; k++)
	{
		cout << sub[k] << endl;
	}
}

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

using namespace std;

int main()
{
    const int NO_OF_VERTICES = 4, NO_OF_EDGES = 3;

    vector <int> degree(NO_OF_VERTICES + 1, 0);
    for(int i = 1; i <= NO_OF_EDGES; i++)
    {
        int u, v;
        cin >> u >> v;

        degree[u]++;
        degree[v]++;
    }

    vector <int> degree_count(NO_OF_VERTICES + 1, 0);
    for(int i = 1; i <= NO_OF_VERTICES; i++)
    {
        degree_count[degree[i]]++;
    }

    cout << (degree_count[1] == 2 && degree_count[2] == NO_OF_VERTICES - 2 ? "YES\n" : "NO\n");
    return 0;
}


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

int main(){
    string s,t;
    cin>>s>>t;
    vector<vector<int> > dp(s.size()+1,vector<int>(t.size()+1,0));
    rep(i,s.size()+1) dp[i][0]=i;
    rep(i,t.size()+1) dp[0][i]=i;
    rept(i,1,s.size()+1){
        rept(j,1,t.size()+1){
            dp[i][j]=min(dp[i-1][j-1]+(s[i-1]!=t[j-1]),min(dp[i][j-1],dp[i-1][j])+1);
        }
    }
    cout<<dp.back().back()<<endl;
   
    return 0;
}


Measured memory_bytes: 6852
import sys
import copy

sys.setrecursionlimit(10 ** 6)

def main():
    def per(s, a=[]):
        if not s:
            return [a]
        if len(s) % 2:
            cs = copy.deepcopy(s)
            res = []
            for u in cs:
                s.remove(u)
                res += per(s, [u] + a)
                s.add(u)
            return res
        u = min(s)
        s.remove(u)
        cs = copy.deepcopy(s)
        res = []
        for uu in cs:
            if uu < u: continue
            s.remove(uu)
            res += per(s, a + [u, uu])
            s.add(uu)
        s.add(u)
        return res

    ord_a = ord("a")
    h, w = map(int, input().split())
    t0 = [[ord(c) - ord_a for c in input()] for _ in range(h)]
    h_set = set(range(h))
    pattern = per(h_set)
    # print(t0)
    # print(pattern)
    b = h % 2
    for p in pattern:
        t1 = [[] for _ in range(h)]
        if b:
            t1[h // 2] = t0[p[0]]
        i = 0
        for ii in range(b, h, 2):
            t1[i] = t0[p[ii]]
            t1[h - 1 - i] = t0[p[ii + 1]]
            i += 1
        # print(p)
        # print(t1)
        fin = [False] * w
        mid = (w % 2 == 1)
        br = False
        for j, c0 in enumerate(zip(*t1)):
            if fin[j]: continue
            fin[j] = True
            c0 = c0[::-1]
            for jj, c1 in enumerate(zip(*t1)):
                if jj <= j: continue
                if fin[jj]: continue
                if c0 == c1:
                    fin[jj] = True
                    break
            else:
                if mid and c0 == c0[::-1]:
                    mid = False
                else:
                    br = True
                    break
        if br: continue
        print("YES")
        exit()
    print("NO")

main()


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

int main(){
    int a, b;
    string op;
    for (int i = 0; ; i++)
    {
        cin>>a>>op>>b;
        if (op == "?") break;

        if (op == "+")
        {
            cout<<a + b<<endl;
        }
        if (op == "-")
        {
            cout<<a - b<<endl;
        }
        if (op == "*")
        {
            cout<<a * b<<endl;
        }
        if (op == "/")
        {
            cout<<a/b<<endl;
        }
    }
}


Measured memory_bytes: 3168
#include <stdio.h>

int main(){
  char str[200000];
  int start=-1,end;
  scanf("%s",str);
  for(int i=0;i<200000;i++){
    if('A'>str[i]||'Z'<str[i]) break;
    if(str[i]=='A'&&start==-1) start=i;
    if(str[i]=='Z') end=i;
  }
  printf("%d",end-start+1);
}


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

int main() {
    int N;
    double ans = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        double x;
        cin >> x;
        string s;
        cin >> s;
        if (s == "JPY") {
            ans += x;
        }
        else {
            ans += x * 380000.0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		int n = stdIn.nextInt();
		Integer[] a = new Integer[n];

		int alice = 0;
		int bob = 0;

		for (int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();

		}

		Arrays.sort(a, Collections.reverseOrder());

		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				alice += a[i];
			} else {
				bob += a[i];
			}

		}

		System.out.println(alice - bob);

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
  int N, K;
  cin >> N >> K;
  int num = 1;
  for(int i=0; i<N; ++i){
    if(num>K) num+=K;
    else num *= 2;
  }
  cout << num << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#define MAX 100005
#define MAXV 1000000000
using namespace std;

int main(){
  int n, k, a[MAX], s = MAX, ans = MAXV;
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n+1-k; i++){
    if(a[i+k-1] <= 0) ans = min(ans, (-1)*a[i]);
    if(a[i] <= 0 && a[i+k-1] >= 0)
      ans = min(ans, a[i+k-1] - a[i] + min(a[i+k-1], (-1)*a[i]));
    if(a[i] >= 0) ans = min(ans, a[i+k-1]);
  }
  cout << ans << endl;
}


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

using namespace std;

int main(){
    vector<int> vc;
    for(int i = 0; i < 3; i++){
        int x; cin >> x;
        vc.push_back(x);
    }

    int count5 = 0, count7 = 0;

    vector<int>::iterator itr = vc.begin();
    while(itr != vc.end()){
        if(*itr == 5) count5++;
        if(*itr == 7) count7++;
        itr++;
    }
    if(count5 == 2 && count7 == 1) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
from collections import Counter
INF = float("inf")

MOD = 1000000007  # type: int


def factorial(n):
    # 試し割りによる素因数分解
    prime_count = Counter()

    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[int(n)] += 1

    return prime_count


def solve(N: int):

    primes = Counter()
    for i in range(1, N+1):
        primes += factorial(i)

    tot = 1
    for key in primes:
        tot *= primes[key]+1
        tot %= MOD

    print(tot)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<stdio.h>
int main(){
	int ans=0,cal[10001],n,i,j,a,b,c,x;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	for(i=0;i<n;i++)scanf("%d",&cal[i]);
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			if(cal[i]<cal[j]){
				x=cal[i];
				cal[i]=cal[j];
				cal[j]=x;
			}
		}
	}
	for(i=1;i<=n;i++){
		x=0;
		for(j=0;j<i;j++)x=x+cal[j];
		x=(c+x)/(a+b*i);
		if(ans<x)ans=x;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9+7;
ll fastpower(ll a, ll b){
    ll res = 1;
    a %= mod;
    while(b){
        if(b&1) res = (res * a) % mod;
        a *= a; a %= mod;
        b >>= 1;
    }
    res %= mod;
    return res;
}
int main()
{
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
	freopen("output.txt","w", stdout);
	freopen("error.txt","w", stderr);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n, k;
	cin>>n>>k;

	ll gcd[k + 1], l;
	memset(gcd, 0, sizeof(gcd));
	ll ans = 0;
	for(ll i = k; i >= 1; i--) {
		l = k/i;
		gcd[i] = fastpower(l, n);
		gcd[i] %= mod;
		for(ll j = i * 2; j <= k; j += i) {
			gcd[i] -= gcd[j];
		}
		ans += ((i)*gcd[i])%mod;
	}	
	ans = ans%mod;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    ll n, k,sum=0,k2;
    cin >> n >> k;
    k2 = k;
    vector<ll> h(n+1,0);
    for (ll i = 0; i < n;i++){
        cin >> h[i];
        sum += h[i];
    }
    sort(h.begin(), h.end(), greater<ll>());
    ll j = 0;
    if(k>n){
        cout << 0 << endl;
    }
    else{
        while (k > 0)
        {
            sum -= h[j];
            //cout << h[j] << endl;
            k--;
            j++;
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans = n/(a+b)*a+min(n%(a+b),a);
  cout << ans << endl;
}


Measured memory_bytes: 256
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll n,ans=0;
  ll a[110];
  scanf("%lld",&n);
  for(int i = 0; i < n; i++)
  {
    scanf("%lld",&a[i]);
  }
  
  for(int i = 0; i < n; i++)
  {
    for(int j = i+1; j < n; j++)
    {
      ll diff = llabs(a[i]-a[j]);
      if(diff>ans){
        ans=diff;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128