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

int N;
typedef 
struct data{
  long long a,b;
} data;
 
data t[50];
char u[50][21];

int check(int x,int y){
  if(t[x].a*t[y].b < t[y].a*t[x].b)return 1;
  else if(t[x].a*t[y].b == t[y].a*t[x].b)return 0;
  else return -1;
}

void change(int x,int y){
  data tmp;
  tmp=t[x];
  t[x]=t[y];
  t[y]=tmp;
  char tmp2[21];
  strcpy(tmp2,u[x]);
  strcpy(u[x],u[y]);
  strcpy(u[y],tmp2);
}

int main(){
  int i,j;
  while(1){
    scanf("%d",&N);
    if(N==0)break;

    for(i=0;i<N;i++){
      int p,a,b,c,d,e,f,s,m;
      scanf("%s %d %d %d %d %d %d",u[i],&p,&a,&b,&c,&d,&e);
      scanf("%d %d %d",&f,&s,&m);
      t[i]=(data){f*s*m-p,a+b+c+(d+e)*m};
    }
    for(i=N-1;i>0;i--){
      for(j=0;j<i;j++){
        if(check(j,j+1)==1){
          change(j,j+1);
        }else if(check(j,j+1)==0 && strcmp(u[j],u[j+1]) > 0){
          change(j,j+1);
        }
      }
    }
    for(i=0;i<N;i++)printf("%s\n",u[i]);
    printf("#\n");
  }
  return 0;
}

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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef rsd511
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    #ifndef rsd511
    #define trace(...) {}
    #define cotra(...) {}
    #endif
} 

// Code Here

int main()
{
    Fast_IO();
    ll n; cin >> n;
    ll a[n]; f(i,0,n-1) cin >> a[i];
    ll ans = 0;
    f(i,1,n-1) {
    	if(a[i] < a[i-1]) {
    		ans += a[i-1] - a[i];
    		a[i] = a[i-1];
    	}
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 5164
#include <cstdio>

int a, b, c;
int n[] = {5, 7, 5};

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

    bool f = false;
    for(int i = 0; i < 3; i++){
        if(n[i % 3] == a && n[(i + 1) % 3] == b && n[(i + 2) % 3] == c){
            f = true;
        }
    }

    if(f) printf("YES\n");
    else printf("NO\n");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n, m, R; cin >> n >> m >> R;
    vi r(R), must(n, -1); rep(i, R) cin >> r[i], r[i]--, must[r[i]] = i;
    using Edge = tuple<int, int>;
    vector<vector<Edge>> G(n);
    rep(loop, m){
        int a, b, c; cin >> a >> b >> c; a--, b--;
        G[a].emplace_back(Edge(c, b));
        G[b].emplace_back(Edge(c, a));
    }

    vector<vll> min_dist(n, vll(1 << R, inf));
    using Elem = tuple<ll, int, int>;
    priority_queue<Elem, vector<Elem>, greater<Elem>> q;
    for(auto& e : r) min_dist[e][1 << must[e]] = 0, q.push(Elem(0, e, 1 << must[e]));

    while(q.size()){
        auto cur = q.top(); q.pop();
        ll cost; int v, stat; tie(cost, v, stat) = cur;
        if(cost != min_dist[v][stat]) continue;

        for(auto& e : G[v]){
            int nv, dc; tie(dc, nv) = e;
            int nstat = stat;
            if(must[nv] != -1){
                if(stat & (1 << must[nv])) continue;
                nstat = (stat | (1 << must[nv]));
            }
            ll ncost = cost + dc;

            if(chmin(min_dist[nv][nstat], ncost)){
                q.push(Elem(ncost, nv, nstat));
            }
        }
    }

    ll res = inf;
    rep(i, n){
        chmin(res, min_dist[i].back());
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 5880
//@samraj2k
//#2ksr
//Don't copy my codes. They produce wrong output.
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int x=abs(sx-tx);
  int y=abs(sy-ty);
  if(x!=0 && y!=0)
  {
  for (int i = 0; i < y; ++i)
  {
    cout<<'U';
  }
  
  for (int i = 0; i < x; ++i)
  {
    cout<<'R';
  }
  for (int i = 0; i < y; ++i)
  {
    cout<<'D';
  }
   for (int i = 0; i < x; ++i)
  {
    cout<<'L';
  }
  cout<<'L';
  for (int i = 0; i < y+1; ++i)
  {
    cout<<'U';
  }
   for (int i = 0; i < x+1; ++i)
  {
    cout<<'R';
  }
  cout<<'D';
cout<<'R';
for (int i = 0; i < y+1; ++i)
  {
    cout<<'D';
  }
   for (int i = 0; i < x+1; ++i)
  {
    cout<<'L';
  }
  cout<<'U';
}
else if(x==0)
{
  for (int i = 0; i < y; ++i)
  {
    cout<<'U';
  }
  cout<<'R';
    for (int i = 0; i < y; ++i)
  {
    cout<<'D';
  }
  cout<<"LL";
    for (int i = 0; i < y; ++i)
  {
    cout<<'U';
  }
  cout<<"RURR";
   for (int i = 0; i < y+2; ++i)
  {
    cout<<'D';
  }
  cout<<"LLU";


}
else if(y==0){
 for (int i = 0; i < x; ++i)
  {
    cout<<'R';
  }
  cout<<'D';
    for (int i = 0; i < y; ++i)
  {
    cout<<'L';
  }
  cout<<"UU";
    for (int i = 0; i < y; ++i)
  {
    cout<<'R';
  }
  cout<<"DRUU";
   for (int i = 0; i < y+2; ++i)
  {
    cout<<'L';
  }
  cout<<"DDR";


}


  return 0;
}

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

using namespace std;


int main(void) {
	int a, b, c, d = 0;
	cin >> a >> b;


	if (a == b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	static String number;
	static long ans;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		number = sc.next();
		ans=0;
		System.out.println(dfs(0,1,0));
	}
	public static long dfs(int start,int last,long sum){
		long num =  Long.parseLong(number.substring(start, last));
		if(last==number.length()){
			
			return sum+num;
		}
		 return dfs(start,last+1,sum)+dfs(last,last+1,sum+num);
		 
		
		
	}
}

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    if A==B and C!=A:
        print(YES)
    elif B==C and B!=A:
        print(YES)
    elif C==A and B!=A:
        print(YES)
    else:
        print(NO)
    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
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <sstream>
#include <math.h>

using namespace std;

string check(string str);
map<char, int> create_table();
int gcd(int a, int b);

int main(){
  char ch = 'a';
  string str;
  int num;
  vector<string> answers;
  map<char,int> table = create_table();
  cin >> num;

  cin.ignore();
  for(int k=0; k<num; k++){
    getline(cin, str);

    char c;
    char list[1];
    bool flag = true;
    int beta;
    int alpha = 1;
    map<char, int>::iterator itr;
    while(flag){
      if(gcd(alpha,26) == 1){ 
        for(beta=1; beta<=26; beta++){
          string result;
          for(int i=0; i<str.size(); i++){
            c = str[i];
            if(c != ' '){
              sprintf(list, "%c", ch+(alpha*table[c]+beta)%26);
              result += list[0];
            }else{
              result += ' ';
            }
          }
          if(result.find("this",0) !=string::npos || result.find("that",0) != string::npos){
            answers.push_back(result);
            flag = false;
            break;
          }
        }
      }
      alpha++;
    }
  }

  for(int j=0; j<answers.size(); j++){
    cout << answers[j] << endl;
  }
  return 0;
}


map<char, int> create_table(){
  map<char, int> table;
  char ch[1];
  char str = 'a';

  for(int i=0; i<26; i++){
    sprintf(ch, "%c", str+i); 
    table.insert(pair<char,int>(ch[0],i));
  }
  return table;
}

int gcd(int a, int b){
  int temp;
  if(a<b){
    temp = a;
    a = b;
    b = temp;
  }
  while(b!=0){
    temp = b;
    b = a%b;
    a = temp;
  }
  return a;
}

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

int main(){
    ll N;
    cin >> N;
    ll A[N+1],kaito[N+1];
    repr(i,1,N+1){
        cin >> A[i];
        kaito[A[i]]=i;
    }
    repr(i,1,N+1){
        if(i!=N+1) cout << kaito[i] << " ";
        else cout << kaito[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max

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

    ll ans=0;
    rep(i,1000) {
        int c[3] = {i/100,(i/10)%10,i%10};
        int num=0;
        rep(j,n) {
            if (s[j]=='0'+c[num]) num++;
            if (num==3) {
                ans++;
                break;
            }
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))

even_list = []
for a in a_list:
    if a%2==0:
        even_list.append(a)

ans = True
for e in even_list:
    if e%3==0 or e%5==0:
        ans = True
    else:
        ans = False
        break

if ans:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int h, w, k, sy, sx;
vector<string> s(810);
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
int d[810][810];
int dist[810][810];
const int INF = 1e9;
bool contain(int y, int x){
    return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    cin >> h >> w >> k;
    rep(i, 0, h) cin >> s[i];
    rep(i, 0, h) rep(j, 0, w){
        if(s[i][j] == 'S'){
            sy = i; sx = j; break;
        }
    }
    rep(i, 0, h){
        rep(j, 0, w){
            int tmp = min(i, min(j, min(h - 1 - i, w  - 1 - j)));
            d[i][j] = tmp;
        }
    }
    int MIN = (d[sy][sx] + k - 1) / k + 1;
    queue<P> q;
    q.push(P(sy, sx));
    rep(i, 0, h) rep(j, 0, w) dist[i][j] = INF;
    dist[sy][sx] = 0;
    while(!q.empty()){
        P p = q.front(); q.pop();
        int y = p.first;
        int x = p.second;
        MIN = min(MIN, (d[y][x] + k - 1) / k + 1);
        rep(i, 0, 4){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(!contain(ny, nx) || dist[ny][nx] != INF) continue;
            dist[ny][nx] = dist[y][x] + 1;
            if(dist[ny][nx] > k) continue;
            // cout << ny << " " << nx << " " << d[y][x] << " " << dist[ny][nx] << endl;
            // MIN = min(MIN, (d[y][x] + k - 1) / k + 1);
            // if(d[ny][nx] == 0 && s[ny][nx] == '.' && dist[ny][nx] <= k) MIN = min(MIN, (int)1);
            if(s[ny][nx] == '#') continue;
            q.push(P(ny, nx));
        }
    }
    cout << MIN << endl;
}

Measured memory_bytes: 11392
# union find
class UnionFind
  def initialize(n)
    @parents = Array.new(n) { |i| i }
    @ranks = Array.new(n) { 0 }
  end

  def root(x)
    if @parents[x] == x
      x
    else
      @parents[x] = root(@parents[x])
    end
  end

  def unite(x, y)
    root_x = root(x)
    root_y = root(y)
    return if root_x == root_y

    if @ranks[root_x] < @ranks[root_y]
      @parents[root_x] = root_y
    else
      @parents[root_y] = root_x
      @ranks[root_x] += 1 if @ranks[root_x] == @ranks[root_y]
    end
  end

  def same?(x, y)
    root(x) == root(y)
  end
end

n, m = gets.split.map(&:to_i)
u = UnionFind.new(n+1)
xyz = []
h = Hash.new
m.times do
  ary = gets.split.map(&:to_i)
  xyz.push ary
  h[ary[0]] = true
  h[ary[1]] = true
  u.unite(ary[0], ary[1])
end

count = n - h.size

roots = Hash.new(false)

h.each do |k, v|
  roots[u.root(k)] = true
end

count += roots.size
puts count


Measured memory_bytes: 17660
from sys import stdin

n = int(stdin.readline().rstrip())
li = [list(stdin.readline().rstrip()) for _ in range(n)]

set_list = {}

for i in li:
    i.sort()
    s = "".join(i)
    if s in set_list:
        set_list[s] += 1
    else:
        set_list[s] = 1

point = 0

for i in set_list.values():
    point += i*(i-1)//2

print(point)

Measured memory_bytes: 39040
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

ll mod = 1e+9 + 7;
map<ll, ll> m;

ll f(ll n){
    if(m.count(n)) return m[n];
    if(n == 0) return m[n] = 1;
    if(n == 1) return m[n] = 2;
    ll temp = (f((n - 2) / 2) + f((n - 1) / 2)) % mod;
    return m[n] = (temp + f(n / 2)) % mod;
}

int main(){
    ll n;
    cin >> n;
    cout << f(n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define all(v) v.begin() , v.end()
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define tr(con) for(auto it = con.begin(); it!= con.end() ; it++)
#define INF 1e9+7   // 1 * 10^9+ 7
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;
 
int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    string str ;cin >> str;
    int ans;
    if(str =="SUN")ans =7 ;
    else if(str == "SAT") ans =1;
   
    else if(str == "FRI") ans =2;
    else if(str == "THU") ans =3;
    else if(str == "WED") ans =4;
    else if(str == "TUE") ans =5;
    else if(str == "MON") ans =6;
    cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <algorithm>

using namespace std;

void sort(int* arr);

int main()
{
    int num, h, l, r;
    int line[3];

    cin >> num;

    for (int n = 0; n < num; n++)
    {
        cin >> line[0] >> line[1] >> line[2];

//        cout << "input:" << line[0] << " " << line[1] << " " << line[2] << endl;

        h = 0;
        l = 0;
        r = 0;

        sort(line);
        h = line[0];
//        h = *max_element(line, line + num);
//        cout << "max:" << h << endl;

        for (int i = 0; i < 3; i++)
        {
            if (line[i] == h && l == 0)
            {
                l = line[i] * line[i];
            }
            else
            {
                r += line[i] * line[i];
            }
        }

//        cout << "left:" << l << endl;
//        cout << "right:" << r << endl;

        if (l == r)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }

    return 0;
}

void sort(int* arr)
{
    for (int i = 0; i < 2; i++)
    {
        for (int n = 0; n < 2 - i; n++)
        {
            if (arr[n] < arr[n+1])
            {
                swap(arr[n], arr[n+1]);
            }
        }
    }
}



Measured memory_bytes: 3052
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int road = sc.nextInt();
        int[] city = new int[n];
        for (int i = 0; i < road; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            city[a - 1]++;
            city[b - 1]++;
        }
        for (int tmp : city) {
            System.out.println(tmp);
        }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n, k;

int main() {
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (n < k) cout << 1 << endl;
    else if (n == k) cout << 0 << endl;
    else cout << n-k << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
bool memo[128];
int main(void) {
  int n, d;
  cin >> n;
  while (n--) {
    cin >> d;
    memo[d] = true;
  }
  int ans = 0;
  for (int i = 0; i < 128; i++)
    if (memo[i])
      ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
str = input()
for i in range(int(input())):
    line = input().split()
    formula = line[0]
    left = int(line[1])
    right = int(line[2]) + 1
    if (formula == 'print'):
        print(str[left:right])
    elif (formula == 'reverse'):
        str = str[:left] + str[left:right][::-1] + str[right:]
    elif (formula == 'replace'):
        str = str[:left] + line[3] + str[right:]



Measured memory_bytes: 5612
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			String s = sc.next();
			
			int width = (s.length() - 1)/2;
			
			boolean isStrong = checkCircle(s) && checkCircle(s.substring(0, width)) &&
					checkCircle(s.substring(width + 1, s.length()));
			
			System.out.println(isStrong ? "Yes" : "No");
		}
	}
	
	public static boolean checkCircle(String s) {
		
//		System.out.println(s);
		
		for(int i = 0  ; i < (s.length()) / 2 ; i++ ) {
//			System.out.println(s.charAt(i));
			if ( s.charAt(i) == s.charAt(s.length()-1-i)) {
				//ok
			}
			else {
				return false;
			}
		}
		return true;
	}

}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

vector<string> a;

void saiki(ll keta,ll now,string str,ll mae){
    if(now==0) a.push_back(str);
    else{
        for(ll i=0;i<10;i++){
            if(keta==now||labs(mae-i)<=1){
                if(keta==now&&i==0) continue;
                char c='0'+i;
                saiki(keta,now-1,str+c,i);
            }
        }
    }
}

int main(){
    ll k;
    cin >> k;
    for(ll i=1;i<=10;i++){
        saiki(i,i,"",0);
    }
    
    cout << a[k-1] << endl;

    return 0;
}









Measured memory_bytes: 12400
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<int,int>
#define LL long long
using namespace std;

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    LL x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    LL req = x/d;
    if (req >= k) {
        cout << x-k*d << endl;
        return 0;
    }
    LL f = k-req;
    if (f%2 == 0) cout << x-req*d;
    else cout << abs(x-req*d-d);
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
#define ll long long
#define rep(i, end) for(ll i=0; i<(ll)(end); i++)

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  ll ans;
  rep(i, s.length()){
    if (s[i] == t[i]) ans++;
  }
  cout << ans << endl;
 
  return 0;
}

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

sum = a.inject(&:+)
divs = []
t = 1
while t * t <= sum
  if sum % t == 0
    divs << t
    divs << sum / t if sum / t != t
  end
  t += 1
end
divs.sort!.reverse!
divs.each do |d|
  r = a.map { |ai| ai % d }
  r.sort!
  sumr = [tmp = 0].concat(r.map { |ri| tmp += ri })
  rdiff = r.map { |ri| d - ri }
  sumrd = [tmp = 0].concat(rdiff.map { |ri| tmp += ri })
  n.times do |i|
    if k >= sumr[i] - sumr[0] && sumr[i] - sumr[0] == sumrd[n] - sumrd[i]
      puts d
      exit
    end
  end
end
puts 1

Measured memory_bytes: 17936
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
    ll a,b,c;
    cin >> a >>b;

    ll ans = (a+b) / 2;

    if ( (a-b)%2 ==0 ){ 
      cout <<ans;
    }else{
      cout << "IMPOSSIBLE";
    }

}


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

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 105;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(ll)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = _begin + (_end - _begin) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dat[3][NMAX] = {};

string S;
vec v;

ll ans = {};

void solve(){
  // main algorithm
  for (size_t i = 0; i < 2; i++) {
    for (size_t j = 0; j < N; j++) {
      dat[i+1][j+1] += max<int>(dat[i][j+1], dat[i+1][j]);
    }
  }
  ans = dat[2][N];
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> N;
  for (size_t i = 0; i < 2; i++) {
    for (size_t j = 0; j < N; j++) {
      scanf("%d", &dat[i+1][j+1]);
    }
  }
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}


Measured memory_bytes: 256
n, W = map(int, input().split())
w = []
v = []
for i in range(n):
    vals = list(map(int, input().split()))
    w.append(vals[0])
    v.append(vals[1])
sum_v = sum(v)
inf = 10**10
dp = [inf] * (sum_v + 1)
dp[0] = 0
for i in range(n):
    for j in reversed(range(sum_v - v[i] + 1)):
        if dp[j] == inf:
            continue
        dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i])
for i in reversed(range(sum_v + 1)):
    if dp[i] > W:
        continue
    print(i)
    break

Measured memory_bytes: 41564
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    string s, t; cin >> s >> t;
    int n = s.length(), m = t.length();
    int ans = m;
    rep(i,n-m+1){
        int cnt = m;
        rep(j,m){
            if(s[i+j]==t[j]) cnt--;
        }
        chmin(ans, cnt);
    }
    cout << ans << '\n';
    
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 100000 * 10000 + 7;
int n, a[N];

int main() {
    //freopen("MA.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    int k = 0; a[k] = -1;
    int res = 1;
    for (int i = 1; i <= n; i++) {
        res = 1LL * res * (i - k) % mod;
        if (a[i] - 1 < 2 * (i - k - 1)) k++;
    }
    cout << res << endl;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    set<int> s;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans=9999999999;
    for(int k=-100;k<=100;k++){
        ll sum=0;
        for(int i=0;i<n;i++){
            sum+=(a[i]-k)*(a[i]-k);
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
_list = list(map(int,input().split()))
even = [x for x in _list if x % 2==0]
answer = []
for x in even:
    if x % 3 == 0 or x % 5 == 0:
        answer.append(True)
if len(even) ==len(answer):
    print("APPROVED")
else:
    print("DENIED")

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

const int N = 2e5L + 11;
int a[N], cnt[N];
int f[N];

int ans = 0;
void add(int i) {
	cnt[i] ++;
	if(i - cnt[i] + 1 > 0) {
		if(f[i - cnt[i] + 1] == 0)
			ans ++;
		f[i - cnt[i] + 1] ++;
	}
}
void del(int i) {
	if(i - cnt[i] + 1 > 0) {
		f[i - cnt[i] + 1] --;
		if(f[i - cnt[i] + 1] == 0)
			ans --;
	}
	cnt[i] --;
}

int main() {
	ios :: sync_with_stdio(0);
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i]; cnt[a[i]] ++;
	}
	for(int i = 1; i <= n; i ++)
		for(int j = i; j > 0 && j > i - cnt[i]; j --)
			f[j] ++;
	for(int i = 1; i <= n; i ++)
		ans += (f[i] > 0);
	for(int i = 1; i <= m; i ++) {
		int x, y; cin >> x >> y;
		add(y); del(a[x]);
		//for(int i = 1; i <= n; i ++) cout << f[i] << ' '; cout << '\n';
		cout << n - ans << '\n';
		a[x] = y;
	}
}

Measured memory_bytes: 3840
int s[];M(int*a){return*1[&a]-*a;}
main(){
	scanf("%d%d%d%d%d",&s[0],&s[1],&s[2],&s[3],&s[4]);
	qsort(s,5,4,M);
	printf("%d %d %d %d %d\n",s[0],s[1],s[2],s[3],s[4]);
	return 0;
}

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

int main(){
	int x;
	scanf("%d",&x);
	stack <char> stek;
	string beg;
	string ans;
	cin >> beg;
	for(int i=0;i<beg.size();i++){
		if(beg[i]=='(') stek.push(beg[i]);
		else{
			if(stek.empty()) ans+='(';
			else stek.pop();	
		}
	}
	ans+=beg;
	while(!stek.empty()) {
		ans+=')';
		stek.pop();	
	}
	cout << ans <<endl;
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
k=int(input())
flg=0
while k>0:
  if a<b and b<c:
    flg=1
    break
  if a>=b:
    b*=2
    k-=1
  elif b>=c:
    c*=2
    k-=1
if a<b and b<c:
  flg=1
if flg==1:
  print('Yes')
else:
  print('No')

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int POW(int n){
    int res = 0;
    if(n % 2 == 1) return 0;
    n /= 2;
    res++;

    return res + POW(n);
}

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

    int n;
    cin >> n;

    ll ans = 0;
    rep(i, n){
        ll tmp;
        cin >> tmp;

        ans += POW(tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define int long long
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

signed main(){
	int n;
	cin>>n;
	int a[n];
	int ide[3];
	rep(i,3)ide[i]=0;
	rep(i,n){
		cin>>a[i];
		if(a[i]%2)ide[2]++;
		else if(a[i]%4==0)ide[1]++;
		else ide[0]++;
	}
	bool preodd=false;
	bool check=false;
	rep(i,n){
		if(!preodd && ide[2]){
			ide[2]--;
			preodd=true;
		}else if(preodd){
			if(ide[1]){
				ide[1]--;
				preodd=false;
			}else{
				check=true;
				break;
			}
		}else break;
	}
	if(!check)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

/*ソートの時に使う
int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}
    qsort (data,sizeof(data),sizeof(int),sort); 
*/

int main(void){
    int n;
    scanf("%d",&n);
    long long a[n],sum[n];
    for (int i=0; i<n; i++){
        scanf("%lld",&a[i]);
        if (i==0){
            sum[i]=a[i];
        } else {
            sum[i]=a[i]+sum[i-1];
        }
    }
    long long ans;
    for (int i=0; i<n-1; i++){
        if (i==0){
            ans=llabs((sum[n-1]-sum[i])-sum[i]);
        } else if (ans>llabs((sum[n-1]-sum[i])-sum[i])){
            ans=llabs((sum[n-1]-sum[i])-sum[i]);
        }
    }
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 3328
import java.util.Scanner;
 
class Main {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int k =sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        if(a%k==0||b%k==0)
        {
            System.out.print("OK");
        }
        else
        if((b/k)-(a)/k>=1)
        {
            System.out.print("OK");
        }
        else
        {
            System.out.print("NG");
        }
    }
}

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

using namespace std;

typedef long long ll;


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

	int n;
	cin >> n;

	cout << n * (n + 1) / 2 << endl;

}


Measured memory_bytes: 256
-- cats-and-dogs.hs --- Cats and Dogs

-- author: Seong Yong-ju <sei40kr@gmail.com>

solve :: Int -> Int -> Int -> Bool
solve a b x = a <= x && x <= a + b

main :: IO ()
main = do
  [a, b, x] <- map (read :: String -> Int) . words <$> getLine
  putStrLn $ if solve a b x then "YES" else "NO"


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

int main(){
    string S;
    cin>>S;
    int num=0,ans=0;
    for(int i=0; i<3; ++i){
        if(S[i]=='R') ++num;
        else{
            ans= max(ans,num);
            num=0;
        }
    }
    ans = max(ans,num);
    cout<<ans<<"\n";
}

Measured memory_bytes: 3588
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())

    COM_MAX = N

    fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2, COM_MAX + 1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    def mod_com(n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

    for i in range(1, K + 1):
        print(mod_com(K - 1, i - 1) * mod_com(N - K + 1, i) % MOD)

    return


if __name__ == '__main__':
    main()


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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  
  for(int i = 0; i < n; i++){
  	cin >> h.at(i);
  }
  
  int maximum = 0;
  int ans = 0;
  
  for(int i = 0; i < n; i++){
  	if(h.at(i) >= maximum) {
    	maximum = h.at(i);
    	ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split(' '))

for i in range(K):
  if i % 2 == 0:
    a = b = 0
    if A % 2 == 1:
      A -= 1
    a = A // 2
    A -= a
    B += a

  else:
    if B % 2 == 1:
      B -= 1
    b = B // 2
    B -= b
    A += b

print(A, B)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    long w = sc.nextLong();
    long ans = (h * w + 1) / 2;
    if((h == 1) || (w == 1)) ans = 1;
    System.out.println(ans);
  }
}


Measured memory_bytes: 21716
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

const int MAX_N = 1000;

int sx, sy, tx, ty;

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

    cin >> sx >> sy >> tx >> ty;

    string s;

    s += string(tx - sx, 'R');

    s += string(ty - sy, 'U');

    s += string(tx - sx, 'L');

    s += string(ty - sy, 'D');

    s += 'D';

    s += string(tx - sx + 1, 'R');

    s += string(ty - sy + 1, 'U');

    s += "LU";

    s += string(tx - sx + 1, 'L');

    s += string(ty - sy + 1, 'D');

    s += 'R';

    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>

int main()
{
	int i;
	std::cin >> i;
	int a[i];
	for (int j = 0; j < i;j++)
	{
		std::cin >> a[j];
	}

	int heal = 0;
	for (int k = 0; k < i-1; k++)
	{
		for (int l = k+1 ; l < i ; l++)
		{
			heal = heal + a[k] * a[l];
		}
	}
	std::cout << heal;
}

Measured memory_bytes: 256
n = int(input())

w = list(map(int, input().split()))

total = sum(w)

s1 = 0
ans = 10**5
for i in range(n):
    s1 +=  w[i]
    s2 = total - s1
    ans = min(ans, abs(s2-s1))

print(ans)

Measured memory_bytes: 3060
/*
=============================================================

------------------Welcome To My Code-------------------------

---------Ankit Kumar || IIITBH || CSE || 2018-2022-----------

=============================================================
*/

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
map<ll, ll>::iterator itr;
vector<ll>::iterator it, it1;
const double PI = 3.141592653589793238;

int main()
{
	FASTIO;


        ll i,j,k,x,y,z,m,n,a,b,c,c1=0,c2=0,flag=0,sum=0;
	string s1,str;
	map<ll,ll>MAP;
	vector<ll>v;
	set<ll>s;

	cin>>n;
	FOR(i,n)
	{
	    cin>>x>>y;

	    if(x==y)
            c1++;

        else
            c1=0;

        if(c1==3)
            flag=1;


	}

	if(flag==1)
        cout<<"Yes";
    else
        cout<<"No";

    nl;



}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define INF 1e9+1
#define MOD 1e9+7
#define INF64 1e18+1

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
  int N;
  cin >> N;
  vector<long long int> A(N+1);
  vector<long long int> B(N);
  rep(i,0,N+1){
    cin >> A[i];
  }
  rep(i,0,N){
    cin >> B[i];
  }

  long long int ans=0;

  rep(i,0,N) {
    if (A[i] >= B[i]) {
      ans += B[i];
    } else {
      B[i] -= A[i];
      ans += A[i];
      if (A[i+1] >= B[i]) {
        A[i+1] -= B[i];
        ans += B[i];
      } else {
        ans += A[i+1];
        A[i+1] = 0;
      }
    }
  }


  put(ans);
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=gc();}
	}
};
using io::gi;
#define ll long long
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
const int N=5005;const ll inf=1000000000000ll,INF=10000000000000000ll;
int a[N],b[N],c[N];
ll d[N],e[N];
int main(){
	int n,m,p,t,i;
	scanf("%d%d%d",&n,&m,&p);
	for(i=1;i<=m;++i){scanf("%d%d%d",&a[i],&b[i],&c[i]);c[i]=p-c[i];}
	
	for(i=2;i<=n;++i)d[i]=INF;t=n;
	while(t--)for(i=1;i<=m;++i)cmin(d[b[i]],d[a[i]]+c[i]);
	
	for(i=1;i< n;++i)e[i]=INF;t=n;
	while(t--)for(i=1;i<=m;++i)cmin(e[a[i]],e[b[i]]+c[i]);
	
//	for(i=1;i<=n;++i)printf("%lld ",d[i]);printf("\n");
//	for(i=1;i<=n;++i)printf("%lld ",e[i]);printf("\n");
	for(i=1;i<=m;++i)if(d[a[i]]<inf&&e[a[i]]<inf&&d[b[i]]<inf&&e[b[i]]<inf&&d[b[i]]>d[a[i]]+c[i]){printf("-1");return 0;}
	if(d[n]<0ll)printf("%lld",-d[n]);else printf("0");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int d[51];
    cin >> N;
    rep(i, N){
        cin >> d[i];
    }
    ll ans = 0;
    rep(i, N){
        REP(j, i+1 , N){
          ans += d[i]*d[j];
        }
    }

    cout << ans << endl;


}

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

using namespace std;

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

    int n;
    string s;

    int c0 = 0, c1 = 0, c2 = 0, c3 = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
	cin >> s;
	if (s == "AC")
	    c0++;
	else if (s == "WA")
	    c1++;
	else if (s == "TLE")
	    c2++;
	else if (s == "RE")
	    c3++;
    }

    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;

    return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  ll N, t;  
  cin >> N;
  vector<ll> a(N);
  map<ll, ll> m;
  map<ll, ll> m2;

  rep(i, N){
    cin >> a[i];
  }

  rep(i, N){
    t = a[i] - i - 1;
    if(m.find(t) == m.end()){
      m.insert(make_pair(t, 0));
    }
    m[t]++;
  }

  rep(i, N){
    t = a[i] + i + 1;
    if(m2.find(t) == m2.end()){
      m2.insert(make_pair(t, 0));
    }
    m2[t]++;
  }

  ll ans = 0;
  for( auto i = m.begin(); i != m.end() ; ++i ) {
    t = 0 - i->first;
    if (m2.find(t) != m2.end()) {
      ans += i->second * m2[t];
    }
  }
  print(ans);

}


Measured memory_bytes: 27920
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        if (ni()>=30) out.println("Yes");
        else out.println("No");
        out.flush();
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}

Measured memory_bytes: 33056
p= []
try:
    while True:
        x,y = map(float,input().split(",")) 
        p.append(complex(x,y))
except EOFError: 
    pass


n=len(p)
sum=0.0
for i in range(1,n-1):
    a,b= p[i]-p[0], p[i+1]-p[0]
    s= (a.conjugate()* b).imag
    sum+= s
print("%.6f" % (abs(sum)/2.0))


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

const int N = 2005;

int n, a[N], d[N][N], p[N][N], q[N][N];

int main(){
    scanf("%d%d%d", &n, a + 1, a + 2);
    n += 2;
    for(int i = 3; i <= n; i++) scanf("%d", a + i);
    for(int i = 1; i <= n; i++) d[i][n] = d[n][i] = abs(a[n] - a[i]);
    for(int i = n; i >= 1; i--){
        for(int j = n; j >= 1; j--){
            if(i == n || j == n) d[i][j] = abs(a[i] - a[j]);
            else if(i < j) d[i][j] = p[j + 1][j];
            else d[i][j] = q[i][i + 1];
            p[i][j] = (i == n ? d[i][j] : max(p[i + 1][j], d[i][j]));
            q[i][j] = (j == n ? d[i][j] : min(q[i][j + 1], d[i][j]));
        }
    }
    printf("%d\n", d[1][2]);
}

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

struct position{
    int x, y;
};

struct road{
    int start, goal, cost;
};

int N;
vector<vector<long>> roads;

vector<bool> flag;

long flow(int now, int goal, long flow_now){
    if(now == goal){
        return flow_now;
    }
    flag[now] = true;
    for(int i = 0; i < N * 2 + 2; i++){
        if(roads[now][i] > 0 && !flag[i]){
            long this_flow = flow(i, goal, min(flow_now, roads[now][i]));
            if(this_flow > 0){
                roads[now][i] -= this_flow;
                roads[i][now] += this_flow;
                return this_flow;
            }
        }
    }
    return 0;
}

int main(){
    cin >> N;
    position red_points[N];
    for(int i = 0; i < N; i++){
        cin >> red_points[i].x >> red_points[i].y;
    }
    roads.resize(N * 2 + 2);
    for(int i = 0; i < N * 2 + 2; i++){
        roads[i].resize(N * 2 + 2);
        fill(roads[i].begin(), roads[i].end(), -1);
    }
    for(int i = 0; i < N; i++){
        position point;
        cin >> point.x >> point.y;
        for(int j = 0; j < N; j++){
            if(red_points[j].x < point.x && red_points[j].y < point.y){
                roads[i][N + j] = 1;
                roads[N + j][i] = 0;
            }
        }
    }
    for(int i = 0; i < N; i++){
        roads[N * 2][i] = 1;
        roads[i][N * 2] = 0;
    }
    for(int i = 0; i < N; i++){
        roads[N + i][N * 2 + 1] = 1;
        roads[N * 2 + 1][N + i] = 0;
    }
    long ans = 0;
    flag.resize(N * 2 + 2);
    while(true){
        for(int i = 0; i < N * 2 + 2; i++){
            flag[i] = false;
        }
        long plus = flow(N * 2, N * 2 + 1, 1e9);
        if(!plus){
            break;
        }
        ans += plus;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640